Skip to content

Commit

Permalink
Merge pull request #132 from GEON-PPANG/refactor/#126
Browse files Browse the repository at this point in the history
[FIX] 회원 필터칩 및 북마크 모아보기 관련 api 리팩토링
  • Loading branch information
seunghaLim authored Aug 10, 2023
2 parents a2a2353 + f61f7d5 commit d5533c5
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class MemberTypesResponseDTO {
public class MemberTypeResponseDTO {
@NotNull private Long memberId;
@NotNull private MainPurpose mainPurpose;
@NotNull private BreadTypeResponseDTO breadType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public ApiResponse<MemberDetailResponseDTO> getMemberDetail() {
}

@PostMapping("/types")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<MemberTypesResponseDTO> updateMemberTypes(
public ApiResponse<MemberTypeResponseDTO> updateMemberTypes(
@Valid @RequestBody final MemberTypesRequestDTO request) {
Long memberId = SecurityUtil.getLoginMemberId();
return ApiResponse.success(
Expand All @@ -41,8 +40,7 @@ public ApiResponse<MemberTypesResponseDTO> updateMemberTypes(
}

@GetMapping("/types")
@ResponseStatus(HttpStatus.OK)
public ApiResponse<MemberTypesResponseDTO> getMemberTypes() {
public ApiResponse<MemberTypeResponseDTO> getMemberTypes() {
Long memberId = SecurityUtil.getLoginMemberId();
return ApiResponse.success(
SuccessType.GET_MEMBER_TYPES_SUCCESS, memberService.getMemberTypes(memberId));
Expand All @@ -61,6 +59,6 @@ public ApiResponse<List<BakeryListReviewedByMemberDTO>> getBakeryListReviewedByM
public ApiResponse<List<BakeryListResponseDTO>> getBookMarkedBakeries() {
Long memberId = SecurityUtil.getLoginMemberId();
return ApiResponse.success(
SuccessType.GET_BOOKMARKED_BAKERIES, bakeryService.getBookMarkedBakeries(memberId));
SuccessType.GET_BOOKMARKED_BAKERIES_SUCCESS, bakeryService.getBookMarkedBakeries(memberId));
}
}
78 changes: 23 additions & 55 deletions api/src/main/java/com/org/gunbbang/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import com.org.gunbbang.repository.MemberRepository;
import com.org.gunbbang.repository.NutrientTypeRepository;
import com.org.gunbbang.util.Security.SecurityUtil;
import com.org.gunbbang.util.mapper.BreadTypeMapper;
import com.org.gunbbang.util.mapper.MemberTypeMapper;
import com.org.gunbbang.util.mapper.NutrientTypeMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand Down Expand Up @@ -104,7 +107,7 @@ public MemberSignUpResponseDTO signUp(MemberSignUpRequestDTO memberSignUpRequest
.build();
}

public MemberTypesResponseDTO updateMemberTypes(MemberTypesRequestDTO request, Long memberId) {
public MemberTypeResponseDTO updateMemberTypes(MemberTypesRequestDTO request, Long memberId) {
Member foundMember =
memberRepository
.findById(memberId)
Expand Down Expand Up @@ -132,69 +135,34 @@ public MemberTypesResponseDTO updateMemberTypes(MemberTypesRequestDTO request, L
foundMember.updateMainPurpose(request.getMainPurpose());
memberRepository.saveAndFlush(foundMember);

// TODO: 이거 구체적으로 어떻게 돌아가는건지???
BreadType foundMemberBreadType = foundMember.getBreadType();
BreadTypeResponseDTO breadTypeResponse =
BreadTypeResponseDTO.builder()
.breadTypeId(foundMemberBreadType.getBreadTypeId())
.breadTypeName(foundMemberBreadType.getBreadTypeName())
.isGlutenFree(foundMemberBreadType.getIsGlutenFree())
.isVegan(foundMemberBreadType.getIsVegan())
.isNutFree(foundMemberBreadType.getIsNutFree())
.isSugarFree(foundMemberBreadType.getIsSugarFree())
.build();

NutrientType foundMemberNutrientType = foundMember.getNutrientType();
NutrientTypeResponseDTO nutrientTypeResponse =
NutrientTypeResponseDTO.builder()
.nutrientTypeId(foundMemberNutrientType.getNutrientTypeId())
.nutrientTypeName(foundMemberNutrientType.getNutrientTypeName())
.isNutrientOpen(foundMemberNutrientType.getIsNutrientOpen())
.isIngredientOpen(foundMemberNutrientType.getIsIngredientOpen())
.isNotOpen(foundMemberNutrientType.getIsNotOpen())
.build();
BreadTypeResponseDTO breadTypeResponseDTO =
BreadTypeMapper.INSTANCE.toBreadTypeResponseDTO(foundMember.getBreadType());
NutrientTypeResponseDTO nutrientTypeResponseDTO =
NutrientTypeMapper.INSTANCE.toNutrientTypeResponseDTO(foundMember.getNutrientType());

return MemberTypesResponseDTO.builder()
.memberId(foundMember.getMemberId())
.mainPurpose(foundMember.getMainPurpose())
.breadType(breadTypeResponse)
.nutrientType(nutrientTypeResponse)
.build();
return MemberTypeMapper.INSTANCE.toMemberTypeResponseDTO(
foundMember.getMemberId(),
foundMember.getMainPurpose(),
breadTypeResponseDTO,
nutrientTypeResponseDTO);
}

public MemberTypesResponseDTO getMemberTypes(Long memberId) {
public MemberTypeResponseDTO getMemberTypes(Long memberId) {
Member foundMember =
memberRepository
.findById(memberId)
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_USER_EXCEPTION));

BreadType foundMemberBreadType = foundMember.getBreadType();
BreadTypeResponseDTO breadType =
BreadTypeResponseDTO.builder()
.breadTypeId(foundMemberBreadType.getBreadTypeId())
.breadTypeName(foundMemberBreadType.getBreadTypeName())
.isGlutenFree(foundMemberBreadType.getIsGlutenFree())
.isVegan(foundMemberBreadType.getIsVegan())
.isNutFree(foundMemberBreadType.getIsNutFree())
.isSugarFree(foundMemberBreadType.getIsSugarFree())
.build();

NutrientType foundMemberNutrientType = foundMember.getNutrientType();
NutrientTypeResponseDTO nutrientTypeResponse =
NutrientTypeResponseDTO.builder()
.nutrientTypeId(foundMemberNutrientType.getNutrientTypeId())
.nutrientTypeName(foundMemberNutrientType.getNutrientTypeName())
.isNutrientOpen(foundMemberNutrientType.getIsNutrientOpen())
.isIngredientOpen(foundMemberNutrientType.getIsIngredientOpen())
.isNotOpen(foundMemberNutrientType.getIsNotOpen())
.build();
BreadTypeResponseDTO breadTypeResponseDTO =
BreadTypeMapper.INSTANCE.toBreadTypeResponseDTO(foundMember.getBreadType());
NutrientTypeResponseDTO nutrientTypeResponseDTO =
NutrientTypeMapper.INSTANCE.toNutrientTypeResponseDTO(foundMember.getNutrientType());

return MemberTypesResponseDTO.builder()
.memberId(foundMember.getMemberId())
.mainPurpose(foundMember.getMainPurpose())
.breadType(breadType)
.nutrientType(nutrientTypeResponse)
.build();
return MemberTypeMapper.INSTANCE.toMemberTypeResponseDTO(
foundMember.getMemberId(),
foundMember.getMainPurpose(),
breadTypeResponseDTO,
nutrientTypeResponseDTO);
}

public void checkDuplicatedNickname(String nickname) {
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/com/org/gunbbang/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void createReviewRecommendKeyword(
Review review =
reviewRepository
.findById(reviewId)
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_REVIEW));
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_REVIEW_EXCEPTION));
Bakery bakery =
bakeryRepository
.findById(review.getBakery().getBakeryId())
Expand All @@ -86,7 +86,7 @@ public ReviewDetailResponseDTO getReviewedByMember(Long reviewId) {
Review review =
reviewRepository
.findById(reviewId)
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_REVIEW));
.orElseThrow(() -> new NotFoundException(ErrorType.NOT_FOUND_REVIEW_EXCEPTION));
if (currentMemberId.equals(review.getMember().getMemberId())) {
List<RecommendKeywordResponseDTO> recommendKeywordList = new ArrayList<>();
if (review.getIsLike()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.org.gunbbang.util.mapper;

import com.org.gunbbang.MainPurpose;
import com.org.gunbbang.controller.DTO.response.BreadTypeResponseDTO;
import com.org.gunbbang.controller.DTO.response.MemberTypeResponseDTO;
import com.org.gunbbang.controller.DTO.response.NutrientTypeResponseDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface MemberTypeMapper {
MemberTypeMapper INSTANCE = Mappers.getMapper(MemberTypeMapper.class);

MemberTypeResponseDTO toMemberTypeResponseDTO(
Long memberId,
MainPurpose mainPurpose,
BreadTypeResponseDTO breadType,
NutrientTypeResponseDTO nutrientType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.org.gunbbang.util.mapper;

import com.org.gunbbang.controller.DTO.response.NutrientTypeResponseDTO;
import com.org.gunbbang.entity.NutrientType;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface NutrientTypeMapper {
NutrientTypeMapper INSTANCE = Mappers.getMapper(NutrientTypeMapper.class);

NutrientTypeResponseDTO toNutrientTypeResponseDTO(NutrientType nutrientType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public enum ErrorType {
NOT_FOUND_BAKERY_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 건빵집입니다"),
NOT_FOUND_BREAD_TYPE_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 빵유형 타입입니다"),
NOT_FOUND_NUTRIENT_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 영양성분 타입입니다"),
NOT_FOUND_SAVE_REVIEW(HttpStatus.NOT_FOUND, "리뷰 저장에 실패했습니다"),
NOT_FOUND_REVIEW(HttpStatus.NOT_FOUND, "존재하지 않는 리뷰입니다"),
NOT_FOUND_SAVE_REVIEW_EXCEPTION(HttpStatus.NOT_FOUND, "리뷰 저장에 실패했습니다"),
NOT_FOUND_REVIEW_EXCEPTION(HttpStatus.NOT_FOUND, "존재하지 않는 리뷰입니다"),
NOT_FOUND_CATEGORY_EXCEPTION(HttpStatus.NOT_FOUND, "해당 카테고리를 찾을 수 없습니다"),

/** 409 CONFLICT */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum SuccessType {
GET_MEMBER_TYPES_SUCCESS(HttpStatus.OK, "회원 필터칩 조회 성공"),
GET_BEST_REVIEWS_SUCCESS(HttpStatus.OK, "베스트 리뷰 조회 성공"),
SEARCH_BAKERIES_SUCCESS(HttpStatus.OK, "건빵집 검색 성공"),
GET_BOOKMARKED_BAKERIES(HttpStatus.OK, "북마크된 건빵집 조회 성공"),
GET_BOOKMARKED_BAKERIES_SUCCESS(HttpStatus.OK, "북마크된 건빵집 조회 성공"),

/** 201 CREATED */
SIGNUP_SUCCESS(HttpStatus.CREATED, "회원가입이 완료됐습니다."),
Expand Down

0 comments on commit d5533c5

Please sign in to comment.