Skip to content

Commit

Permalink
Merge pull request #251 from TEAM-MODDY/refactor/#250
Browse files Browse the repository at this point in the history
#250 [refactor] 엔드포인트 변경, 디자이너 제안 상세보기 response 도메인별로 분리
  • Loading branch information
hellozo0 authored Feb 24, 2024
2 parents ce6bed7 + a91be27 commit c4f0265
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ public SuccessResponse<ApplicationImgUrlResponse> getApplicationImgUrlOpenChat(
return SuccessResponse.success(SuccessCode.GET_APPLICATION_IMG_URL_SUCCESS, hairModelApplicationRetrieveService.getApplicationImgUrl(applicationId));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moddy.server.controller.application.dto.response;

import java.util.List;

public record ApplicationInfoDetailResponse(
Long applicationId,
List<String> preferStyle,
String modelApplicationDetail
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

@RestController
@RequiredArgsConstructor
@Tag(name = "DesignerController")
@Tag(name = "Designer Controller")
@RequestMapping("/designer")
public class DesignerRegisterController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@RestController
@RequiredArgsConstructor
@Tag(name = "DesignerController")
@Tag(name = "Designer Controller")
@RequestMapping("/designer")
public class DesignerRetrieveController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@RestController
@RequiredArgsConstructor
@Tag(name = "ModelController")
@Tag(name = "Model Controller")
@RequestMapping("/model")
public class ModelRegisterController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

public record DesignerInfoResponse(
Long designerId,
String imgUrl,
String shopName,
String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public SuccessResponse<ModelMainOfferResponse> getModelMainInfo(
public SuccessResponse<DetailOfferResponse> getModelDetailOfferInfo(
@Parameter(hidden = true) @UserId Long modelId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, hairServiceOfferRetrieveService.getOfferDetail(modelId, offerId));
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, hairServiceOfferRetrieveService.getOfferDetail(offerId));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.moddy.server.controller.model.dto.response;
package com.moddy.server.controller.offer.dto.response;

import lombok.Builder;

import java.util.List;

@Builder
public record StyleDetailResponse(
public record OfferInfoResponse(
Long offerId,
Boolean isAgree,
List<String> preferStyle,
String designerOfferDetail,
String modelApplicationDetail,
List<Boolean> preferOfferConditions
) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.moddy.server.controller.offer.response;

import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse;
import com.moddy.server.controller.model.dto.response.DesignerInfoResponse;
import com.moddy.server.controller.model.dto.response.StyleDetailResponse;

import com.moddy.server.controller.offer.dto.response.OfferInfoResponse;

public record DetailOfferResponse(
DesignerInfoResponse designerInfo,
StyleDetailResponse styleDetail
ApplicationInfoDetailResponse applicationInfo,
OfferInfoResponse offerInfo
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.controller.designer.dto.response.DownloadUrlResponseDto;
import com.moddy.server.controller.designer.dto.response.HairModelApplicationResponse;
Expand Down Expand Up @@ -58,6 +59,17 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int
);
}

public ApplicationInfoDetailResponse getOfferApplicationInfo(final Long applicationId) {
List<String> preferHairStyleList = getPreferHairStyle(applicationId);
String applicationHairDetail = getApplicationHairDetail(applicationId);

return new ApplicationInfoDetailResponse(
applicationId,
preferHairStyleList,
applicationHairDetail
);
}

public ApplicationDto getApplicationDetailInfo(final Long applicationId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
Long modelId = hairModelApplication.getModel().getId();
Expand Down Expand Up @@ -87,42 +99,41 @@ public ApplicationDto getApplicationDetailInfo(final Long applicationId) {
hairModelApplication.getInstagramId());
}

public String fetchApplicationHairDetail(final Long applicationId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
return hairModelApplication.getHairDetail();
}

public List<String> fetchPreferHairStyle(final Long applicationId) {
List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId);
List<String> preferHairStyleList = preferHairStyles.stream().map(hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

return preferHairStyleList;
}


public boolean fetchModelApplyStatus(final Long modelId) {
return hairModelApplicationJpaRepository.existsByModelId(modelId);
}

public ApplicationImgUrlResponse getApplicationImgUrl(final Long applicationId){
public ApplicationImgUrlResponse getApplicationImgUrl(final Long applicationId) {

return new ApplicationImgUrlResponse(hairModelApplicationJpaRepository.findById(applicationId).get().getApplicationCaptureUrl());
}

public DownloadUrlResponseDto getApplicationCaptureDownloadUrl(final Long applicationId) {
final HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
final String applicationDownloadUrl = s3Service.getPreSignedUrlToDownload(hairModelApplication.getApplicationCaptureUrl());
return new DownloadUrlResponseDto(applicationDownloadUrl);
}

private Page<HairModelApplication> findApplicationsByPaging(final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);

return applicationPage;
}

public DownloadUrlResponseDto getApplicationCaptureDownloadUrl(final Long applicationId) {
final HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId)
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
final String applicationDownloadUrl = s3Service.getPreSignedUrlToDownload(hairModelApplication.getApplicationCaptureUrl());
return new DownloadUrlResponseDto(applicationDownloadUrl);
private String getApplicationHairDetail(final Long applicationId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
return hairModelApplication.getHairDetail();
}

private List<String> getPreferHairStyle(final Long applicationId) {
List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId);
List<String> preferHairStyleList = preferHairStyles.stream().map(hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

return preferHairStyleList;
}

private HairModelApplicationResponse getApplicationResponse(final HairModelApplication application) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DesignerInfoResponse getOfferDesignerInfoResponse(final Long designerId)
Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));
List<String> dayOfWeekList = getDayOfWeekList(designerId);

DesignerInfoResponse designerInfoResponse = new DesignerInfoResponse(designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getPortfolio().getInstagramUrl(), designer.getPortfolio().getNaverPlaceUrl(), designer.getIntroduction(), designer.getGender().getValue(), dayOfWeekList, designer.getHairShop().getAddress(), designer.getHairShop().getDetailAddress());
DesignerInfoResponse designerInfoResponse = new DesignerInfoResponse(designerId, designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getPortfolio().getInstagramUrl(), designer.getPortfolio().getNaverPlaceUrl(), designer.getIntroduction(), designer.getGender().getValue(), dayOfWeekList, designer.getHairShop().getAddress(), designer.getHairShop().getDetailAddress());
return designerInfoResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.model.dto.DesignerInfoOpenChatDto;
import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse;
import com.moddy.server.controller.model.dto.response.DesignerInfoResponse;
import com.moddy.server.controller.model.dto.response.OfferResponse;
import com.moddy.server.controller.model.dto.response.StyleDetailResponse;
import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse;
import com.moddy.server.controller.offer.dto.response.OfferInfoResponse;
import com.moddy.server.controller.offer.response.DetailOfferResponse;
import com.moddy.server.domain.designer.Designer;
import com.moddy.server.domain.hair_service_offer.HairServiceOffer;
Expand Down Expand Up @@ -47,36 +47,35 @@ public boolean getIsSendStatus(final Long applicationId, final Long userId) {
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndDesignerId(applicationId, userId);
return offer.isPresent();
}
public DetailOfferResponse getOfferDetail(final Long modelId, final Long offerId) {

public DetailOfferResponse getOfferDetail(final Long offerId) {

HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION));

DesignerInfoResponse designerInfoResponse = designerRetrieveService.getOfferDesignerInfoResponse(hairServiceOffer.getDesigner().getId());
StyleDetailResponse styleDetailResponse = getStyleDetailResponse(hairServiceOffer, offerId);
ApplicationInfoDetailResponse applicationInfoDetailResponse = hairModelApplicationRetrieveService.getOfferApplicationInfo(hairServiceOffer.getHairModelApplication().getId());
OfferInfoResponse offerInfoResponse = getOfferDetailResponse(hairServiceOffer, offerId);

handleOfferClickStatus(hairServiceOffer);

return new DetailOfferResponse(designerInfoResponse, styleDetailResponse);
return new DetailOfferResponse(designerInfoResponse, applicationInfoDetailResponse,offerInfoResponse);
}

private StyleDetailResponse getStyleDetailResponse(final HairServiceOffer hairServiceOffer, final Long offerId) {

String applicationHairDetail = hairModelApplicationRetrieveService.fetchApplicationHairDetail(hairServiceOffer.getHairModelApplication().getId());
List<String> preferHairStyleList = hairModelApplicationRetrieveService.fetchPreferHairStyle(hairServiceOffer.getHairModelApplication().getId());
private OfferInfoResponse getOfferDetailResponse(final HairServiceOffer hairServiceOffer, final Long offerId) {

List<PreferOfferCondition> preferOfferConditionList = preferOfferConditionJpaRepository.findAllByHairServiceOfferId(offerId);
List<OfferCondition> offerConditionList = preferOfferConditionList.stream().map(PreferOfferCondition::getOfferCondition).collect(Collectors.toList());
List<Boolean> preferOfferConditionBooleanList = Arrays.stream(OfferCondition.values()).map(offerConditionList::contains).collect(Collectors.toList());

StyleDetailResponse styleDetailResponse = StyleDetailResponse
OfferInfoResponse offerInfoResponse = OfferInfoResponse
.builder()
.offerId(hairServiceOffer.getId())
.isAgree(hairServiceOffer.isModelAgree())
.preferStyle(preferHairStyleList)
.designerOfferDetail(hairServiceOffer.getOfferDetail())
.modelApplicationDetail(applicationHairDetail)
.preferOfferConditions(preferOfferConditionBooleanList)
.build();

return styleDetailResponse;
return offerInfoResponse;
}

public ModelMainOfferResponse getModelMainOfferInfo(final Long modelId, final int page, final int size) {
Expand Down

0 comments on commit c4f0265

Please sign in to comment.