Skip to content

Commit

Permalink
Feat: 상품 수정, 삭제 권한 확인 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Taekgil99 committed Dec 2, 2022
1 parent 650d6db commit 606133c
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public Product create(Long userId, int price, String productName,TitleImg titleI
@Transactional
public Product update(Long productId, Long categoryId, int price , String productName, TitleImg titleImg, DetailImg detailImg, User user) {
Product findProduct = productRepository.findById(productId).orElseThrow(ProductNotFound::new);
checkPermission(productId, user);

if (!user.getEmail().equals("admin@luxmeal.xyz") && !user.getUserRole().equals("ROLE_ADMIN"))
throw new BusinessLogicException(ExceptionCode.HANDLE_ACCESS_DENIED);

log.info(" findProduct : ",findProduct);
Category category = categoryRepository.findById(categoryId).orElseThrow(CategoryNotFound::new);
log.info(" category : ", category);
Expand Down Expand Up @@ -116,7 +119,10 @@ public Product update(Long productId, Long categoryId, int price , String produc
@Transactional
public Long delete(Long productId, User user) {
Product product = productRepository.findById(productId).orElseThrow(ProductNotFound::new);
checkPermission(productId, user);

if (!user.getEmail().equals("admin@luxmeal.xyz") && !user.getUserRole().equals("ROLE_ADMIN"))
throw new BusinessLogicException(ExceptionCode.HANDLE_ACCESS_DENIED);

log.info(" product : ", product);
productRepository.delete(product);
log.info(" 상품 삭제 ");
Expand Down Expand Up @@ -209,9 +215,4 @@ public List<Product> random() {
}
return list;
}
private void checkPermission(Long productId, User user) {
if (productRepository.existsByProductIdAndUserUserId(productId, user.getUserId()) || user.getUserRole().equals("ROLE_ADMIN_TEST")) {
throw new BusinessLogicException(ExceptionCode.HANDLE_ACCESS_DENIED);
}
}
}

0 comments on commit 606133c

Please sign in to comment.