diff --git a/api/src/main/java/com/org/gunbbang/controller/DTO/response/BakeryDetailResponseDTO.java b/api/src/main/java/com/org/gunbbang/controller/DTO/response/BakeryDetailResponseDTO.java index 9da16bb6..89ed0bfb 100644 --- a/api/src/main/java/com/org/gunbbang/controller/DTO/response/BakeryDetailResponseDTO.java +++ b/api/src/main/java/com/org/gunbbang/controller/DTO/response/BakeryDetailResponseDTO.java @@ -19,7 +19,7 @@ public class BakeryDetailResponseDTO extends BaseBakeryResponseDTO { private String homepageUrl; private String instagramUrl; private String address; - private String openingTime; + private String openingHours; private String closedDay; private String phoneNumber; private List menuList; diff --git a/api/src/main/java/com/org/gunbbang/service/BakeryService.java b/api/src/main/java/com/org/gunbbang/service/BakeryService.java index 4e33da1b..a8f5a723 100644 --- a/api/src/main/java/com/org/gunbbang/service/BakeryService.java +++ b/api/src/main/java/com/org/gunbbang/service/BakeryService.java @@ -1,5 +1,7 @@ package com.org.gunbbang.service; +import static com.org.gunbbang.util.ConstantVO.BLANK_SPACE; + import com.org.gunbbang.CategoryType; import com.org.gunbbang.NotFoundException; import com.org.gunbbang.controller.DTO.response.*; @@ -10,6 +12,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 +81,20 @@ public BakeryDetailResponseDTO getBakeryDetail(Long memberId, Long bakeryId) { bakeryRepository .findById(bakeryId) .orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_BAKERY_EXCEPTION)); - List bakeryMenu = menuRepository.findAllByBakery(bakery); - BreadTypeResponseDTO breadType = getBreadType(bakery); + BreadTypeResponseDTO breadType = + BreadTypeMapper.INSTANCE.toBreadTypeResponseDTO(bakery.getBreadType()); boolean isBookMarked = isBookMarked(memberId, bakeryId); - List menuList = new ArrayList<>(); - - for (Menu menu : bakeryMenu) { - menuList.add( - MenuResponseDTO.builder() - .menuId(menu.getMenuId()) - .menuName(menu.getMenuName()) - .menuPrice(menu.getMenuPrice()) - .build()); - } + List bakeryMenuList = menuRepository.findAllByBakery(bakery); + List menuList = MenuMapper.INSTANCE.toMenuResponseDTOList(bakeryMenuList); + String address = + getAddress(bakery.getState(), bakery.getCity(), bakery.getTown(), bakery.getAddressRest()); - 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(); + return BakeryMapper.INSTANCE.toBakeryDetailResponseDTO( + bakery, address, breadType, isBookMarked, menuList); + } + + String getAddress(String state, String city, String town, String addressRest) { + return state + BLANK_SPACE + city + BLANK_SPACE + town + BLANK_SPACE + addressRest; } public List getBestBakeries(Long memberId) { diff --git a/api/src/main/java/com/org/gunbbang/util/ConstantVO.java b/api/src/main/java/com/org/gunbbang/util/ConstantVO.java new file mode 100644 index 00000000..1eda8ebc --- /dev/null +++ b/api/src/main/java/com/org/gunbbang/util/ConstantVO.java @@ -0,0 +1,5 @@ +package com.org.gunbbang.util; + +public class ConstantVO { + public static final String BLANK_SPACE = " "; +} diff --git a/api/src/main/java/com/org/gunbbang/util/mapper/BakeryMapper.java b/api/src/main/java/com/org/gunbbang/util/mapper/BakeryMapper.java index ab351df6..6100a421 100644 --- a/api/src/main/java/com/org/gunbbang/util/mapper/BakeryMapper.java +++ b/api/src/main/java/com/org/gunbbang/util/mapper/BakeryMapper.java @@ -1,9 +1,6 @@ package com.org.gunbbang.util.mapper; -import com.org.gunbbang.controller.DTO.response.BakeryListResponseDTO; -import com.org.gunbbang.controller.DTO.response.BakerySearchResponseDTO; -import com.org.gunbbang.controller.DTO.response.BestBakeryListResponseDTO; -import com.org.gunbbang.controller.DTO.response.BreadTypeResponseDTO; +import com.org.gunbbang.controller.DTO.response.*; import com.org.gunbbang.entity.Bakery; import java.util.List; import org.mapstruct.Mapper; @@ -24,4 +21,14 @@ BakerySearchResponseDTO toBakerySearchResponseDTO( int resultCount, List bakeryList); List toBestBakeryListResponseDTO(List bakeries); + + @Mapping(source = "bakery.isHACCP", target = "isHACCP") + @Mapping(source = "bakery.isVegan", target = "isVegan") + @Mapping(source = "bakery.isNonGMO", target = "isNonGMO") + BakeryDetailResponseDTO toBakeryDetailResponseDTO( + Bakery bakery, + String address, + BreadTypeResponseDTO breadType, + boolean isBookMarked, + List menuList); } diff --git a/api/src/main/java/com/org/gunbbang/util/mapper/MenuMapper.java b/api/src/main/java/com/org/gunbbang/util/mapper/MenuMapper.java new file mode 100644 index 00000000..19d3ce52 --- /dev/null +++ b/api/src/main/java/com/org/gunbbang/util/mapper/MenuMapper.java @@ -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 toMenuResponseDTOList(List menuList); +}