Skip to content
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

#215 [refactor] 지원서 상세보기 api service 분리 #216

Merged
merged 7 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

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.SuccessCode;
import com.moddy.server.config.resolver.user.UserId;
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.ModelInfoResponse;
import com.moddy.server.controller.model.dto.ApplicationDto;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.service.application.HairModelApplicationRegisterService;
import com.moddy.server.service.application.HairModelApplicationRetrieveService;
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 All @@ -17,6 +26,8 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -27,7 +38,9 @@
public class ApplicationController {

private final HairModelApplicationRegisterService hairModelApplicationRegisterService;

private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;
private final ModelRetrieveService modelRetrieveService;
private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;
@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.")
@ApiResponses({
Expand All @@ -45,5 +58,42 @@ public SuccessNonDataResponse submitModelApplication(
hairModelApplicationRegisterService.postApplication(modelId, modelImgUrl, applicationCaptureImgUrl, applicationInfo);
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}
@Tag(name = "DesignerController")
@Operation(summary = "[JWT] 모델 지원서 상세 조회", description = "모델 지원서 상세 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "지원서 아이디가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping("/designer/{applicationId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ApplicationDetailInfoResponse> getApplicationDetailInfo(
@Parameter(hidden = true) @UserId Long designerId,
@PathVariable(value = "applicationId") Long 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);
}
}

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2
사용하지 않는 변수는 제거해주세요!


@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@ApiResponses({
Expand Down Expand Up @@ -75,21 +86,6 @@ public SuccessNonDataResponse offerCreateRequest(
return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS);
}

@Operation(summary = "[JWT] 모델 지원서 상세 조회", description = "모델 지원서 상세 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "지원서 아이디가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping("/{applicationId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ApplicationDetailInfoResponse> getApplicationDetailInfo(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId) {
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, designerService.getApplicationDetail(userId, applicationId));
}

@Operation(summary = "[JWT] 제안서 다운로드 링크", description = "디자이너 제안서 다운로드 링크 불러오는 API")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
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
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.moddy.server.domain.hair_service_record.HairServiceRecord;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface HairServiceRecordJpaRepository extends JpaRepository<HairServiceRecord, Long> {
void deleteAllByHairModelApplication(HairModelApplication hairModelApplication);
List<HairServiceRecord> findAllByHairModelApplicationId(Long applicationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.controller.designer.dto.response.HairModelApplicationResponse;
import com.moddy.server.controller.designer.dto.response.HairRecordResponse;
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;
import com.moddy.server.domain.hair_service_offer.HairServiceOffer;
import com.moddy.server.domain.model.ModelApplyStatus;
import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository;
import com.moddy.server.domain.hair_service_record.HairServiceRecord;
import com.moddy.server.domain.hair_service_record.repository.HairServiceRecordJpaRepository;
import com.moddy.server.domain.prefer_hair_style.PreferHairStyle;
import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository;
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository;
import com.moddy.server.service.designer.DesignerRetrieveService;
import com.moddy.server.service.model.ModelRetrieveService;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -33,6 +37,9 @@ public class HairModelApplicationRetrieveService {
private final DesignerRetrieveService designerRetrieveService;
private final ModelRetrieveService modelRetrieveService;
private final PreferHairStyleJpaRepository preferHairStyleJpaRepository;
private final PreferRegionJpaRepository preferRegionJpaRepository;
private final HairServiceRecordJpaRepository hairServiceRecordJpaRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;

public String getApplicationCaptureUrl(final Long applicationId) {
HairModelApplication application = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
Expand All @@ -54,7 +61,34 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int
applicationResponsesList
);
}
public ApplicationDto getApplicationDetailInfo(final Long applicationId){
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
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()));

List<HairRecordResponse> recordResponseList = hairServiceRecords.stream().map(records -> {
HairRecordResponse hairRecordResponse = new HairRecordResponse(
records.getServiceRecordTerm().getValue(),
records.getServiceRecord().getValue()
);
return hairRecordResponse;
}).collect(Collectors.toList());

return new ApplicationDto(
hairModelApplication.getModelImgUrl(),
hairModelApplication.getHairLength().getValue(),
preferhairStyleList,
recordResponseList,
hairModelApplication.getHairDetail(),
hairModelApplication.getInstagramId());
}
public String fetchApplicationHairDetail(final Long applicationId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
return hairModelApplication.getHairDetail();
Expand Down
Loading
Loading