Skip to content

Commit

Permalink
refactor: spot orElseThrow -> existsById 변경 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gahyuun committed Jan 16, 2025
1 parent 3752fe2 commit a99ed4a
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ public class SpotService {
private final MenuRepository menuRepository;

public MenuListResponse fetchMenus(Long spotId) {
spotRepository.findById(spotId).orElseThrow(() -> new BusinessException(ErrorType.NOT_FOUND_SPOT_ERROR));
if (spotRepository.existsById(spotId)) {
throw new BusinessException(ErrorType.NOT_FOUND_SPOT_ERROR);
}
List<MenuEntity> menuEntityList = menuRepository.findAllBySpotId(spotId);
List<MenuResponse> menuList = menuEntityList.stream()
.map(menu -> MenuResponse.builder().id(menu.getId()).name(menu.getName()).price(menu.getPrice())
.image(menu.getImage()).build()).toList();
.map(menu -> MenuResponse.builder()
.id(menu.getId())
.name(menu.getName())
.price(menu.getPrice())
.image(menu.getImage())
.build())
.toList();

return new MenuListResponse(menuList);
}
Expand Down

0 comments on commit a99ed4a

Please sign in to comment.