Skip to content

Commit

Permalink
#215 [refactor] applicationRetrieve service 에서 컨트롤러 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pkl0912 committed Jan 31, 2024
1 parent e0008ea commit 8a8fd44
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@
import com.moddy.server.common.dto.ErrorResponse;
import com.moddy.server.common.dto.SuccessNonDataResponse;
import com.moddy.server.common.dto.SuccessResponse;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.enums.SuccessCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.designer.dto.request.OfferCreateRequest;
import com.moddy.server.controller.designer.dto.request.OfferImageUrlRequestDto;
import com.moddy.server.controller.designer.dto.response.ApplicationDetailInfoResponse;
import com.moddy.server.controller.designer.dto.response.ApplicationInfoResponse;
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.ModelInfoResponse;
import com.moddy.server.controller.model.dto.ApplicationDto;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.service.application.HairModelApplicationRetrieveService;
import com.moddy.server.service.designer.DesignerService;
import com.moddy.server.service.model.ModelRetrieveService;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -42,6 +51,8 @@ public class DesignerController {

private final DesignerService designerService;
private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;
private final ModelRetrieveService modelRetrieveService;
private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;

@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@ApiResponses({
Expand Down Expand Up @@ -85,9 +96,31 @@ public SuccessNonDataResponse offerCreateRequest(
@GetMapping("/{applicationId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ApplicationDetailInfoResponse> getApplicationDetailInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(hidden = true) @UserId Long designerId,
@PathVariable(value = "applicationId") Long applicationId) {
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, hairModelApplicationRetrieveService.getApplicationDetail(userId, applicationId));
ApplicationDto applicationDto = hairModelApplicationRetrieveService.getApplicationDetailInfo(applicationId);
ApplicationModelInfoDto modelInfoDto = modelRetrieveService.getApplicationModelInfo(applicationId);
ApplicationInfoResponse applicationInfoResponse = new ApplicationInfoResponse(
applicationId,
applicationDto.modelImgUrl(),
applicationDto.hairLength(),
applicationDto.preferHairStyleList(),
applicationDto.recordResponseList(),
applicationDto.hairDetail(),
hairServiceOfferRetrieveService.getIsSendStatus(applicationId, designerId)
);

ModelInfoResponse modelInfoResponse = new ModelInfoResponse(
modelInfoDto.modelId(),
modelInfoDto.name(),
modelInfoDto.age(),
modelInfoDto.gender(),
modelInfoDto.regionList(),
applicationDto.instgramId()
);

ApplicationDetailInfoResponse applicationDetailInfoResponse = new ApplicationDetailInfoResponse(applicationInfoResponse,modelInfoResponse);
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, applicationDetailInfoResponse);
}

@Operation(summary = "[JWT] 제안서 다운로드 링크", description = "디자이너 제안서 다운로드 링크 불러오는 API")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.moddy.server.controller.model.dto;

import com.moddy.server.controller.designer.dto.response.HairRecordResponse;

import java.util.List;

public record ApplicationDto(
String modelImgUrl,
String hairLength,
List<String> preferHairStyleList,
List<HairRecordResponse> recordResponseList,
String hairDetail,
String instgramId
) {
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.moddy.server.controller.model.dto;

import java.util.List;

public record ApplicationModelInfoDto(
Long modelId,
String name,
int age,
String gender
String gender,
List<String> regionList
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.moddy.server.controller.designer.dto.response.HairModelApplicationResponse;
import com.moddy.server.controller.designer.dto.response.HairRecordResponse;
import com.moddy.server.controller.designer.dto.response.ModelInfoResponse;
import com.moddy.server.controller.model.dto.ApplicationDto;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.domain.hair_model_application.repository.HairModelApplicationJpaRepository;
Expand Down Expand Up @@ -66,20 +67,15 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int
applicationResponsesList
);
}

public ApplicationDetailInfoResponse getApplicationDetail(final Long designerId, final Long applicationId) {

public ApplicationDto getApplicationDetailInfo(final Long applicationId){
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

Long modelId = hairModelApplication.getModel().getId();
ApplicationModelInfoDto modelInfoDto = modelRetrieveService.getApplicationModelInfo(modelId);

List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId);

List<String> preferhairStyleList = preferHairStyles.stream().map(hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

Long modelId = hairModelApplication.getModel().getId();

List<HairServiceRecord> hairServiceRecords = hairServiceRecordJpaRepository.findAllByHairModelApplicationId(applicationId);
hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal()));

Expand All @@ -97,29 +93,13 @@ public ApplicationDetailInfoResponse getApplicationDetail(final Long designerId,
return hairRecordResponse;
}).collect(Collectors.toList());

ApplicationInfoResponse applicationInfoResponse = new ApplicationInfoResponse(
applicationId,
return new ApplicationDto(
hairModelApplication.getModelImgUrl(),
hairModelApplication.getHairLength().getValue(),
preferhairStyleList,
recordResponseList,
hairModelApplication.getHairDetail(),
getIsSendStatus(applicationId, designerId)
);

ModelInfoResponse modelInfoResponse = new ModelInfoResponse(
modelId,
modelInfoDto.name(),
modelInfoDto.age(),
modelInfoDto.gender(),
regionList,
hairModelApplication.getInstagramId()
);

return new ApplicationDetailInfoResponse(
applicationInfoResponse,
modelInfoResponse
);
hairModelApplication.getInstagramId());
}
private Page<HairModelApplication> findApplicationsByPaging(final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.auth.dto.response.RegionResponse;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.domain.hair_model_application.repository.HairModelApplicationJpaRepository;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
import com.moddy.server.domain.prefer_region.PreferRegion;
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository;
import com.moddy.server.domain.region.repository.RegionJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,10 +24,20 @@
public class ModelRetrieveService {
private final ModelJpaRepository modelJpaRepository;
private final RegionJpaRepository regionJpaRepository;
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository;
private final PreferRegionJpaRepository preferRegionJpaRepository;

public ApplicationModelInfoDto getApplicationModelInfo(final Long modelId) {
public ApplicationModelInfoDto getApplicationModelInfo(final Long applicationId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
Long modelId = hairModelApplication.getModel().getId();
Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
return new ApplicationModelInfoDto(model.getName(), model.getAge(), model.getGender().getValue());

List<PreferRegion> preferRegions = preferRegionJpaRepository.findAllByModelId(modelId);

List<String> regionList = preferRegions.stream().map(preferregion -> {
return preferregion.getRegion().getName();
}).collect(Collectors.toList());
return new ApplicationModelInfoDto(modelId, model.getName(), model.getAge(), model.getGender().getValue(), regionList);
}

public List<RegionResponse> getRegionList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -36,4 +38,9 @@ public OpenChatResponse getOpenChatInfo(final Long userId, final Long offerId) {

return openChatResponse;
}

public Boolean getIsSendStatus(final Long applicationId, final Long userId) {
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndDesignerId(applicationId, userId);
return offer.isPresent();
}
}

0 comments on commit 8a8fd44

Please sign in to comment.