diff --git a/marketplace-service/src/main/java/com/axonivy/market/controller/ProductController.java b/marketplace-service/src/main/java/com/axonivy/market/controller/ProductController.java index 3f5ad210f..24d820ac4 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/controller/ProductController.java +++ b/marketplace-service/src/main/java/com/axonivy/market/controller/ProductController.java @@ -62,7 +62,7 @@ public ProductController(ProductService productService, GitHubService gitHubServ public ResponseEntity> findProducts(@RequestParam(name = TYPE) String type, @RequestParam(required = false, name = KEYWORD) String keyword, @RequestParam(name = LANGUAGE) String language, @RequestParam(name = IS_REST_DESIGNER) Boolean isRestDesigner, Pageable pageable) { - Page results = productService.findAllProducts(type, keyword, language, isRestDesigner, pageable); + Page results = productService.findProducts(type, keyword, language, isRestDesigner, pageable); if (results.isEmpty()) { return generateEmptyPagedModel(); } diff --git a/marketplace-service/src/main/java/com/axonivy/market/service/ProductService.java b/marketplace-service/src/main/java/com/axonivy/market/service/ProductService.java index 6671be9d6..c16352bc5 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/service/ProductService.java +++ b/marketplace-service/src/main/java/com/axonivy/market/service/ProductService.java @@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable; public interface ProductService { - Page findAllProducts(String type, String keyword, String language, Boolean isRestDesigner,Pageable pageable); + Page findProducts(String type, String keyword, String language, Boolean isRestDesigner, Pageable pageable); boolean syncLatestDataFromMarketRepo(); diff --git a/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java b/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java index f4156de00..b3a079aca 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java +++ b/marketplace-service/src/main/java/com/axonivy/market/service/impl/ProductServiceImpl.java @@ -9,12 +9,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; @@ -103,15 +98,19 @@ public ProductServiceImpl(ProductRepository productRepository, GHAxonIvyMarketRe } @Override - public Page findProducts(String type, String keyword, String language, Pageable pageable) { + public Page findProducts(String type, String keyword, String language, Boolean isRestDesigner, Pageable pageable) { final var typeOption = TypeOption.of(type); final var searchPageable = refinePagination(language, pageable); var searchCriteria = new ProductSearchCriteria(); - searchCriteria.setType(typeOption); searchCriteria.setListed(true); searchCriteria.setKeyword(keyword); - searchCriteria.setLanguage(Language.of(language)); - searchCriteria.setType(typeOption); + if (BooleanUtils.isTrue(isRestDesigner)) { + searchCriteria.setType(TypeOption.CONNECTORS); + searchCriteria.setLanguage(Language.of(Locale.ENGLISH.toLanguageTag())); + } else { + searchCriteria.setType(typeOption); + searchCriteria.setLanguage(Language.of(language)); + } return productRepository.searchByCriteria(searchCriteria, searchPageable); } diff --git a/marketplace-service/src/test/java/com/axonivy/market/controller/ProductControllerTest.java b/marketplace-service/src/test/java/com/axonivy/market/controller/ProductControllerTest.java index 601c3d724..0c3e8ce39 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/controller/ProductControllerTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/controller/ProductControllerTest.java @@ -73,7 +73,7 @@ void setup() { void testFindProductsAsEmpty() { PageRequest pageable = PageRequest.of(0, 20); Page mockProducts = new PageImpl<>(List.of(), pageable, 0); - when(service.findAllProducts(any(), any(), any(), any() , any())).thenReturn(mockProducts); + when(service.findProducts(any(), any(), any(), any() , any())).thenReturn(mockProducts); when(pagedResourcesAssembler.toEmptyModel(any(), any())).thenReturn(PagedModel.empty()); var result = productController.findProducts(TypeOption.ALL.getOption(), null, "en", false, pageable); assertEquals(HttpStatus.OK, result.getStatusCode()); @@ -87,7 +87,7 @@ void testFindProducts() { Product mockProduct = createProductMock(); Page mockProducts = new PageImpl<>(List.of(mockProduct), pageable, 1); - when(service.findAllProducts(any(), any(), any(), any(), any())).thenReturn(mockProducts); + when(service.findProducts(any(), any(), any(), any(), any())).thenReturn(mockProducts); assembler = new ProductModelAssembler(); var mockProductModel = assembler.toModel(mockProduct); var mockPagedModel = PagedModel.of(List.of(mockProductModel), new PageMetadata(1, 0, 1)); diff --git a/marketplace-service/src/test/java/com/axonivy/market/service/ProductServiceImplTest.java b/marketplace-service/src/test/java/com/axonivy/market/service/ProductServiceImplTest.java index 6e0d5484d..c619e2abf 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/service/ProductServiceImplTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/service/ProductServiceImplTest.java @@ -178,17 +178,17 @@ void testFindProducts() { // Start testing by All when(productRepository.searchByCriteria(any(), any(Pageable.class))).thenReturn(mockResultReturn); // Executes - var result = productService.findProducts(TypeOption.ALL.getOption(), keyword, language, PAGEABLE); + var result = productService.findProducts(TypeOption.ALL.getOption(), keyword, language, false, PAGEABLE); assertEquals(mockResultReturn, result); // Start testing by Connector // Executes - result = productService.findProducts(TypeOption.CONNECTORS.getOption(), keyword, language, PAGEABLE); + result = productService.findProducts(TypeOption.CONNECTORS.getOption(), keyword, language, true, PAGEABLE); assertEquals(mockResultReturn, result); // Start testing by Other // Executes - result = productService.findProducts(TypeOption.DEMOS.getOption(), keyword, language, PAGEABLE); + result = productService.findProducts(TypeOption.DEMOS.getOption(), keyword, language, false, PAGEABLE); assertEquals(2, result.getSize()); } @@ -260,7 +260,7 @@ void testFindAllProductsWithKeyword() { language = "en"; when(productRepository.searchByCriteria(any(), any(Pageable.class))).thenReturn(mockResultReturn); // Executes - var result = productService.findProducts(TypeOption.ALL.getOption(), keyword, language, PAGEABLE); + var result = productService.findProducts(TypeOption.ALL.getOption(), keyword, language, false, PAGEABLE); assertEquals(mockResultReturn, result); verify(productRepository).searchByCriteria(any(), any(Pageable.class)); @@ -270,7 +270,7 @@ void testFindAllProductsWithKeyword() { .filter(product -> product.getNames().get(Language.EN.getValue()).equals(SAMPLE_PRODUCT_NAME)) .collect(Collectors.toList()))); // Executes - result = productService.findProducts(TypeOption.ALL.getOption(), SAMPLE_PRODUCT_NAME, language, PAGEABLE); + result = productService.findProducts(TypeOption.ALL.getOption(), SAMPLE_PRODUCT_NAME, language, false, PAGEABLE); assertTrue(result.hasContent()); assertEquals(SAMPLE_PRODUCT_NAME, result.getContent().get(0).getNames().get(Language.EN.getValue())); @@ -281,7 +281,7 @@ void testFindAllProductsWithKeyword() { && product.getType().equals(TypeOption.CONNECTORS.getCode())) .collect(Collectors.toList()))); // Executes - result = productService.findProducts(TypeOption.CONNECTORS.getOption(), SAMPLE_PRODUCT_NAME, language, PAGEABLE); + result = productService.findProducts(TypeOption.CONNECTORS.getOption(), SAMPLE_PRODUCT_NAME, language, false, PAGEABLE); assertTrue(result.hasContent()); assertEquals(SAMPLE_PRODUCT_NAME, result.getContent().get(0).getNames().get(Language.EN.getValue())); } @@ -345,7 +345,7 @@ void testSearchProducts() { when(productRepository.searchByCriteria(any(), any(Pageable.class))).thenReturn( mockResultReturn); - var result = productService.findProducts(type, keyword, language, simplePageable); + var result = productService.findProducts(type, keyword, language, false, simplePageable); assertEquals(result, mockResultReturn); verify(productRepository).searchByCriteria(any(), any(Pageable.class)); } diff --git a/marketplace-ui/src/app/modules/product/product-card/product-card.component.spec.ts b/marketplace-ui/src/app/modules/product/product-card/product-card.component.spec.ts index 79fe77af4..c5af98ebf 100644 --- a/marketplace-ui/src/app/modules/product/product-card/product-card.component.spec.ts +++ b/marketplace-ui/src/app/modules/product/product-card/product-card.component.spec.ts @@ -7,6 +7,16 @@ import { import { ProductCardComponent } from './product-card.component'; import { Product } from '../../../shared/models/product.model'; import { Language } from '../../../shared/enums/language.enum'; +import { ProductComponent } from '../product.component'; +import { ProductService } from '../product.service'; +import { inject } from '@angular/core'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; +import { + provideHttpClient, + withInterceptorsFromDi +} from '@angular/common/http'; +import { ActivatedRoute } from '@angular/router'; +import { of } from 'rxjs'; const products = MOCK_PRODUCTS._embedded.products as Product[]; const noDeNameAndNoLogoUrlProducts = @@ -15,11 +25,20 @@ const noDeNameAndNoLogoUrlProducts = describe('ProductCardComponent', () => { let component: ProductCardComponent; let fixture: ComponentFixture; + let mockActivatedRoute: any; beforeEach(async () => { + mockActivatedRoute = { queryParams: of({ showPopup: 'true' }) }; await TestBed.configureTestingModule({ imports: [ProductCardComponent, TranslateModule.forRoot()], - providers: [TranslateService] + providers: [ + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + TranslateService, + ProductService, + ProductComponent, + { provide: ActivatedRoute, useValue: mockActivatedRoute } + ] }).compileComponents(); fixture = TestBed.createComponent(ProductCardComponent); diff --git a/marketplace-ui/src/app/modules/product/product.component.ts b/marketplace-ui/src/app/modules/product/product.component.ts index c175f24c5..f8838cb6b 100644 --- a/marketplace-ui/src/app/modules/product/product.component.ts +++ b/marketplace-ui/src/app/modules/product/product.component.ts @@ -53,7 +53,7 @@ export class ProductComponent implements AfterViewInit, OnDestroy { criteria: Criteria = { search: '', type: TypeOption.All_TYPES, - isRestDesigner: false + isRestDesigner: false, sort: SortOption.STANDARD, language: Language.EN }; @@ -71,23 +71,17 @@ export class ProductComponent implements AfterViewInit, OnDestroy { @ViewChild('observer', { static: true }) observerElement!: ElementRef; constructor() { - console.log(this.route); - let phuc = ''; this.route.queryParams.subscribe(params => { - if ('resultsOnly' in params && this.isDesignerEnvironment) { - this.isRestClient.set(true); - } else { - this.isRestClient.set(false); - } + this.isRestClient.set( + params['resultsOnly'] && this.isDesignerEnvironment + ); + if (params['search'] != null) { - phuc = params['search']; - console.log(params['search']); this.criteria.search = params['search']; } }); this.loadProductItems(); - console.log(phuc); this.subscriptions.push( this.searchTextChanged .pipe(debounceTime(SEARCH_DEBOUNCE_TIME))