diff --git a/src/main/java/org/hankki/hankkiserver/api/menu/controller/MenuController.java b/src/main/java/org/hankki/hankkiserver/api/menu/controller/MenuController.java index 604b9784..56f8342a 100644 --- a/src/main/java/org/hankki/hankkiserver/api/menu/controller/MenuController.java +++ b/src/main/java/org/hankki/hankkiserver/api/menu/controller/MenuController.java @@ -1,6 +1,8 @@ package org.hankki.hankkiserver.api.menu.controller; import jakarta.validation.Valid; +import jakarta.validation.constraints.Min; +import java.util.List; import lombok.RequiredArgsConstructor; import org.hankki.hankkiserver.api.dto.HankkiResponse; import org.hankki.hankkiserver.api.menu.service.MenuCommandService; @@ -11,32 +13,41 @@ import org.hankki.hankkiserver.api.menu.service.response.MenusPostResponse; import org.hankki.hankkiserver.api.store.controller.request.MenuPostRequest; import org.hankki.hankkiserver.common.code.CommonSuccessCode; -import org.springframework.web.bind.annotation.*; - -import java.util.List; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor @RequestMapping("/api/v1") +@Validated public class MenuController { private final MenuCommandService menuCommandService; @DeleteMapping("/{storeId}/menus/{id}") - public HankkiResponse deleteMenu(@PathVariable("storeId") final Long storeId, @PathVariable("id") final Long id) { + public HankkiResponse deleteMenu(@PathVariable("storeId") @Min(value = 1L) final long storeId, + @PathVariable("id") @Min(value = 1L) final long id) { menuCommandService.deleteMenu(MenuDeleteCommand.of(storeId, id)); return HankkiResponse.success(CommonSuccessCode.NO_CONTENT); } @PatchMapping("/{storeId}/menus/{id}") - public HankkiResponse updateMenu(@PathVariable("storeId") final Long storeId, @PathVariable("id") final Long id, + public HankkiResponse updateMenu(@PathVariable("storeId") @Min(value = 1L) final long storeId, + @PathVariable("id") @Min(value = 1L) final long id, @Valid @RequestBody final MenuPostRequest request) { menuCommandService.modifyMenu(MenuPatchCommand.of(storeId, id, request.name(), request.price())); return HankkiResponse.success(CommonSuccessCode.OK); } @PostMapping("{storeId}/menus/bulk") - public HankkiResponse createMenu(@PathVariable final Long storeId, @Valid @RequestBody final List request) { + public HankkiResponse createMenu(@PathVariable @Min(value = 1L) final long storeId, + @Valid @RequestBody final List request) { List command = request.stream() .map(r -> MenuPostCommand.of(r.name(), r.price())) .toList();