use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShoppingCartApi method getByCustomer.
@Deprecated
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/{id}/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by customer id. Customer must be authenticated", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
// customer
@ResponseBody
public // customer
ReadableShoppingCart getByCustomer(// customer
@PathVariable Long id, // cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
Principal principal = request.getUserPrincipal();
// lookup customer
Customer customer = customerService.getById(id);
if (customer == null) {
throw new ResourceNotFoundException("No Customer found for id [" + id + "]");
}
customerFacadev1.authorize(customer, principal);
ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, id, merchantStore, language);
if (readableCart == null) {
throw new ResourceNotFoundException("No cart found for customerid [" + id + "]");
}
return readableCart;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShoppingCartApi method getByCustomer.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/auth/customer/cart", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "Get a shopping cart by authenticated customer", notes = "", produces = "application/json", response = ReadableShoppingCart.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
@ResponseBody
public ReadableShoppingCart getByCustomer(// cart code
@RequestParam Optional<String> cart, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, HttpServletRequest request, HttpServletResponse response) {
Principal principal = request.getUserPrincipal();
Customer customer = null;
try {
customer = customerFacade.getCustomerByUserName(principal.getName(), merchantStore);
} catch (Exception e) {
throw new ServiceRuntimeException("Exception while getting customer [ " + principal.getName() + "]");
}
if (customer == null) {
throw new ResourceNotFoundException("No Customer found for principal[" + principal.getName() + "]");
}
customerFacadev1.authorize(customer, principal);
ReadableShoppingCart readableCart = shoppingCartFacadev1.get(cart, customer.getId(), merchantStore, language);
if (readableCart == null) {
throw new ResourceNotFoundException("No cart found for customer [" + principal.getName() + "]");
}
return readableCart;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method modifyCart.
@Override
public ReadableShoppingCart modifyCart(String cartCode, PersistableShoppingCartItem item, MerchantStore store, Language language) throws Exception {
Validate.notNull(cartCode, "String cart code cannot be null");
Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
ShoppingCart cartModel = getCartModel(cartCode, store);
if (cartModel == null) {
throw new ResourceNotFoundException("Cart code [" + cartCode + "] not found");
}
return modifyCart(cartModel, item, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method deleteCustomerReview.
@Override
public void deleteCustomerReview(Long customerId, Long reviewId, MerchantStore store, Language language) {
CustomerReview customerReview = getCustomerReviewById(reviewId);
if (!customerReview.getReviewedCustomer().getId().equals(customerId)) {
throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
}
deleteCustomerReview(customerReview);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateCustomerReview.
@Override
public PersistableCustomerReview updateCustomerReview(Long id, Long reviewId, PersistableCustomerReview review, MerchantStore store, Language language) {
CustomerReview customerReview = getCustomerReviewById(reviewId);
if (!customerReview.getReviewedCustomer().getId().equals(id)) {
throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
}
// rating maximum 5
if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
throw new ServiceRuntimeException("Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
}
review.setReviewedCustomer(id);
return review;
}
Aggregations