-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] 빵집 상세보기 리팩터링 #145
[FIX] 빵집 상세보기 리팩터링 #145
Changes from 3 commits
85ec9f4
7aba394
2f2a4ef
a3f906d
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import com.org.gunbbang.service.specification.BakerySpecifications; | ||
import com.org.gunbbang.util.mapper.BakeryMapper; | ||
import com.org.gunbbang.util.mapper.BreadTypeMapper; | ||
import com.org.gunbbang.util.mapper.MenuMapper; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
|
@@ -78,49 +79,21 @@ public BakeryDetailResponseDTO getBakeryDetail(Long memberId, Long bakeryId) { | |
bakeryRepository | ||
.findById(bakeryId) | ||
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_BAKERY_EXCEPTION)); | ||
List<Menu> bakeryMenu = menuRepository.findAllByBakery(bakery); | ||
BreadTypeResponseDTO breadType = getBreadType(bakery); | ||
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. BreadTypeResponseDTO로 변환하는 매퍼 만들었던걸로 기억하는데 있으면 매퍼로 처리하는것도 괜찮아 보입니다~ 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. 매퍼로 동일하게 처리하고 리팩토링하면서 다른 곳에서 쓰이면 같이 수정하겠습니다~ 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. 제가 이미 쓰긴합니다 하암ㅋㅋ 매퍼 코드 있으니 함 생각해보세요~ |
||
boolean isBookMarked = isBookMarked(memberId, bakeryId); | ||
List<MenuResponseDTO> menuList = new ArrayList<>(); | ||
|
||
for (Menu menu : bakeryMenu) { | ||
menuList.add( | ||
MenuResponseDTO.builder() | ||
.menuId(menu.getMenuId()) | ||
.menuName(menu.getMenuName()) | ||
.menuPrice(menu.getMenuPrice()) | ||
.build()); | ||
} | ||
|
||
return BakeryDetailResponseDTO.builder() | ||
.bakeryId(bakery.getBakeryId()) | ||
.bakeryName(bakery.getBakeryName()) | ||
.bakeryPicture(bakery.getBakeryPicture()) | ||
.isHACCP(bakery.getIsHACCP()) | ||
.isVegan(bakery.getIsVegan()) | ||
.isNonGMO(bakery.getIsNonGMO()) | ||
.breadType(breadType) | ||
.firstNearStation(bakery.getFirstNearStation()) | ||
.secondNearStation(bakery.getSecondNearStation()) | ||
.isBookMarked(isBookMarked) | ||
.bookMarkCount(bakery.getBookMarkCount()) | ||
.reviewCount(bakery.getReviewCount()) | ||
.mapUrl(bakery.getMapUrl()) | ||
.homepageUrl(bakery.getHomepageUrl()) | ||
.instagramUrl(bakery.getInstagramUrl()) | ||
.address( | ||
bakery.getState() | ||
+ " " | ||
+ bakery.getCity() | ||
+ " " | ||
+ bakery.getTown() | ||
+ " " | ||
+ bakery.getAddressRest()) | ||
.openingTime(bakery.getOpeningHours()) | ||
.closedDay(bakery.getClosedDay()) | ||
.phoneNumber(bakery.getPhoneNumber()) | ||
.menuList(menuList) | ||
.build(); | ||
List<MenuResponseDTO> menuList = | ||
MenuMapper.INSTANCE.toMenuResponseDTOList(menuRepository.findAllByBakery(bakery)); | ||
String address = | ||
bakery.getState() | ||
+ " " | ||
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. 요거 띄어쓰기 BLANK_SPACE 이런 식으로 상수화 처리 어떠실까욜 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. 추가로 address 가져오는 부분 함수로 빼는건 어떠실까욜 매개변수가 너무 많을까요?? 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. 오옹 상수화는 생각도 못했네요 좋습니다! address 가져오는 부분도 함수로 빼는거 좋습니다! |
||
+ bakery.getCity() | ||
+ " " | ||
+ bakery.getTown() | ||
+ " " | ||
+ bakery.getAddressRest(); | ||
|
||
return BakeryMapper.INSTANCE.toBakeryDetailResponseDTO( | ||
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. 휴우 깔끔하네요~ 마음의 안정 |
||
bakery, address, breadType, isBookMarked, menuList); | ||
} | ||
|
||
public List<BestBakeryListResponseDTO> getBestBakeries(Long memberId) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.org.gunbbang.util.mapper; | ||
|
||
import com.org.gunbbang.controller.DTO.response.MenuResponseDTO; | ||
import com.org.gunbbang.entity.Menu; | ||
import java.util.List; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.ERROR) | ||
public interface MenuMapper { | ||
MenuMapper INSTANCE = Mappers.getMapper(MenuMapper.class); | ||
|
||
List<MenuResponseDTO> toMenuResponseDTOList(List<Menu> menuList); | ||
} |
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.
매개변수 전달만을 위한 변수 선언
-> 변수를 선언한 코드가 더 가독성이 좋다면 변수 선언 하고 매개변수로 전달하는게 좋다고 생각합니다
getXXX() 이런식으로 값을 얻어오는 메서드의 경우 별다른 변수 선언 없이 바로 매개변수에 넣어줘도 가독성이 크게 나빠지지는 않는다고 생각해요~ 현재 코드로 봤을 땐 변경 전 코드가 (제기준) 더 좋아보이긴 합니다
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.
참고하겠습니다 감사티비!!