Skip to content

Commit

Permalink
update prop name & format
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Aug 1, 2024
1 parent e73f29a commit 45df6c5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public class FeedbackController {

private final PagedResourcesAssembler<Feedback> pagedResourcesAssembler;

public FeedbackController(FeedbackService feedbackService, JwtService jwtService,
FeedbackModelAssembler feedbackModelAssembler, PagedResourcesAssembler<Feedback> pagedResourcesAssembler) {
public FeedbackController(FeedbackService feedbackService, JwtService jwtService, FeedbackModelAssembler feedbackModelAssembler, PagedResourcesAssembler<Feedback> pagedResourcesAssembler) {
this.feedbackService = feedbackService;
this.jwtService = jwtService;
this.feedbackModelAssembler = feedbackModelAssembler;
Expand All @@ -71,7 +70,7 @@ public FeedbackController(FeedbackService feedbackService, JwtService jwtService
@Operation(summary = "Find feedbacks by product id with lazy loading", description = "Get all user feedback by product id (from meta.json) with lazy loading", parameters = {
@Parameter(name = "page", description = "Page number to retrieve", in = ParameterIn.QUERY, example = "0", required = true),
@Parameter(name = "size", description = "Number of items per page", in = ParameterIn.QUERY, example = "20", required = true),
@Parameter(name = "sort", description = "Sorting criteria in the format: Sorting criteria(popularity|alphabetically|recent), Sorting order(asc|desc)", in = ParameterIn.QUERY, example = "[\"popularity\",\"asc\"]", required = true) })
@Parameter(name = "sort", description = "Sorting criteria in the format: Sorting criteria(popularity|alphabetically|recent), Sorting order(asc|desc)", in = ParameterIn.QUERY, example = "[\"popularity\",\"asc\"]", required = true)})
public ResponseEntity<PagedModel<FeedbackModel>> findFeedbacks(
@PathVariable(ID) @Parameter(description = "Product id (from meta.json)", example = "portal", in = ParameterIn.PATH) String productId,
@ParameterObject Pageable pageable) {
Expand Down Expand Up @@ -105,10 +104,11 @@ public ResponseEntity<FeedbackModel> findFeedbackByUserIdAndProductId(
@Operation(summary = "Create user feedback", description = "Save user feedback of product with their token from Github account.")
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Example request body for feedback", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = FeedbackModelRequest.class)))
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Successfully created user feedback"),
@ApiResponse(responseCode = "401", description = "Unauthorized request") })
public ResponseEntity<Void> createFeedback(@RequestBody @Valid FeedbackModelRequest feedbackRequest,
@RequestHeader(value = X_AUTHORIZATION) @Parameter(description = "JWT Bearer token", example = "Bearer 123456", in = ParameterIn.HEADER) String bearerToken) {
@ApiResponse(responseCode = "201", description = "Successfully created user feedback"),
@ApiResponse(responseCode = "401", description = "Unauthorized request")})
public ResponseEntity<Void> createFeedback(
@RequestBody @Valid FeedbackModelRequest feedbackRequest,
@RequestHeader(value = X_AUTHORIZATION) @Parameter(description = "JWT Bearer token", example = "Bearer 123456", in = ParameterIn.HEADER) String bearerToken) {
String token = null;
if (bearerToken != null && bearerToken.startsWith(CommonConstants.BEARER)) {
token = bearerToken.substring(CommonConstants.BEARER.length()).trim(); // Remove "Bearer " prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public OAuth2Controller(GitHubService gitHubService, JwtService jwtService, GitH
@PostMapping(GIT_HUB_LOGIN)
@Operation(description = "Get rating authentication token")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully login to GitHub provider", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Map.class))),
@ApiResponse(responseCode = "400", description = "Bad Request")})
@ApiResponse(responseCode = "200", description = "Successfully login to GitHub provider", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Map.class))),
@ApiResponse(responseCode = "400", description = "Bad Request")})
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = Oauth2AuthorizationCode.class)))
public ResponseEntity<Map<String, String>> gitHubLogin(@RequestBody Oauth2AuthorizationCode oauth2AuthorizationCode) {
String accessToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.axonivy.market.constants.RequestMappingConstants.PRODUCT;
import static com.axonivy.market.constants.RequestMappingConstants.SYNC;
import static com.axonivy.market.constants.RequestParamConstants.AUTHORIZATION;
import static com.axonivy.market.constants.RequestParamConstants.X_AUTHORIZATION;
import static com.axonivy.market.constants.RequestParamConstants.KEYWORD;
import static com.axonivy.market.constants.RequestParamConstants.LANGUAGE;
import static com.axonivy.market.constants.RequestParamConstants.RESET_SYNC;
Expand Down Expand Up @@ -68,20 +68,11 @@ public ProductController(ProductService productService, GitHubService gitHubServ
@Parameter(name = "size", description = "Number of items per page", in = ParameterIn.QUERY, example = "20", required = true),
@Parameter(name = "sort", description = "Sorting criteria in the format: Sorting criteria(popularity|alphabetically|recent), Sorting order(asc|desc)",
in = ParameterIn.QUERY, example = "[\"popularity\",\"asc\"]", required = true)})
public ResponseEntity<PagedModel<ProductModel>> findProducts(@RequestParam(name = TYPE)
@Parameter(description = "Type of product.", in = ParameterIn.QUERY,
schema = @Schema(type = "string", allowableValues = {"all", "connectors", "utilities", "solutions", "demos"}))
String type,
@RequestParam(required = false, name = KEYWORD)
@Parameter(description = "Keyword that exist in product's name or short description", example = "connector", in = ParameterIn.QUERY)
String keyword,
@RequestParam(name = LANGUAGE)
@Parameter(description = "Language of product short description", in = ParameterIn.QUERY,
schema = @Schema(allowableValues = {"en", "de"}))
String language,
@ParameterObject
Pageable pageable) {

public ResponseEntity<PagedModel<ProductModel>> findProducts(
@RequestParam(name = TYPE) @Parameter(description = "Type of product.", in = ParameterIn.QUERY, schema = @Schema(type = "string", allowableValues = {"all", "connectors", "utilities", "solutions", "demos"})) String type,
@RequestParam(required = false, name = KEYWORD) @Parameter(description = "Keyword that exist in product's name or short description", example = "connector", in = ParameterIn.QUERY) String keyword,
@RequestParam(name = LANGUAGE) @Parameter(description = "Language of product short description", in = ParameterIn.QUERY, schema = @Schema(allowableValues = {"en", "de"})) String language,
@ParameterObject Pageable pageable) {
Page<Product> results = productService.findProducts(type, keyword, language, pageable);
if (results.isEmpty()) {
return generateEmptyPagedModel();
Expand All @@ -93,7 +84,8 @@ public ResponseEntity<PagedModel<ProductModel>> findProducts(@RequestParam(name

@PutMapping(SYNC)
@Operation(hidden = true)
public ResponseEntity<Message> syncProducts(@RequestHeader(value = AUTHORIZATION) String authorizationHeader,
public ResponseEntity<Message> syncProducts(
@RequestHeader(value = X_AUTHORIZATION) String authorizationHeader,
@RequestParam(value = RESET_SYNC, required = false) Boolean resetSync) {
String token = getBearerToken(authorizationHeader);
gitHubService.validateUserOrganization(token, GitHubConstants.AXONIVY_MARKET_ORGANIZATION_NAME);
Expand All @@ -119,7 +111,7 @@ public ResponseEntity<Message> syncProducts(@RequestHeader(value = AUTHORIZATION
@PostMapping(CUSTOM_SORT)
@Operation(hidden = true)
public ResponseEntity<Message> createCustomSortProducts(
@RequestHeader(value = AUTHORIZATION) String authorizationHeader,
@RequestHeader(value = X_AUTHORIZATION) String authorizationHeader,
@RequestBody @Valid ProductCustomSortRequest productCustomSortRequest) {
String token = getBearerToken(authorizationHeader);
gitHubService.validateUserOrganization(token, GitHubConstants.AXONIVY_MARKET_ORGANIZATION_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,43 @@ public class ProductDetailsController {
private final ProductService productService;
private final ProductDetailModelAssembler detailModelAssembler;

public ProductDetailsController(VersionService versionService, ProductService productService,
ProductDetailModelAssembler detailModelAssembler) {
public ProductDetailsController(VersionService versionService, ProductService productService, ProductDetailModelAssembler detailModelAssembler) {
this.versionService = versionService;
this.productService = productService;
this.detailModelAssembler = detailModelAssembler;
}

@GetMapping(BY_ID_AND_TAG)
@Operation(summary = "Find product detail by product id and release tag.", description = "get product detail by it product id and release tag")
public ResponseEntity<ProductDetailModel> findProductDetailsByVersion(@PathVariable(ID)
@Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH)
String id,
@PathVariable(TAG)
@Parameter(description = "Release tag (from git hub repo tags)", example = "v10.0.20", in = ParameterIn.PATH)
String tag) {
public ResponseEntity<ProductDetailModel> findProductDetailsByVersion(
@PathVariable(ID) @Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH) String id,
@PathVariable(TAG) @Parameter(description = "Release tag (from git hub repo tags)", example = "v10.0.20", in = ParameterIn.PATH) String tag) {
var productDetail = productService.fetchProductDetail(id);
return new ResponseEntity<>(detailModelAssembler.toModel(productDetail, tag), HttpStatus.OK);
}

@CrossOrigin(originPatterns = "*")
@PutMapping(INSTALLATION_COUNT_BY_ID)
@Operation(summary = "Update installation count of product", description = "By default, increase installation count when click download product files by users")
public ResponseEntity<Integer> syncInstallationCount(@PathVariable(ID)
@Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH)
String productId) {
public ResponseEntity<Integer> syncInstallationCount(
@PathVariable(ID) @Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH) String productId) {
int result = productService.updateInstallationCountForProduct(productId);
return new ResponseEntity<>(result, HttpStatus.OK);
}

@GetMapping(BY_ID)
@Operation(summary = "increase installation count by 1", description = "update installation count when click download product files by users")
public ResponseEntity<ProductDetailModel> findProductDetails(@PathVariable(ID)
@Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH)
String id) {
public ResponseEntity<ProductDetailModel> findProductDetails(
@PathVariable(ID) @Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH) String id) {
var productDetail = productService.fetchProductDetail(id);
return new ResponseEntity<>(detailModelAssembler.toModel(productDetail), HttpStatus.OK);
}

@GetMapping(VERSIONS_BY_ID)
public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(@PathVariable(ID)
@Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH)
String id,
@RequestParam(SHOW_DEV_VERSION) @Parameter(description = "Option to get Dev Version (Snapshot/ sprint release)", in = ParameterIn.QUERY)
boolean isShowDevVersion,
@RequestParam(name = DESIGNER_VERSION, required = false) @Parameter(in = ParameterIn.QUERY, example = "v10.0.20")
String designerVersion) {
public ResponseEntity<List<MavenArtifactVersionModel>> findProductVersionsById(
@PathVariable(ID) @Parameter(description = "Product id (from meta.json)", example = "adobe-acrobat-connector", in = ParameterIn.PATH) String id,
@RequestParam(SHOW_DEV_VERSION) @Parameter(description = "Option to get Dev Version (Snapshot/ sprint release)", in = ParameterIn.QUERY) boolean isShowDevVersion,
@RequestParam(name = DESIGNER_VERSION, required = false) @Parameter(in = ParameterIn.QUERY, example = "v10.0.20") String designerVersion) {
List<MavenArtifactVersionModel> models =
versionService.getArtifactsAndVersionToDisplay(id, isShowDevVersion, designerVersion);
return new ResponseEntity<>(models, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('ProductFeedbackService', () => {

const req = httpMock.expectOne('api/feedback');
expect(req.request.method).toBe('POST');
expect(req.request.headers.get('Authorization')).toBe('Bearer mockToken');
expect(req.request.headers.get('X-Authorization')).toBe('Bearer mockToken');
req.flush(feedback);
expect(productStarRatingService.fetchData).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProductFeedbackService {

submitFeedback(feedback: Feedback): Observable<Feedback> {
const headers = new HttpHeaders().set(
'Authorization',
'X-Authorization',
`Bearer ${this.authService.getToken()}`
);
return this.http
Expand Down

0 comments on commit 45df6c5

Please sign in to comment.