Skip to content

Commit 308646b

Browse files
CatalogApi
1 parent 11eb99a commit 308646b

File tree

15 files changed

+233
-36
lines changed

15 files changed

+233
-36
lines changed

sm-core-model/src/main/java/com/salesmanager/core/model/catalog/catalog/Catalog.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.persistence.ManyToOne;
1616
import javax.persistence.OneToMany;
1717
import javax.persistence.Table;
18+
import javax.persistence.UniqueConstraint;
1819
import javax.validation.Valid;
1920

2021
import org.hibernate.annotations.GenericGenerator;
@@ -44,7 +45,8 @@
4445

4546
@Entity
4647
@EntityListeners(value = com.salesmanager.core.model.common.audit.AuditListener.class)
47-
@Table(name = "CATALOG", schema=SchemaConstant.SALESMANAGER_SCHEMA)
48+
@Table(name = "CATALOG", schema=SchemaConstant.SALESMANAGER_SCHEMA,
49+
uniqueConstraints=@UniqueConstraint(columnNames = {"MERCHANT_ID", "CODE"}))
4850
public class Catalog extends SalesManagerEntity<Long, Catalog> implements Auditable {
4951
private static final long serialVersionUID = 1L;
5052

sm-core-model/src/main/java/com/salesmanager/core/model/catalog/catalog/CatalogEntry.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import javax.persistence.JoinColumn;
99
import javax.persistence.ManyToOne;
1010
import javax.persistence.Table;
11+
import javax.persistence.UniqueConstraint;
1112

1213
import org.hibernate.annotations.GenericGenerator;
1314
import org.hibernate.annotations.Parameter;
1415

16+
import com.salesmanager.core.constants.SchemaConstant;
1517
import com.salesmanager.core.model.catalog.category.Category;
1618
import com.salesmanager.core.model.catalog.product.Product;
1719
import com.salesmanager.core.model.common.audit.AuditSection;
@@ -20,7 +22,8 @@
2022

2123
@Entity
2224
@EntityListeners(value = com.salesmanager.core.model.common.audit.AuditListener.class)
23-
@Table(name="CATALOG_ENTRY")
25+
@Table(name = "CATALOG_ENTRY", schema= SchemaConstant.SALESMANAGER_SCHEMA,uniqueConstraints=
26+
@UniqueConstraint(columnNames = {"PRODUCT_ID", "CATEGORY_ID", "CATALOG_ID"}) )
2427
public class CatalogEntry extends SalesManagerEntity<Long, CatalogEntry> implements Auditable {
2528

2629

0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package com.salesmanager.core.business.repositories.catalog.catalog;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
45

56
import com.salesmanager.core.model.catalog.catalog.Catalog;
67

78
public interface CatalogRepository extends JpaRepository<Catalog, Long> {
9+
10+
11+
@Query("select c from Catalog c join fetch c.merchantStore cm where c.id=?1 and cm.id = ?2")
12+
Catalog findById(Long catalogId, Integer merchantId);
13+
14+
@Query("select c from Catalog c join fetch c.merchantStore cm where c.code=?1 and cm.id = ?2")
15+
Catalog findByCode(String code, Integer merchantId);
816

917
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ public interface CatalogService extends SalesManagerEntityService<Long, Catalog>
1414
/**
1515
* Creates a new Catalog
1616
* @param store
17-
* @param code
1817
* @return Catalog
1918
* @throws ServiceException
2019
*/
21-
Catalog saveOrUddate(Catalog catalog, MerchantStore store, String code) throws ServiceException;
20+
Catalog saveOrUddate(Catalog catalog, MerchantStore store) throws ServiceException;
21+
22+
Catalog getById(Long catalogId, MerchantStore store);
23+
24+
Catalog getByCode(String code, MerchantStore store);
2225

2326
/**
2427
* Get a list of Catalog associated with a MarketPlace

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public CatalogServiceImpl(CatalogRepository repository) {
3535
}
3636

3737
@Override
38-
public Catalog saveOrUddate(Catalog catalog, MerchantStore store, String code) throws ServiceException {
39-
38+
public Catalog saveOrUddate(Catalog catalog, MerchantStore store) throws ServiceException {
4039
catalogRepository.save(catalog);
4140
return catalog;
4241
}
@@ -54,4 +53,14 @@ public void delete(Catalog catalog) throws ServiceException {
5453
catalogRepository.delete(catalog);
5554
}
5655

56+
@Override
57+
public Catalog getById(Long catalogId, MerchantStore store) {
58+
return catalogRepository.findById(catalogId, store.getId());
59+
}
60+
61+
@Override
62+
public Catalog getByCode(String code, MerchantStore store) {
63+
return catalogRepository.findByCode(code, store.getId());
64+
}
65+
5766
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
package com.salesmanager.shop.model.catalog.catalog;
22

3-
import com.salesmanager.shop.model.catalog.NamedEntity;
3+
import com.salesmanager.shop.model.shop.ReadableMerchantStore;
44

5-
public class ReadableCatalog extends NamedEntity {
5+
public class ReadableCatalog extends CatalogEntity {
66

77
/**
88
*
99
*/
1010
private static final long serialVersionUID = 1L;
1111
private String creationDate;
12+
private ReadableMerchantStore store;
1213
public String getCreationDate() {
1314
return creationDate;
1415
}
1516
public void setCreationDate(String creationDate) {
1617
this.creationDate = creationDate;
1718
}
19+
public ReadableMerchantStore getStore() {
20+
return store;
21+
}
22+
public void setStore(ReadableMerchantStore store) {
23+
this.store = store;
24+
}
25+
1826

1927
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package com.salesmanager.shop.store.controller.catalog.facade;
22

33
import com.salesmanager.core.model.merchant.MerchantStore;
4+
import com.salesmanager.core.model.reference.language.Language;
45
import com.salesmanager.shop.model.catalog.catalog.PersistableCatalog;
56
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalog;
67

78
public interface CatalogFacade {
89

9-
ReadableCatalog saveCatalog(PersistableCatalog catalog, MerchantStore store);
10+
ReadableCatalog saveCatalog(PersistableCatalog catalog, MerchantStore store, Language language);
1011

11-
void deleteCatalog(Long catalogId, MerchantStore store);
12+
void updateCatalog(Long catalogId, PersistableCatalog catalog, MerchantStore store, Language language);
1213

13-
ReadableCatalog getCatalog(Long catalogId, MerchantStore store);
14+
void deleteCatalog(Long catalogId, MerchantStore store, Language language);
15+
16+
ReadableCatalog getCatalog(String code, MerchantStore store, Language language);
17+
18+
ReadableCatalog getCatalog(Long id, MerchantStore store, Language language);
1419

1520
}

sm-shop/SALESMANAGER-TEST.h2.db

8 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
11
package com.salesmanager.shop.mapper.catalog;
22

3+
import org.springframework.beans.factory.annotation.Autowired;
34
import org.springframework.stereotype.Component;
45

56
import com.salesmanager.core.model.catalog.catalog.Catalog;
67
import com.salesmanager.core.model.merchant.MerchantStore;
78
import com.salesmanager.core.model.reference.language.Language;
89
import com.salesmanager.shop.mapper.Mapper;
910
import com.salesmanager.shop.model.catalog.catalog.ReadableCatalog;
11+
import com.salesmanager.shop.model.shop.ReadableMerchantStore;
12+
import com.salesmanager.shop.store.controller.store.facade.StoreFacade;
13+
import com.salesmanager.shop.utils.DateUtil;
1014

1115
@Component
1216
public class ReadableCatalogMapper implements Mapper<Catalog, ReadableCatalog> {
17+
18+
@Autowired
19+
private StoreFacade storeFacade;
1320

1421
@Override
1522
public ReadableCatalog convert(Catalog source, MerchantStore store, Language language) {
16-
// TODO Auto-generated method stub
17-
return null;
23+
ReadableCatalog destination = new ReadableCatalog();
24+
return convert(source, destination, store, language);
1825
}
1926

2027
@Override
2128
public ReadableCatalog convert(Catalog source, ReadableCatalog destination, MerchantStore store,
2229
Language language) {
23-
// TODO Auto-generated method stub
24-
return null;
30+
if(destination == null) {
31+
destination = new ReadableCatalog();
32+
}
33+
34+
if(source.getId()!=null && source.getId().longValue() >0) {
35+
destination.setId(source.getId());
36+
}
37+
38+
destination.setCode(source.getCode());
39+
40+
if(source.getMerchantStore() != null) {
41+
ReadableMerchantStore st = storeFacade.getByCode(source.getMerchantStore().getCode(), language);
42+
destination.setStore(st);
43+
}
44+
45+
destination.setDefaultCatalog(source.isDefaultCatalog());
46+
47+
if(source.getAuditSection()!=null) {
48+
destination.setCreationDate(DateUtil.formatDate(source.getAuditSection().getDateCreated()));
49+
}
50+
51+
return destination;
52+
2553
}
2654

2755
}

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

+30-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.web.bind.annotation.DeleteMapping;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PatchMapping;
811
import org.springframework.web.bind.annotation.PathVariable;
912
import org.springframework.web.bind.annotation.PostMapping;
1013
import org.springframework.web.bind.annotation.PutMapping;
@@ -67,13 +70,13 @@ public ReadableCatalog createCatalog(
6770
@RequestBody @Valid PersistableCatalog catalog,
6871
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
6972

70-
return catalogFacade.saveCatalog(catalog, merchantStore);
73+
return catalogFacade.saveCatalog(catalog, merchantStore, language);
7174

7275
}
7376

74-
@PutMapping(value = "/private/catalog/{id}")
77+
@PatchMapping(value = "/private/catalog/{id}")
7578
@ResponseStatus(HttpStatus.OK)
76-
@ApiOperation(httpMethod = "PUT", value = "Update catalog", notes = "",
79+
@ApiOperation(httpMethod = "PATCH", value = "Update catalog", notes = "",
7780
response = Void.class)
7881
@ApiImplicitParams({
7982
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
@@ -84,21 +87,38 @@ public void updateCatalog(
8487
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
8588

8689
catalog.setId(id);
87-
catalogFacade.saveCatalog(catalog, merchantStore);
90+
catalogFacade.updateCatalog(id, catalog, merchantStore, language);
91+
92+
}
93+
94+
@GetMapping(value = "/private/catalog/{id}")
95+
@ResponseStatus(HttpStatus.OK)
96+
@ApiOperation(httpMethod = "GET", value = "Get catalog", notes = "",
97+
response = Void.class)
98+
@ApiImplicitParams({
99+
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
100+
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
101+
public ReadableCatalog getCatalog(
102+
@PathVariable Long id,
103+
@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
104+
105+
return catalogFacade.getCatalog(id, merchantStore, language);
106+
88107
}
89108

90109

91110

92-
/* @DeleteMapping(value = "/private/content/")
93-
@ApiOperation(httpMethod = "DETETE", value = "Deletes a file from CMS", notes = "Delete a file from server",
111+
@DeleteMapping(value = "/private/catalog/{id}")
112+
@ApiOperation(httpMethod = "DETETE", value = "Deletes a catalog", notes = "",
94113
response = Void.class)
95114
@ApiImplicitParams({
96115
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),
97116
@ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en")})
98-
public void deleteFile(
99-
@Valid ContentName name,
117+
public void deleteCatalog(
118+
@PathVariable Long id,
100119
@ApiIgnore MerchantStore merchantStore,
101120
@ApiIgnore Language language) {
102-
contentFacade.delete(merchantStore, name.getName(), name.getContentType());
103-
}*/
121+
122+
catalogFacade.deleteCatalog(id, merchantStore, language);
123+
}
104124
}

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductGroupApi.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.stereotype.Controller;
1111
import org.springframework.web.bind.annotation.DeleteMapping;
1212
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.PatchMapping;
1314
import org.springframework.web.bind.annotation.PathVariable;
1415
import org.springframework.web.bind.annotation.RequestBody;
1516
import org.springframework.web.bind.annotation.RequestMapping;
@@ -72,7 +73,7 @@ public class ProductGroupApi {
7273
}
7374

7475
@ResponseStatus(HttpStatus.OK)
75-
@GetMapping("/private/products/group/{code}")
76+
@PatchMapping("/private/products/group/{code}")
7677
@ApiOperation(httpMethod = "PATCH", value = "Update product group visible flag", notes = "", response = ProductGroup.class)
7778
@ApiImplicitParams({
7879
@ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"),

sm-shop/src/main/java/com/salesmanager/shop/store/api/v1/product/ProductOptionApi.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.salesmanager.shop.store.api.v1.product;
22

3-
import java.util.Optional;
4-
53
import javax.servlet.http.HttpServletRequest;
64
import javax.servlet.http.HttpServletResponse;
75
import javax.validation.Valid;

0 commit comments

Comments
 (0)