-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,271 additions
and
741 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
## Mac files | ||
.DS_Store | ||
|
||
## Drawio source files ## | ||
*.drawio | ||
|
||
|
49 changes: 49 additions & 0 deletions
49
product-service/src/main/java/com/siriusxi/ms/store/ps/api/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.siriusxi.ms.store.ps.api; | ||
|
||
import com.siriusxi.ms.store.api.core.product.ProductEndpoint; | ||
import com.siriusxi.ms.store.api.core.product.ProductService; | ||
import com.siriusxi.ms.store.api.core.product.dto.Product; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Class <code>ProductController</code> is the implementation of the main Product Endpoint API | ||
* definition. | ||
* | ||
* @see ProductEndpoint | ||
* @author mohamed.taman | ||
* @version v1.0 | ||
* @since v3.0 codename Storm | ||
*/ | ||
@RestController | ||
@Log4j2 | ||
public class ProductController implements ProductEndpoint { | ||
|
||
/** Product service business logic interface. */ | ||
private final ProductService prodService; | ||
|
||
@Autowired | ||
public ProductController(@Qualifier("ProductServiceImpl") ProductService prodService) { | ||
this.prodService = prodService; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public Product getProduct(int id) { | ||
return prodService.getProduct(id); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public Product createProduct(Product body) { | ||
return prodService.createProduct(body); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void deleteProduct(int id) { | ||
prodService.deleteProduct(id); | ||
} | ||
} |
68 changes: 0 additions & 68 deletions
68
product-service/src/main/java/com/siriusxi/ms/store/ps/controller/ProductServiceImpl.java
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ms/store/ps/controller/ProductMapper.java → ...xi/ms/store/ps/service/ProductMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
product-service/src/main/java/com/siriusxi/ms/store/ps/service/ProductServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.siriusxi.ms.store.ps.service; | ||
|
||
import com.siriusxi.ms.store.api.core.product.ProductService; | ||
import com.siriusxi.ms.store.api.core.product.dto.Product; | ||
import com.siriusxi.ms.store.ps.persistence.ProductEntity; | ||
import com.siriusxi.ms.store.ps.persistence.ProductRepository; | ||
import com.siriusxi.ms.store.util.exceptions.InvalidInputException; | ||
import com.siriusxi.ms.store.util.exceptions.NotFoundException; | ||
import com.siriusxi.ms.store.util.http.ServiceUtil; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.dao.DuplicateKeyException; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service("ProductServiceImpl") | ||
@Log4j2 | ||
public class ProductServiceImpl implements ProductService { | ||
|
||
private final ServiceUtil serviceUtil; | ||
|
||
private final ProductRepository repository; | ||
|
||
private final ProductMapper mapper; | ||
|
||
@Autowired | ||
public ProductServiceImpl( | ||
ProductRepository repository, ProductMapper mapper, ServiceUtil serviceUtil) { | ||
this.repository = repository; | ||
this.mapper = mapper; | ||
this.serviceUtil = serviceUtil; | ||
} | ||
|
||
@Override | ||
public Product createProduct(Product body) { | ||
try { | ||
ProductEntity entity = mapper.apiToEntity(body); | ||
ProductEntity newEntity = repository.save(entity); | ||
|
||
log.debug("createProduct: entity created for productId: {}", body.getProductId()); | ||
return mapper.entityToApi(newEntity); | ||
|
||
} catch (DuplicateKeyException dke) { | ||
throw new InvalidInputException("Duplicate key, Product Id: " + body.getProductId()); | ||
} | ||
} | ||
|
||
@Override | ||
public Product getProduct(int productId) { | ||
if (productId < 1) throw new InvalidInputException("Invalid productId: " + productId); | ||
|
||
ProductEntity entity = | ||
repository | ||
.findByProductId(productId) | ||
.orElseThrow( | ||
() -> new NotFoundException("No product found for productId: " + productId)); | ||
|
||
Product response = mapper.entityToApi(entity); | ||
response.setServiceAddress(serviceUtil.getServiceAddress()); | ||
|
||
log.debug("getProduct: found productId: {}", response.getProductId()); | ||
|
||
return response; | ||
} | ||
|
||
/* | ||
Implementation is idempotent, that is, | ||
it will not report any failure if the entity is not found Always 200 | ||
*/ | ||
@Override | ||
public void deleteProduct(int productId) { | ||
log.debug("deleteProduct: tries to delete an entity with productId: {}", productId); | ||
repository.findByProductId(productId).ifPresent(repository::delete); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
product-service/src/test/java/com/siriusxi/ms/store/ps/MapperTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.