-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into feature/78_june-777_판…
…매금액정산
- Loading branch information
Showing
59 changed files
with
3,373 additions
and
13 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
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
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/menu/exception/InvalidMenuPriceUpdateException.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,9 @@ | ||
package camp.woowak.lab.menu.exception; | ||
|
||
import camp.woowak.lab.common.exception.BadRequestException; | ||
|
||
public class InvalidMenuPriceUpdateException extends BadRequestException { | ||
public InvalidMenuPriceUpdateException(String message) { | ||
super(MenuErrorCode.INVALID_PRICE, message); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/menu/exception/InvalidMenuStockUpdateException.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,9 @@ | ||
package camp.woowak.lab.menu.exception; | ||
|
||
import camp.woowak.lab.common.exception.ConflictException; | ||
|
||
public class InvalidMenuStockUpdateException extends ConflictException { | ||
public InvalidMenuStockUpdateException(String message) { | ||
super(MenuErrorCode.INVALID_UPDATE_MENU_STOCK, message); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/menu/exception/MenuOwnerNotMatchException.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,9 @@ | ||
package camp.woowak.lab.menu.exception; | ||
|
||
import camp.woowak.lab.common.exception.ForbiddenException; | ||
|
||
public class MenuOwnerNotMatchException extends ForbiddenException { | ||
public MenuOwnerNotMatchException(String message) { | ||
super(MenuErrorCode.MENU_OWNER_NOT_MATCH, message); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/menu/exception/NotEqualsOwnerException.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,9 @@ | ||
package camp.woowak.lab.menu.exception; | ||
|
||
import camp.woowak.lab.common.exception.BadRequestException; | ||
|
||
public class NotEqualsOwnerException extends BadRequestException { | ||
public NotEqualsOwnerException(String message) { | ||
super(MenuErrorCode.NOT_EQUALS_OWNER, message); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/menu/exception/NotUpdatableTimeException.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,9 @@ | ||
package camp.woowak.lab.menu.exception; | ||
|
||
import camp.woowak.lab.common.exception.ConflictException; | ||
|
||
public class NotUpdatableTimeException extends ConflictException { | ||
public NotUpdatableTimeException(String message) { | ||
super(MenuErrorCode.NOT_UPDATABLE_TIME, message); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/java/camp/woowak/lab/menu/service/MenuPriceUpdateService.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,48 @@ | ||
package camp.woowak.lab.menu.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import camp.woowak.lab.menu.domain.Menu; | ||
import camp.woowak.lab.menu.exception.MenuOwnerNotMatchException; | ||
import camp.woowak.lab.menu.exception.UnauthorizedMenuCategoryCreationException; | ||
import camp.woowak.lab.menu.repository.MenuRepository; | ||
import camp.woowak.lab.menu.service.command.MenuPriceUpdateCommand; | ||
import camp.woowak.lab.order.exception.NotFoundMenuException; | ||
import camp.woowak.lab.store.domain.Store; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Service | ||
@Slf4j | ||
public class MenuPriceUpdateService { | ||
private final MenuRepository menuRepository; | ||
|
||
public MenuPriceUpdateService(MenuRepository menuRepository) { | ||
this.menuRepository = menuRepository; | ||
} | ||
|
||
/** | ||
* @throws camp.woowak.lab.menu.exception.InvalidMenuPriceUpdateException 업데이트 하려는 가격이 0 또는 음수인 경우 | ||
* @throws UnauthorizedMenuCategoryCreationException 자신의 가게의 메뉴가 아닌 메뉴를 업데이트 하려는 경우 | ||
* @throws NotFoundMenuException 존재하지 않는 메뉴의 가격을 업데이트 하려는 경우 | ||
*/ | ||
@Transactional | ||
public long updateMenuPrice(MenuPriceUpdateCommand cmd) { | ||
Menu menu = menuRepository.findByIdWithStore(cmd.menuId()) | ||
.orElseThrow(() -> { | ||
log.info("등록되지 않은 메뉴 {}의 가격 수정을 시도했습니다.", cmd.menuId()); | ||
throw new NotFoundMenuException("등록되지 않은 Menu의 가격 수정을 시도했습니다."); | ||
}); | ||
|
||
Store store = menu.getStore(); | ||
if (!store.isOwnedBy(cmd.vendorId())) { | ||
log.info("권한없는 사용자 {}가 점포 {}의 메뉴 가격 수정을 시도했습니다.", cmd.vendorId(), store.getId()); | ||
throw new MenuOwnerNotMatchException("권한없는 사용자가 메뉴 가격 수정을 시도했습니다."); | ||
} | ||
|
||
long updatedPrice = menu.updatePrice(cmd.updatePrice()); | ||
log.info("Store({}) 의 메뉴({}) 가격을 ({})로 수정했습니다.", store.getId(), menu.getId(), cmd.updatePrice()); | ||
|
||
return updatedPrice; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/camp/woowak/lab/menu/service/UpdateMenuStockService.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,56 @@ | ||
package camp.woowak.lab.menu.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import camp.woowak.lab.cart.exception.MenuNotFoundException; | ||
import camp.woowak.lab.menu.domain.Menu; | ||
import camp.woowak.lab.menu.exception.InvalidMenuStockUpdateException; | ||
import camp.woowak.lab.menu.exception.NotEqualsOwnerException; | ||
import camp.woowak.lab.menu.exception.NotUpdatableTimeException; | ||
import camp.woowak.lab.menu.repository.MenuRepository; | ||
import camp.woowak.lab.menu.service.command.UpdateMenuStockCommand; | ||
|
||
@Service | ||
public class UpdateMenuStockService { | ||
private final MenuRepository menuRepository; | ||
|
||
public UpdateMenuStockService(MenuRepository menuRepository) { | ||
this.menuRepository = menuRepository; | ||
} | ||
|
||
/** | ||
* | ||
* @throws MenuNotFoundException 메뉴를 찾을 수 없는 경우 발생한다. | ||
* @throws NotEqualsOwnerException 메뉴를 소유한 가게의 주인이 아닌 경우 발생한다. | ||
* @throws NotUpdatableTimeException 가게가 열려있지 않은 경우 발생한다. | ||
* @throws InvalidMenuStockUpdateException 메뉴의 재고를 변경할 수 없는 경우 발생한다. | ||
*/ | ||
@Transactional | ||
public Long updateMenuStock(UpdateMenuStockCommand cmd) { | ||
// 수량을 변경하려는 메뉴를 조회한다. | ||
Menu targetMenu = findMenuByIdForUpdateOrThrow(cmd.menuId()); | ||
|
||
// 메뉴를 소유한 가게를 조회한다. | ||
if (!targetMenu.getStore().isOwnedBy(cmd.vendorId())) { | ||
throw new NotEqualsOwnerException("메뉴를 소유한 가게의 주인이 아닙니다."); | ||
} | ||
|
||
// 가게가 열려있는지 확인한다. | ||
if (targetMenu.getStore().isOpen()) { | ||
throw new NotUpdatableTimeException("가게가 열려 있습니다."); | ||
} | ||
|
||
// 메뉴의 재고를 변경한다. | ||
int modifiedRow = menuRepository.updateStock(cmd.menuId(), cmd.stock()); | ||
if (modifiedRow != 1) { // 변경된 메뉴의 개수가 1이 아닌 경우 예외를 발생시킨다. | ||
throw new InvalidMenuStockUpdateException("변경의 영향을 받은 메뉴의 개수가 1이 아닙니다."); | ||
} | ||
|
||
return targetMenu.getId(); | ||
} | ||
|
||
private Menu findMenuByIdForUpdateOrThrow(Long menuId) { | ||
return menuRepository.findByIdForUpdate(menuId).orElseThrow(() -> new MenuNotFoundException("메뉴를 찾을 수 없습니다.")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/camp/woowak/lab/menu/service/command/MenuPriceUpdateCommand.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,15 @@ | ||
package camp.woowak.lab.menu.service.command; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* @param vendorId 업데이트를 시도하는 vendor의 id | ||
* @param menuId 업데이트 할 menu의 id | ||
* @param updatePrice 업데이트 할 가격 | ||
*/ | ||
public record MenuPriceUpdateCommand( | ||
UUID vendorId, | ||
Long menuId, | ||
Long updatePrice | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/camp/woowak/lab/menu/service/command/UpdateMenuStockCommand.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,6 @@ | ||
package camp.woowak.lab.menu.service.command; | ||
|
||
import java.util.UUID; | ||
|
||
public record UpdateMenuStockCommand(Long menuId, int stock, UUID vendorId) { | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/order/repository/OrderRepository.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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package camp.woowak.lab.order.repository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import camp.woowak.lab.order.domain.Order; | ||
|
||
public interface OrderRepository extends JpaRepository<Order, Long> { | ||
@Query("SELECT o FROM Order o JOIN FETCH o.store s WHERE s.owner.id = :vendorId") | ||
List<Order> findAllByOwner(UUID vendorId); | ||
|
||
@Query("SELECT o FROM Order o JOIN FETCH o.store s WHERE s.id = :storeId AND s.owner.id = :vendorId") | ||
List<Order> findByStore(Long storeId, UUID vendorId); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/camp/woowak/lab/order/service/RetrieveOrderListService.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 camp.woowak.lab.order.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import camp.woowak.lab.order.repository.OrderRepository; | ||
import camp.woowak.lab.order.service.command.RetrieveOrderListCommand; | ||
import camp.woowak.lab.order.service.dto.OrderDTO; | ||
import camp.woowak.lab.store.domain.Store; | ||
import camp.woowak.lab.store.exception.NotEqualsOwnerException; | ||
import camp.woowak.lab.store.exception.NotFoundStoreException; | ||
import camp.woowak.lab.store.repository.StoreRepository; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class RetrieveOrderListService { | ||
private final OrderRepository orderRepository; | ||
private final StoreRepository storeRepository; | ||
|
||
public RetrieveOrderListService(OrderRepository orderRepository, StoreRepository storeRepository) { | ||
this.orderRepository = orderRepository; | ||
this.storeRepository = storeRepository; | ||
} | ||
|
||
public List<OrderDTO> retrieveOrderListOfVendorStores(RetrieveOrderListCommand command) { | ||
// 점주 매장 주문 조회 권한 검증은 필요없다. | ||
return orderRepository.findAllByOwner(command.vendorId()).stream().map(OrderDTO::new).toList(); | ||
} | ||
|
||
/** | ||
* | ||
* @throws NotFoundStoreException 매장이 존재하지 않을 경우 | ||
* @throws NotEqualsOwnerException 매장의 주인이 아닐 경우 | ||
*/ | ||
public List<OrderDTO> retrieveOrderListOfStore(RetrieveOrderListCommand command) { | ||
// 점주 매장 주문 조회 권한 검증 | ||
// 점주가 소유한 매장인지 확인 | ||
Store targetStore = storeRepository.findById(command.storeId()) | ||
.orElseThrow(() -> new NotFoundStoreException("해당 매장이 존재하지 않습니다.")); | ||
|
||
if (!targetStore.isOwnedBy(command.vendorId())) { | ||
throw new NotEqualsOwnerException(command.vendorId() + "는 " + targetStore.getId() + " 매장의 주인이 아닙니다."); | ||
} | ||
|
||
return orderRepository.findByStore(command.storeId(), command.vendorId()).stream().map(OrderDTO::new).toList(); | ||
} | ||
} |
Oops, something went wrong.