-
Notifications
You must be signed in to change notification settings - Fork 4
[#102] 카페 메뉴 조회하기 및 삭제하기 #109
base: develop
Are you sure you want to change the base?
Changes from all commits
372a4cd
e45557d
38593ae
11a7c30
7638527
9d01c77
2c7176c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,20 @@ | ||
| package com.flab.cafeguidebook.controller; | ||
|
|
||
| import com.flab.cafeguidebook.domain.Option; | ||
| import com.flab.cafeguidebook.dto.MenuDTO; | ||
| import com.flab.cafeguidebook.dto.OptionDTO; | ||
| import com.flab.cafeguidebook.service.MenuService; | ||
| import com.flab.cafeguidebook.service.OptionService; | ||
| import java.util.List; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.validation.BindingResult; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
|
|
@@ -91,4 +95,69 @@ public ResponseEntity updateOption(@PathVariable long menuId, @PathVariable long | |
| return ResponseEntity.ok(optionDTO); | ||
| } | ||
|
|
||
| @GetMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity getAllMenu(@PathVariable long cafeId) { | ||
| List<MenuDTO> AllMenu = menuService.getAllMenu(cafeId); | ||
| if (AllMenu.size() > 0) { | ||
| return ResponseEntity.ok().body(AllMenu); | ||
| } else { | ||
| LOGGER.info("해당 카페의 전체 메뉴를 조회할 수 없습니다. cafeId = {}", cafeId); | ||
| return ResponseEntity.badRequest().build(); | ||
| } | ||
| } | ||
|
|
||
| @GetMapping(value = "/{menuId}/options", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity getAllOption(@PathVariable long cafeId, @PathVariable long menuId) { | ||
| List<OptionDTO> AllOption = optionService.getAllOption(menuId); | ||
| if (AllOption.size() > 0) { | ||
| return ResponseEntity.ok().body(AllOption); | ||
| } else { | ||
| LOGGER.info("해당 메뉴의 전체 옵션을 조회할 수 없습니다. cafeId = {}, menuId = {}", cafeId, menuId); | ||
| return ResponseEntity.badRequest().build(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 위와 동일 |
||
| } | ||
| } | ||
|
|
||
| @GetMapping(value = "/{menuId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity getMenu(@PathVariable long cafeId, @PathVariable long menuId) { | ||
| MenuDTO menuDTO = menuService.getMenu(menuId); | ||
| if (menuDTO == null) { | ||
| LOGGER.info("해당 메뉴를 조회할 수 없습니다. cafeId = {}, menuId = {}", cafeId, menuId); | ||
| return ResponseEntity.badRequest().build(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 역시 이곳에서도 메뉴가 없다고 해서 400 에러를 내면 안될것 같습니다. |
||
| } else { | ||
| return ResponseEntity.ok(menuDTO); | ||
| } | ||
| } | ||
|
|
||
| @GetMapping(value = "/{menuId}/options/{optionId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity getOption(@PathVariable long menuId, @PathVariable long optionId) { | ||
| OptionDTO optionDTO = optionService.getOption(optionId); | ||
| if (optionDTO == null) { | ||
| LOGGER.info("해당 옵션을 조회할 수 없습니다. menuId = {}, optionId = {}", menuId, optionId); | ||
| return ResponseEntity.badRequest().build(); | ||
| } else { | ||
| return ResponseEntity.ok(optionDTO); | ||
| } | ||
| } | ||
|
|
||
| @DeleteMapping(value = "/{menuId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity deleteMenu(@PathVariable long cafeId, @PathVariable long menuId) { | ||
| boolean deleteMenu = menuService.deleteMenu(menuId); | ||
| if (!deleteMenu) { | ||
| LOGGER.info("해당 메뉴를 삭제할 수 없습니다. cafeId = {}, menuId = {}", cafeId, menuId); | ||
| return ResponseEntity.badRequest().build(); | ||
| } else { | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } | ||
|
|
||
| @DeleteMapping(value = "/{menuId}/options/{optionId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
| public ResponseEntity deleteOption(@PathVariable long menuId, @PathVariable long optionId) { | ||
| boolean deleteOption = optionService.deleteOption(optionId); | ||
| if (!deleteOption) { | ||
| LOGGER.info("해당 옵션을 삭제할 수 없습니다. menuId = {}, optionId = {}", menuId, optionId); | ||
| return ResponseEntity.badRequest().build(); | ||
| } else { | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| package com.flab.cafeguidebook.service; | ||
|
|
||
| import com.flab.cafeguidebook.converter.MenuConverter.MenuDTOToMenuConverter; | ||
| import com.flab.cafeguidebook.converter.MenuConverter.MenuToMenuDTOConverter; | ||
| import com.flab.cafeguidebook.domain.Menu; | ||
| import com.flab.cafeguidebook.dto.MenuDTO; | ||
| import com.flab.cafeguidebook.mapper.MenuMapper; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
|
|
@@ -12,6 +19,9 @@ public class MenuService { | |
| @Autowired | ||
| private MenuDTOToMenuConverter menuDTOToMenuConverter; | ||
|
|
||
| @Autowired | ||
| MenuToMenuDTOConverter menuToMenuDTOConverter; | ||
|
|
||
| @Autowired | ||
| private MenuMapper menuMapper; | ||
|
|
||
|
|
@@ -24,4 +34,19 @@ public boolean updateMenu(MenuDTO menuDTO) { | |
| int updateMenu = menuMapper.updateMenu(menuDTOToMenuConverter.convert(menuDTO)); | ||
| return updateMenu == 1; | ||
| } | ||
|
|
||
| public List<MenuDTO> getAllMenu(long cafeId) { | ||
| List<MenuDTO> selectAllMenu = menuMapper.selectAllMenu(cafeId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cafeId 의 유효성 검증이 필요해보입니다. |
||
| return selectAllMenu; | ||
| } | ||
|
|
||
| public MenuDTO getMenu(long menuId) { | ||
| MenuDTO selectMenu = menuMapper.selectMenu(menuId); | ||
| return selectMenu; | ||
| } | ||
|
|
||
| public boolean deleteMenu(long menuId) { | ||
| int deleteMenu = menuMapper.deleteMenu(menuId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 메뉴가 존재하는지 확인후 없다면 404를 내리고 있는데 삭제를 실패한 경우면 500에러를 내리는게 더 좋을것 같습니다. |
||
| return deleteMenu == 1; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.flab.cafeguidebook.converter.OptionConverter.OptionDTOToOptionConverter; | ||
| import com.flab.cafeguidebook.dto.OptionDTO; | ||
| import com.flab.cafeguidebook.mapper.OptionMapper; | ||
| import java.util.List; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
|
|
@@ -24,4 +25,19 @@ public boolean updateOption(OptionDTO optionDTO) { | |
| int updateOption = optionMapper.updateOption(optionDTOToOptionConverter.convert(optionDTO)); | ||
| return updateOption == 1; | ||
| } | ||
|
|
||
| public List<OptionDTO> getAllOption(long menuId) { | ||
| List<OptionDTO> selectAllOption = optionMapper.selectAllOption(menuId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. menuId에 대한 검증부터 하는것이 좋을것 같습니다. |
||
| return selectAllOption; | ||
| } | ||
|
|
||
| public OptionDTO getOption(long optionId) { | ||
| OptionDTO selectOption = optionMapper.selectOption(optionId); | ||
| return selectOption; | ||
| } | ||
|
|
||
| public boolean deleteOption(long optionId) { | ||
| int deleteOption = optionMapper.deleteOption(optionId); | ||
| return deleteOption == 1; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실제로 메뉴가 없는경우도 있을수 있는데 400에러를 내리는건 안될것 같습니다.