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 1 commit
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 @@ -87,7 +87,7 @@ public SuccessNonDataResponse offerCreateRequest(
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));
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, hairModelApplicationRetrieveService.getApplicationDetail(userId, applicationId));
Copy link
Member

Choose a reason for hiding this comment

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

p3
여기서도 userId를 designerId로 수정하면 좋을 것 같습니다!

}

@Operation(summary = "[JWT] 제안서 다운로드 링크", description = "디자이너 제안서 다운로드 링크 불러오는 API")
Expand Down

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 @@ -2,13 +2,23 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
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.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.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.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.PreferRegion;
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository;
import com.moddy.server.service.designer.DesignerRetrieveService;
import com.moddy.server.service.model.ModelRetrieveService;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,7 +28,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
Expand All @@ -30,6 +42,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 @@ -51,6 +66,61 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int
applicationResponsesList
);
}

public ApplicationDetailInfoResponse getApplicationDetail(final Long designerId, 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());

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

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

Copy link
Member

Choose a reason for hiding this comment

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

p2
Offer 서비스에서 해당 api를 위해 preferRegion을 참조하는 것 보다
modelRetrieve를 통해서 모델 정보를 가져올 때 preferRegion 정보도 같이 가져오는 것이 어떨까요?

List<String> regionList = preferRegions.stream().map(preferregion -> {
return preferregion.getRegion().getName();
}).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

p2
해당 구문은 사용하지 않는 구문인 것 같습니다!
사용하지 않는 구문은 제거해주세요!

또한, 해당 구문을 지우면 PreferRegionRepository도 사용하지 않게될텐데 해당 변수와 import도 같이 제거해주세요!


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

ApplicationInfoResponse applicationInfoResponse = new ApplicationInfoResponse(
applicationId,
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
);
}
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);
Expand All @@ -75,4 +145,8 @@ private HairModelApplicationResponse getApplicationResponse(final HairModelAppli
);
return applicationResponse;
}
private Boolean getIsSendStatus(final Long applicationId, final Long userId) {
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndDesignerId(applicationId, userId);
return offer.isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import com.moddy.server.controller.designer.dto.request.OfferCreateRequest;
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.HairModelApplicationResponse;
import com.moddy.server.controller.designer.dto.response.HairRecordResponse;
import com.moddy.server.controller.designer.dto.response.ModelInfoResponse;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
Expand All @@ -26,7 +24,6 @@
import com.moddy.server.domain.hair_service_offer.HairServiceOffer;
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.HairServcieRecordJpaRepository;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
import com.moddy.server.domain.prefer_hair_style.PreferHairStyle;
Expand All @@ -45,9 +42,6 @@
import com.moddy.server.service.auth.AuthService;
import lombok.Builder;
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 org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -76,10 +70,8 @@ public class DesignerService {
private final PreferHairStyleJpaRepository preferHairStyleJpaRepository;
private final ModelJpaRepository modelJpaRepository;
private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository;
private final HairServcieRecordJpaRepository hairServiceRecordJpaRepository;
private final AuthService authService;
private final PreferRegionJpaRepository preferRegionJpaRepository;
private final HairServcieRecordJpaRepository hairServcieRecordJpaRepository;
private final UserRepository userRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
private final SmsUtil smsUtil;
Expand Down Expand Up @@ -150,66 +142,6 @@ public void postOffer(Long userId, Long applicationId, OfferCreateRequest reques
smsUtil.sendOfferToModel(modelPhoneNumber, modelName);
}

@Transactional
public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long applicationId) {

HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

Model model = modelJpaRepository.findById(hairModelApplication.getModel().getId()).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());

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

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

List<String> regionList = preferRegions.stream().map(preferregion -> {
return preferregion.getRegion().getName();
}).collect(Collectors.toList());

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

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

ModelInfoResponse modelInfoResponse = new ModelInfoResponse(
model.getId(),
model.getName(),
model.getAge(),
model.getGender().getValue(),
regionList,
hairModelApplication.getInstagramId()
);

return new ApplicationDetailInfoResponse(
applicationInfoResponse,
modelInfoResponse
);
}

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

public DownloadUrlResponseDto getOfferImageDownloadUrl(final Long userId, final String offerImageUrl) {
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
String preSignedUrl = s3Service.getPreSignedUrlToDownload(offerImageUrl);
Expand Down
Loading