๋ฐ์ํ
์ค๋์ ์๋ฌ ๐ฅ
์ฒ์์ Order์ User๋ฅผ Lazy ์ ๋ต์ผ๋ก ์ค์ ํ์๋ค
๊ทธ๋ฐ๋ฐ
@Transactional
public void updateInCart(Long orderId, BasketRequestDto requestDto, User user) {
Order order = orderRepository.findByIdAndIsOrdered(orderId, false).orElseThrow(
() -> new ApiException(ErrorCode.INVALID_CART)
);
checkUserOrRole(user, order);
menuService.findMenu(requestDto.getMenu_id());
for (Basket basket : order.getBaskets()) {
if (Objects.equals(basket.getMenu().getId(), requestDto.getMenu_id())) {
order.deleteBasket(basket);
basket.updateCount(requestDto);
order.addBasket(basket);
return;
}
}
throw new ApiException(ErrorCode.INVALID_MENU_IN_CART);
}
private static void checkUserOrRole(User user, Order order) {
if (!order.getUser().getUsername().equals(loginUser.getUsername()) && !loginUser.getRole().equals(UserRoleEnum.ADMIN)) {
throw new ApiException(ErrorCode.INVALID_USER);
}
}
์ด ์ฝ๋์์ order.getUser() ๊ฐ null! ์ ๋๋ก sql ๋ฌธ์ ํ์ธํ์ง ์์ ์๋ชป
728x90
๋ฐ์ํ
'TIL๐ฅ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
23.12.11 TIL (1) | 2023.12.11 |
---|---|
23.12.08 TIL (0) | 2023.12.09 |
23.12.06 TIL (0) | 2023.12.06 |
23.12.05 TIL (0) | 2023.12.05 |
23.12.04 TIL (0) | 2023.12.04 |