Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/TEAM-MODDY/moddy-server
Browse files Browse the repository at this point in the history
…into refactor/#224

# Conflicts:
#	src/main/java/com/moddy/server/controller/application/ApplicationController.java
#	src/main/java/com/moddy/server/controller/designer/DesignerController.java
  • Loading branch information
pkl0912 committed Feb 7, 2024
2 parents 186ae05 + edbd217 commit 37f5c57
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/moddy/server/config/jwt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private Claims getAccessTokenClaims() {
return Jwts.claims()
.setSubject(ACCESS_TOKEN)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + 20 * 1000L));
.setExpiration(new Date(now.getTime() + 40 * 1000L));
}

private Claims getBody(final String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
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.DesignerMainResponse;
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 @@ -21,6 +28,7 @@
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.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
Expand All @@ -33,6 +41,8 @@ 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입니다.")
Expand All @@ -51,7 +61,6 @@ 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({
Expand All @@ -67,5 +76,42 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, hairModelApplicationRetrieveService.getDesignerMainInfo(designerId, page, size));
}
@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 @@ -25,7 +25,6 @@
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.RequestBody;
Expand Down Expand Up @@ -80,21 +79,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
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 @@ -116,66 +108,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

0 comments on commit 37f5c57

Please sign in to comment.