Skip to content

Commit

Permalink
Fix: 관리자 메뉴 수정 관련(#26)
Browse files Browse the repository at this point in the history
- reqdto category_idx 카멜케이스로 변경
- 이미지 선택사항으로 변경

close: #26
  • Loading branch information
mummhy0811 committed May 4, 2024
1 parent 5108b63 commit a7b1ab1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public class MenuReqDto {
private int menuPrice;


private int category_idx;
private int categoryIdx;
}
13 changes: 7 additions & 6 deletions src/main/java/com/hanaro/starbucks/service/MenuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ public void updateMenu(int menuIdx, MenuReqDto menuReqDto, MultipartFile img) th
throw new Exception("존재하지 않는 메뉴입니다.");
}
Menu menu = optionalMenu.get();
Optional<Category> optionalCategory = categoryRepository.findById(menuReqDto.getCategory_idx());
Optional<Category> 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);
}
}

0 comments on commit a7b1ab1

Please sign in to comment.