-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
9ec918e
e0008ea
8a8fd44
c009e4f
5bb0678
70d1dfd
ff08eb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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)); | ||
|
@@ -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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p2 |
||
List<String> regionList = preferRegions.stream().map(preferregion -> { | ||
return preferregion.getRegion().getName(); | ||
}).collect(Collectors.toList()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3
여기서도 userId를 designerId로 수정하면 좋을 것 같습니다!