From a7b1ab1660be7385ef77489bee376df65c51fee7 Mon Sep 17 00:00:00 2001 From: mummhy0811 Date: Sun, 5 May 2024 00:20:41 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EA=B4=80=EB=A6=AC=EC=9E=90=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=20=EC=88=98=EC=A0=95=20=EA=B4=80=EB=A0=A8(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - reqdto category_idx 카멜케이스로 변경 - 이미지 선택사항으로 변경 close: #26 --- .../hanaro/starbucks/controller/MenuController.java | 2 +- .../com/hanaro/starbucks/dto/menu/MenuReqDto.java | 2 +- .../com/hanaro/starbucks/service/MenuService.java | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hanaro/starbucks/controller/MenuController.java b/src/main/java/com/hanaro/starbucks/controller/MenuController.java index d17661a..89be5ba 100644 --- a/src/main/java/com/hanaro/starbucks/controller/MenuController.java +++ b/src/main/java/com/hanaro/starbucks/controller/MenuController.java @@ -40,7 +40,7 @@ public void deleteMenuByMenuIdx(@PathVariable int menuIdx) throws Exception{ } @PutMapping(value = "/admin/{menuIdx}", consumes = {MediaType.APPLICATION_JSON_VALUE, "multipart/form-data"}) - public void updateMenu(@PathVariable int menuIdx, @RequestPart(value = "dto") MenuReqDto menuReqDto, @RequestPart(value = "menuImg") MultipartFile img) throws Exception{ + public void updateMenu(@PathVariable int menuIdx, @RequestPart(value = "dto") MenuReqDto menuReqDto, @RequestPart(value = "menuImg", required = false) MultipartFile img) throws Exception{ menuService.updateMenu(menuIdx, menuReqDto, img); } } diff --git a/src/main/java/com/hanaro/starbucks/dto/menu/MenuReqDto.java b/src/main/java/com/hanaro/starbucks/dto/menu/MenuReqDto.java index 8dfab3c..aad6e89 100644 --- a/src/main/java/com/hanaro/starbucks/dto/menu/MenuReqDto.java +++ b/src/main/java/com/hanaro/starbucks/dto/menu/MenuReqDto.java @@ -11,5 +11,5 @@ public class MenuReqDto { private int menuPrice; - private int category_idx; + private int categoryIdx; } diff --git a/src/main/java/com/hanaro/starbucks/service/MenuService.java b/src/main/java/com/hanaro/starbucks/service/MenuService.java index c1cebb6..a101a21 100644 --- a/src/main/java/com/hanaro/starbucks/service/MenuService.java +++ b/src/main/java/com/hanaro/starbucks/service/MenuService.java @@ -60,15 +60,16 @@ public void updateMenu(int menuIdx, MenuReqDto menuReqDto, MultipartFile img) th throw new Exception("존재하지 않는 메뉴입니다."); } Menu menu = optionalMenu.get(); - Optional optionalCategory = categoryRepository.findById(menuReqDto.getCategory_idx()); + Optional optionalCategory = categoryRepository.findById(menuReqDto.getCategoryIdx()); if (optionalCategory.isEmpty()) { - throw new Exception("존재하지 않는 카테고리입니다."); + throw new Exception("존재하지 않는 카테고리입니다."+ menuReqDto.getCategoryIdx()); } - log.info("메뉴 검색 완"); - String url = s3Uploader.updateFile(img, menu.getMenuImage(), optionalCategory.get().getCategoryName()); - log.info(url); + String url; + + if(img==null || img.isEmpty()) url=menu.getMenuImage(); + else url = s3Uploader.updateFile(img, menu.getMenuImage(), optionalCategory.get().getCategoryName()); + menu.update(menuReqDto, url); - log.info("업데이트 완"); menuRepository.save(menu); } }