Skip to content

Commit 11eb99a

Browse files
API catalog management
1 parent 309c8aa commit 11eb99a

File tree

23 files changed

+438
-86
lines changed

23 files changed

+438
-86
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.salesmanager.core.business.repositories.catalog.catalog;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.PagingAndSortingRepository;
7+
8+
import com.salesmanager.core.model.catalog.catalog.CatalogEntry;
9+
10+
public interface PageableCatalogEntryRepository extends PagingAndSortingRepository<CatalogEntry, Long> {
11+
12+
13+
@Query(value = "select distinct c from CatalogEntry c join fetch c.product cp join fetch c.category cc join fetch c.catalog cl join fetch cl.merchantStore clm left join fetch cp.descriptions cpd left join fetch cc.descriptions ccd where cl.id=?1 and clm.id=?2 and cl.id=?2 and cpd.language=?3 and (?4 is null or cpd.name like %?4%)",
14+
countQuery = "select count(c) from CatalogEntry c join c.product cp join c.category cc join c.catalog cl join cl.merchantStore clm join cp.descriptions cpd where cl.id=?1 and clm.id=?2 and cpd.language=?3 and (?4 is null or cpd.name like %?4%)")
15+
Page<CatalogEntry> listByCatalog(Long catalogId, Integer storeId, Integer languageId, String name, Pageable pageable);
16+
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.salesmanager.core.business.repositories.catalog.catalog;
2+
3+
import org.springframework.data.domain.Page;
4+
import org.springframework.data.domain.Pageable;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.PagingAndSortingRepository;
7+
8+
import com.salesmanager.core.model.catalog.catalog.Catalog;
9+
10+
public interface PageableCatalogRepository extends PagingAndSortingRepository<Catalog, Long> {
11+
12+
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 distinct c from Catalog c join c.merchantStore cm where c.id=?1 and (?2 is null or c.code like %?2%)")
15+
Page<Catalog> listByStore(Integer storeId, String code, Pageable pageable);
16+
17+
18+
}

sm-core/src/main/java/com/salesmanager/core/business/repositories/merchant/MerchantRepository.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
public interface MerchantRepository extends JpaRepository<MerchantStore, Integer>, MerchantRepositoryCustom {
1010

11-
@Query("select m from MerchantStore m left join fetch m.parent mp left join fetch m.country mc left join fetch m.currency mc left join fetch m.zone mz left join fetch m.defaultLanguage md left join fetch m.languages mls where m.code = ?1")
11+
@Query("select m from MerchantStore m "
12+
+ "left join fetch m.parent mp"
13+
+ "left join fetch m.country mc "
14+
+ "left join fetch m.currency mc "
15+
+ "left join fetch m.zone mz "
16+
+ "left join fetch m.defaultLanguage md "
17+
+ "left join fetch m.languages mls where m.code = ?1")
1218
MerchantStore findByCode(String code);
1319

1420
@Query("select m from MerchantStore m left join fetch m.parent mp left join fetch m.country mc left join fetch m.currency mc left join fetch m.zone mz left join fetch m.defaultLanguage md left join fetch m.languages mls where m.id = ?1")
21+
//@Query("select m from MerchantStore m left join fetch m.country mc left join fetch m.currency mc left join fetch m.zone mz left join fetch m.defaultLanguage md left join fetch m.languages mls where m.id = ?1")
1522
MerchantStore getById(int id);
1623

1724
@Query("select distinct m from MerchantStore m left join fetch m.parent mp left join fetch m.country mc left join fetch m.currency mc left join fetch m.zone mz left join fetch m.defaultLanguage md left join fetch m.languages mls where mp.code = ?1")

sm-core/src/main/java/com/salesmanager/core/business/services/catalog/catalog/CatalogService.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.salesmanager.core.business.services.catalog.catalog;
22

3-
import java.util.List;
4-
53
import org.springframework.data.domain.Page;
64

75
import com.salesmanager.core.business.exception.ServiceException;
@@ -20,7 +18,7 @@ public interface CatalogService extends SalesManagerEntityService<Long, Catalog>
2018
* @return Catalog
2119
* @throws ServiceException
2220
*/
23-
Catalog create(MerchantStore store, String code) throws ServiceException;
21+
Catalog saveOrUddate(Catalog catalog, MerchantStore store, String code) throws ServiceException;
2422

2523
/**
2624
* Get a list of Catalog associated with a MarketPlace

sm-core/src/main/java/com/salesmanager/core/business/services/catalog/catalog/CatalogServiceImpl.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import javax.inject.Inject;
44

5+
import org.jsoup.helper.Validate;
6+
import org.springframework.beans.factory.annotation.Autowired;
57
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.PageRequest;
9+
import org.springframework.data.domain.Pageable;
610
import org.springframework.stereotype.Service;
711

812
import com.salesmanager.core.business.exception.ServiceException;
913
import com.salesmanager.core.business.repositories.catalog.catalog.CatalogRepository;
14+
import com.salesmanager.core.business.repositories.catalog.catalog.PageableCatalogRepository;
1015
import com.salesmanager.core.business.services.common.generic.SalesManagerEntityServiceImpl;
1116
import com.salesmanager.core.model.catalog.catalog.Catalog;
1217
import com.salesmanager.core.model.merchant.MerchantStore;
@@ -18,31 +23,35 @@ public class CatalogServiceImpl
1823
implements CatalogService {
1924

2025

21-
private CatalogRepository catalogEntryRepository;
26+
private CatalogRepository catalogRepository;
27+
28+
@Autowired
29+
private PageableCatalogRepository pageableCatalogRepository;
2230

2331
@Inject
2432
public CatalogServiceImpl(CatalogRepository repository) {
2533
super(repository);
26-
this.catalogEntryRepository = repository;
34+
this.catalogRepository = repository;
2735
}
2836

2937
@Override
30-
public Catalog create(MerchantStore store, String code) throws ServiceException {
31-
// TODO Auto-generated method stub
32-
return null;
38+
public Catalog saveOrUddate(Catalog catalog, MerchantStore store, String code) throws ServiceException {
39+
40+
catalogRepository.save(catalog);
41+
return catalog;
3342
}
3443

3544
@Override
3645
public Page<Catalog> getCatalogs(MerchantStore store, Language language, String name, int page, int count)
3746
throws ServiceException {
38-
// TODO Auto-generated method stub
39-
return null;
47+
Pageable pageRequest = new PageRequest(page, count);
48+
return pageableCatalogRepository.listByStore(store.getId(), name, pageRequest);
4049
}
4150

4251
@Override
4352
public void delete(Catalog catalog) throws ServiceException {
44-
// TODO Auto-generated method stub
45-
53+
Validate.notNull(catalog,"Catalog must not be null");
54+
catalogRepository.delete(catalog);
4655
}
4756

4857
}

sm-core/src/test/java/com/salesmanager/test/catalog/CategoryTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package com.salesmanager.test.catalog;
22

33
import static org.junit.Assert.assertNotNull;
4+
45
import java.util.HashSet;
56
import java.util.Set;
7+
68
import org.junit.Test;
9+
710
import com.salesmanager.core.business.exception.ServiceException;
811
import com.salesmanager.core.model.catalog.category.Category;
912
import com.salesmanager.core.model.catalog.category.CategoryDescription;
1013
import com.salesmanager.core.model.merchant.MerchantStore;
1114
import com.salesmanager.core.model.reference.language.Language;
15+
1216
import junit.framework.Assert;
1317

1418

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.salesmanager.shop.model.content;
2+
3+
import com.salesmanager.shop.model.catalog.NamedEntity;
4+
5+
public class ReadableContentDescription extends NamedEntity {
6+
7+
/**
8+
*
9+
*/
10+
private static final long serialVersionUID = 1L;
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.salesmanager.shop.model.content;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.salesmanager.shop.model.entity.Entity;
7+
8+
public class ReadableContentFull extends Entity {
9+
10+
private String code;
11+
private boolean visible;
12+
private String contentType;
13+
14+
private boolean isDisplayedInMenu;
15+
16+
17+
/**
18+
*
19+
*/
20+
private static final long serialVersionUID = 1L;
21+
private List<ReadableContentDescription> descriptions = new ArrayList<ReadableContentDescription>();
22+
public List<ReadableContentDescription> getDescriptions() {
23+
return descriptions;
24+
}
25+
public void setDescriptions(List<ReadableContentDescription> descriptions) {
26+
this.descriptions = descriptions;
27+
}
28+
public String getCode() {
29+
return code;
30+
}
31+
public void setCode(String code) {
32+
this.code = code;
33+
}
34+
35+
public boolean isVisible() {
36+
return visible;
37+
}
38+
public void setVisible(boolean visible) {
39+
this.visible = visible;
40+
}
41+
public String getContentType() {
42+
return contentType;
43+
}
44+
public void setContentType(String contentType) {
45+
this.contentType = contentType;
46+
}
47+
public boolean isDisplayedInMenu() {
48+
return isDisplayedInMenu;
49+
}
50+
public void setDisplayedInMenu(boolean isDisplayedInMenu) {
51+
this.isDisplayedInMenu = isDisplayedInMenu;
52+
}
53+
54+
}

sm-shop-model/src/main/java/com/salesmanager/shop/store/controller/content/facade/ContentFacade.java

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.salesmanager.shop.model.content.PersistableContent;
1010
import com.salesmanager.shop.model.content.PersistableContentPage;
1111
import com.salesmanager.shop.model.content.ReadableContentBox;
12+
import com.salesmanager.shop.model.content.ReadableContentFull;
1213
import com.salesmanager.shop.model.content.ReadableContentPage;
1314

1415
/**
@@ -103,5 +104,7 @@ public interface ContentFacade {
103104
* @param language
104105
*/
105106
void saveContentPage(PersistableContent page, MerchantStore merchantStore, Language language);
107+
108+
ReadableContentFull getContent(String code, MerchantStore store, Language language);
106109

107110
}

sm-shop/SALESMANAGER-TEST.h2.db

0 Bytes
Binary file not shown.

sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/PersistableCatalogMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.salesmanager.shop.mapper.catalog;
22

3+
import org.springframework.stereotype.Component;
4+
35
import com.salesmanager.core.model.catalog.catalog.Catalog;
46
import com.salesmanager.core.model.merchant.MerchantStore;
57
import com.salesmanager.core.model.reference.language.Language;
68
import com.salesmanager.shop.mapper.Mapper;
79
import com.salesmanager.shop.model.catalog.catalog.PersistableCatalog;
810

11+
@Component
912
public class PersistableCatalogMapper implements Mapper<PersistableCatalog, Catalog> {
1013

1114
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.salesmanager.shop.mapper.catalog;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import com.salesmanager.core.model.catalog.catalog.Catalog;
6+
import com.salesmanager.core.model.merchant.MerchantStore;
7+
import com.salesmanager.core.model.reference.language.Language;
8+
import com.salesmanager.shop.mapper.Mapper;
9+
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalog;
10+
11+
@Component
12+
public class ReadableCatalogMapper implements Mapper<Catalog, ReadableCatalog> {
13+
14+
@Override
15+
public ReadableCatalog convert(Catalog source, MerchantStore store, Language language) {
16+
// TODO Auto-generated method stub
17+
return null;
18+
}
19+
20+
@Override
21+
public ReadableCatalog convert(Catalog source, ReadableCatalog destination, MerchantStore store,
22+
Language language) {
23+
// TODO Auto-generated method stub
24+
return null;
25+
}
26+
27+
}

sm-shop/src/main/java/com/salesmanager/shop/mapper/catalog/ReadableCategoryMapper.java

-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public ReadableCategory convert(Category source, MerchantStore store, Language l
2525

2626
feedDescription(source, language, target);
2727

28-
/* Optional<com.salesmanager.shop.model.catalog.category.CategoryDescription> categoryDescription =
29-
getCategoryDescription(source, language, target);
30-
categoryDescription.ifPresent(target::setDescription);*/
3128

3229
Optional<com.salesmanager.shop.model.catalog.category.Category> parentCategory =
3330
createParentCategory(source);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.salesmanager.shop.store.api.v1.catalog;
2+
3+
import javax.validation.Valid;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.PathVariable;
9+
import org.springframework.web.bind.annotation.PostMapping;
10+
import org.springframework.web.bind.annotation.PutMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.ResponseStatus;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.http.HttpStatus;
16+
17+
import com.salesmanager.core.model.merchant.MerchantStore;
18+
import com.salesmanager.core.model.reference.language.Language;
19+
import com.salesmanager.shop.model.catalog.catalog.PersistableCatalog;
20+
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalog;
21+
import com.salesmanager.shop.store.controller.catalog.facade.CatalogFacade;
22+
23+
import io.swagger.annotations.Api;
24+
import io.swagger.annotations.ApiImplicitParam;
25+
import io.swagger.annotations.ApiImplicitParams;
26+
import io.swagger.annotations.ApiOperation;
27+
import io.swagger.annotations.SwaggerDefinition;
28+
import io.swagger.annotations.Tag;
29+
import springfox.documentation.annotations.ApiIgnore;
30+
31+
@RestController
32+
@RequestMapping(value = "/api/v1")
33+
@Api(tags = {"Catalog management resource (Catalog Management Api)"})
34+
@SwaggerDefinition(tags = {
35+
@Tag(name = "Catalog management resource", description = "Manage catalogs and attached products")
36+
})
37+
public class CatalogApi {
38+
39+
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogApi.class);
40+
41+
@Autowired
42+
private CatalogFacade catalogFacade;
43+
44+
45+
/* @GetMapping(value = "/content/folder", produces = MediaType.APPLICATION_JSON_VALUE)
46+
@ApiImplicitParams({
47+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
48+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
49+
public ContentFolder folder(@RequestParam(value = "path", required = false) String path,
50+
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception {
51+
String decodedPath = decodeContentPath(path);
52+
return contentFacade.getContentFolder(decodedPath, merchantStore);
53+
}
54+
55+
*/
56+
57+
58+
59+
@PostMapping(value = "/private/catalog")
60+
@ResponseStatus(HttpStatus.OK)
61+
@ApiOperation(httpMethod = "POST", value = "Create catalog", notes = "",
62+
response = Void.class)
63+
@ApiImplicitParams({
64+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
65+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
66+
public ReadableCatalog createCatalog(
67+
@RequestBody @Valid PersistableCatalog catalog,
68+
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
69+
70+
return catalogFacade.saveCatalog(catalog, merchantStore);
71+
72+
}
73+
74+
@PutMapping(value = "/private/catalog/{id}")
75+
@ResponseStatus(HttpStatus.OK)
76+
@ApiOperation(httpMethod = "PUT", value = "Update catalog", notes = "",
77+
response = Void.class)
78+
@ApiImplicitParams({
79+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
80+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
81+
public void updateCatalog(
82+
@PathVariable Long id,
83+
@RequestBody @Valid PersistableCatalog catalog,
84+
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
85+
86+
catalog.setId(id);
87+
catalogFacade.saveCatalog(catalog, merchantStore);
88+
}
89+
90+
91+
92+
/* @DeleteMapping(value = "/private/content/")
93+
@ApiOperation(httpMethod = "DETETE", value = "Deletes a file from CMS", notes = "Delete a file from server",
94+
response = Void.class)
95+
@ApiImplicitParams({
96+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
97+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
98+
public void deleteFile(
99+
@Valid ContentName name,
100+
@ApiIgnore MerchantStore merchantStore,
101+
@ApiIgnore Language language) {
102+
contentFacade.delete(merchantStore, name.getName(), name.getContentType());
103+
}*/
104+
}

0 commit comments

Comments
 (0)