Skip to content

Commit d258c61

Browse files
Manage catalog entry
1 parent 7b36284 commit d258c61

File tree

10 files changed

+87
-19
lines changed

10 files changed

+87
-19
lines changed
0 Bytes
Binary file not shown.

sm-core/src/main/java/com/salesmanager/core/business/repositories/catalog/catalog/PageableCatalogRepository.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
public interface PageableCatalogRepository extends PagingAndSortingRepository<Catalog, Long> {
1111

1212

13-
@Query(value = "select distinct c from Catalog c join fetch c.merchantStore cm where c.id=?1 and (?2 is null or c.code like %?2%)",
14-
countQuery = "select count(c) from Catalog c join c.merchantStore cm where c.id=?1 and (?2 is null or c.code like %?2%)")
13+
@Query(value = "select distinct c from Catalog c join fetch c.merchantStore cm where cm.id=?1 and (?2 is null or c.code like %?2%)",
14+
countQuery = "select count(c) from Catalog c join c.merchantStore cm where cm.id=?1 and (?2 is null or c.code like %?2%)")
1515
Page<Catalog> listByStore(Integer storeId, String code, Pageable pageable);
1616

1717

sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/catalog/facade/CatalogFacade.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface CatalogFacade {
3030

3131
ReadableCatalogList listCatalogs(Optional<String> code, MerchantStore store, Language language, int page, int count);
3232

33-
ReadableCatalogEntryList listCatalogEntry(Optional<String> product, MerchantStore store, Language language, int page, int count);
33+
ReadableCatalogEntryList listCatalogEntry(Optional<String> product, Long catalogId, MerchantStore store, Language language, int page, int count);
3434

3535
ReadableCatalogEntry getCatalogEntry(Long id, MerchantStore store, Language language);
3636

sm-shop/SALESMANAGER-TEST.h2.db

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/PersistableProductPopulator.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
import java.util.HashSet;
88
import java.util.List;
99
import java.util.Set;
10+
1011
import javax.inject.Inject;
12+
1113
import org.apache.commons.collections4.CollectionUtils;
1214
import org.apache.commons.lang.Validate;
1315
import org.apache.commons.lang3.StringUtils;
1416
import org.springframework.beans.factory.annotation.Autowired;
1517
import org.springframework.stereotype.Component;
18+
1619
import com.salesmanager.core.business.constants.Constants;
1720
import com.salesmanager.core.business.exception.ConversionException;
1821
import com.salesmanager.core.business.services.catalog.category.CategoryService;
@@ -26,8 +29,6 @@
2629
import com.salesmanager.core.model.catalog.category.Category;
2730
import com.salesmanager.core.model.catalog.product.Product;
2831
import com.salesmanager.core.model.catalog.product.attribute.ProductAttribute;
29-
import com.salesmanager.core.model.catalog.product.attribute.ProductOption;
30-
import com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue;
3132
import com.salesmanager.core.model.catalog.product.availability.ProductAvailability;
3233
import com.salesmanager.core.model.catalog.product.description.ProductDescription;
3334
import com.salesmanager.core.model.catalog.product.image.ProductImage;
@@ -131,7 +132,7 @@ public Product populate(PersistableProduct source,
131132

132133
productDescription.setProduct(target);
133134
productDescription.setDescription(description.getDescription());
134-
135+
productDescription.setProductHighlight(description.getHighlights());
135136
productDescription.setName(description.getName());
136137
productDescription.setSeUrl(description.getFriendlyUrl());
137138
productDescription.setMetatagKeywords(description.getKeyWords());

sm-shop/src/main/java/com/salesmanager/shop/populator/catalog/ReadableProductPopulator.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,20 @@ public ReadableProduct populate(Product source,
431431
target.setSku(source.getSku());
432432

433433
FinalPrice price = pricingService.calculateProductPrice(source);
434+
435+
if(price != null) {
434436

435-
target.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
436-
target.setPrice(price.getFinalPrice());
437-
target.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
438-
439-
if(price.isDiscounted()) {
440-
target.setDiscounted(true);
441-
}
437+
target.setFinalPrice(pricingService.getDisplayAmount(price.getFinalPrice(), store));
438+
target.setPrice(price.getFinalPrice());
439+
target.setOriginalPrice(pricingService.getDisplayAmount(price.getOriginalPrice(), store));
440+
441+
if(price.isDiscounted()) {
442+
target.setDiscounted(true);
443+
}
442444

445+
}
446+
447+
443448
//availability
444449
for(ProductAvailability availability : source.getAvailabilities()) {
445450
//if(availability.getRegion().equals(Constants.ALL_REGIONS)) {//TODO REL 2.1 accept a region
@@ -556,6 +561,7 @@ com.salesmanager.shop.model.catalog.product.ProductDescription populateDescripti
556561
tragetDescription.setDescription(description.getDescription());
557562
tragetDescription.setHighlights(description.getProductHighlight());
558563
tragetDescription.setLanguage(description.getLanguage().getCode());
564+
tragetDescription.setKeyWords(description.getMetatagKeywords());
559565
if(description.getLanguage() != null) {
560566
tragetDescription.setLanguage(description.getLanguage().getCode());
561567
}

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/catalog/CatalogApi.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.salesmanager.shop.model.catalog.catalog.PersistableCatalogEntry;
2929
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalog;
3030
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalogEntry;
31+
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalogEntryList;
3132
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalogList;
3233
import com.salesmanager.shop.model.entity.EntityExists;
3334
import com.salesmanager.shop.store.controller.catalog.facade.CatalogFacade;
@@ -186,11 +187,35 @@ public void removeCatalogEntry(
186187

187188

188189

190+
}
191+
192+
@GetMapping(value = "/private/catalog/{id}/entry")
193+
@ResponseStatus(HttpStatus.OK)
194+
@ApiOperation(httpMethod = "GET", value = "Get catalog entry by catalog", notes = "",
195+
response = ReadableCatalogEntryList.class)
196+
@ApiImplicitParams({
197+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
198+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
199+
public ReadableCatalogEntryList getCatalogEntry(
200+
@RequestParam(name="id") Long id,
201+
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language,
202+
@RequestParam(value = "page", required = false, defaultValue="0") Integer page,
203+
@RequestParam(value = "count", required = false, defaultValue="10") Integer count,
204+
HttpServletRequest request) {
205+
206+
return catalogFacade.listCatalogEntry(catalogEntryFilter(request), id, merchantStore, language, page, count);
207+
208+
189209
}
190210

191211
private Optional<String> catalogFilter(HttpServletRequest request) {
192212

193213
return Optional.ofNullable((String)request.getAttribute("code"));
194-
}
214+
}
215+
216+
private Optional<String> catalogEntryFilter(HttpServletRequest request) {
217+
218+
return Optional.ofNullable((String)request.getAttribute("name"));
219+
}
195220

196221
}

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/category/CategoryApi.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@
3535
import io.swagger.annotations.ApiOperation;
3636
import io.swagger.annotations.ApiResponse;
3737
import io.swagger.annotations.ApiResponses;
38+
import io.swagger.annotations.SwaggerDefinition;
39+
import io.swagger.annotations.Tag;
3840
import springfox.documentation.annotations.ApiIgnore;
3941

4042
@RestController
41-
@Api(value = "/api/v1/category")
4243
@RequestMapping(value = "/api/v1")
44+
@Api(tags = {"Category management resource (Category Management Api)"})
45+
@SwaggerDefinition(tags = {
46+
@Tag(name = "Category management resource", description = "Manage category and attached products")
47+
})
4348
public class CategoryApi {
4449

4550
private static final int DEFAULT_CATEGORY_DEPTH = 0;

sm-shop/src/main/java/com/salesmanager/shop/store/facade/catalog/CatalogFacadeImpl.java

+35-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public void updateCatalog(Long catalogId, PersistableCatalog catalog, MerchantSt
155155
public ReadableCatalog getCatalog(Long id, MerchantStore store, Language language) {
156156
Validate.notNull(id,"Catalog id cannot be null");
157157
Validate.notNull(store,"MerchantStore cannot be null");
158-
Validate.notNull(language,"Language cannot be null");
159158

160159
Catalog c = catalogService.getById(id, store);
161160

@@ -209,9 +208,41 @@ public ReadableCatalogList listCatalogs(Optional<String> code, MerchantStore sto
209208
}
210209

211210
@Override
212-
public ReadableCatalogEntryList listCatalogEntry(Optional<String> product, MerchantStore store, Language language, int page, int count) {
213-
// TODO Auto-generated method stub
214-
return null;
211+
public ReadableCatalogEntryList listCatalogEntry(Optional<String> product, Long id, MerchantStore store, Language language, int page, int count) {
212+
Validate.notNull(store,"MerchantStore cannot be null");
213+
String productCode = null;
214+
if(product.isPresent()) {
215+
productCode = product.get();
216+
}
217+
218+
Catalog catalog = catalogService.getById(id, store);
219+
220+
if(catalog == null) {
221+
throw new ResourceNotFoundException("Catalog with id [" + id + "] not found for store ["+ store.getCode() +"]");
222+
}
223+
224+
ReadableCatalogEntryList catalogList = new ReadableCatalogEntryList();
225+
226+
try {
227+
Page<CatalogEntry> entry = catalogEntryService.list(catalog, store, language, productCode, page, count);
228+
229+
if(entry.getSize() == 0) {
230+
return catalogList;
231+
}
232+
233+
List<ReadableCatalogEntry> readableList = entry.getContent().stream()
234+
.map(cat -> readableCatalogEntryMapper.convert(cat, store, language))
235+
.collect(Collectors.toList());
236+
237+
catalogList.setCatalogEntry(readableList);
238+
catalogList.setTotalPages(entry.getTotalPages());
239+
catalogList.setRecordsTotal(entry.getSize());
240+
241+
} catch (ServiceException e) {
242+
throw new ServiceRuntimeException("Cannot get catalog entry for catalog [" + id + "] andr merchant [" + store.getCode() + "]");
243+
}
244+
245+
return catalogList;
215246
}
216247

217248
@Override

0 commit comments

Comments
 (0)