diff --git a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java index 2a7ad8f5..9289c058 100644 --- a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java @@ -26,7 +26,8 @@ public enum SuccessCode { REFRESH_SUCCESS(HttpStatus.OK, "토큰 갱신 성공입니다."), CREATE_MODEL_APPLICATION_SUCCESS(HttpStatus.OK, "모델 지원서 생성 성공입니다."), USER_WITHDRAW_SUCCESS(HttpStatus.OK, "회원 탈퇴 성공입니다."), - GET_PRE_SIGNED_URL_SUCCESS(HttpStatus.OK, "제안서 다운로드 url 생성 성공"); + GET_PRE_SIGNED_URL_SUCCESS(HttpStatus.OK, "제안서 다운로드 url 생성 성공"), + GET_APPLICATION_IMG_URL_SUCCESS(HttpStatus.OK, "지원서 이미지 url 가져오기 성공"); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/moddy/server/config/resolver/kakao/KakaoCodeResolver.java b/src/main/java/com/moddy/server/config/resolver/kakao/KakaoCodeResolver.java index d1269679..e07ae02c 100644 --- a/src/main/java/com/moddy/server/config/resolver/kakao/KakaoCodeResolver.java +++ b/src/main/java/com/moddy/server/config/resolver/kakao/KakaoCodeResolver.java @@ -1,5 +1,6 @@ package com.moddy.server.config.resolver.kakao; +import com.moddy.server.common.exception.model.BadRequestException; import com.moddy.server.common.exception.model.UnAuthorizedException; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; @@ -28,7 +29,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m final HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest(); final String token = request.getHeader(AUTHORIZATION); if (token == null || token.isBlank() || !token.startsWith("Bearer ")) { - throw new UnAuthorizedException(EMPTY_KAKAO_CODE_EXCEPTION); + throw new BadRequestException(EMPTY_KAKAO_CODE_EXCEPTION); } return token.substring("Bearer ".length()); } diff --git a/src/main/java/com/moddy/server/controller/application/ApplicationController.java b/src/main/java/com/moddy/server/controller/application/ApplicationRegisterController.java similarity index 90% rename from src/main/java/com/moddy/server/controller/application/ApplicationController.java rename to src/main/java/com/moddy/server/controller/application/ApplicationRegisterController.java index 5d1e90b1..d052e89a 100644 --- a/src/main/java/com/moddy/server/controller/application/ApplicationController.java +++ b/src/main/java/com/moddy/server/controller/application/ApplicationRegisterController.java @@ -18,17 +18,19 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; @RestController @RequiredArgsConstructor -public class ApplicationController { +@Tag(name = "Application Controller") +@RequestMapping("/application") +public class ApplicationRegisterController { private final HairModelApplicationRegisterService hairModelApplicationRegisterService; - @Tag(name = "ModelController") @Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"), @@ -36,7 +38,7 @@ public class ApplicationController { @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), }) @SecurityRequirement(name = "JWT Auth") - @PostMapping(value = "/model/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public SuccessNonDataResponse submitModelApplication( @Parameter(hidden = true) @UserId Long modelId, @RequestPart(value = "modelImgUrl", required = false) MultipartFile modelImgUrl, @@ -46,4 +48,3 @@ public SuccessNonDataResponse submitModelApplication( return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS); } } - diff --git a/src/main/java/com/moddy/server/controller/designer/DesignerController.java b/src/main/java/com/moddy/server/controller/application/ApplicationRetrieveController.java similarity index 59% rename from src/main/java/com/moddy/server/controller/designer/DesignerController.java rename to src/main/java/com/moddy/server/controller/application/ApplicationRetrieveController.java index 3a1a4307..aeb400ce 100644 --- a/src/main/java/com/moddy/server/controller/designer/DesignerController.java +++ b/src/main/java/com/moddy/server/controller/application/ApplicationRetrieveController.java @@ -1,17 +1,20 @@ -package com.moddy.server.controller.designer; +package com.moddy.server.controller.application; 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.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.controller.model.dto.response.ApplicationImgUrlResponse; 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; @@ -20,28 +23,39 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; 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; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; - import static com.moddy.server.common.exception.enums.SuccessCode.GET_PRE_SIGNED_URL_SUCCESS; +@Tag(name = "Application Controller", description = "지원서 관련 API 입니다.") @RestController -@RequestMapping("/designer") -@Tag(name = "DesignerController") @RequiredArgsConstructor -public class DesignerController { - - private final DesignerService designerService; +@RequestMapping("/application") +public class ApplicationRetrieveController { private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService; + private final ModelRetrieveService modelRetrieveService; + private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService; + + @Operation(summary = "[JWT] 제안서 다운로드 링크", description = "디자이너 제안서 다운로드 링크 불러오는 API") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "지원서 다운로드 URL 조회 성공"), + @ApiResponse(responseCode = "401", description = "토큰이 만료되었습니다. 다시 로그인 해주세요."), + @ApiResponse(responseCode = "404", description = "해당 지원서는 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + }) + @GetMapping("/{applicationId}/download-url") + @SecurityRequirement(name = "JWT Auth") + public SuccessResponse getOfferImageDownloadUrl( + @Parameter(hidden = true) @UserId final Long modelId, + @PathVariable final Long applicationId + ) { + return SuccessResponse.success(GET_PRE_SIGNED_URL_SUCCESS, hairModelApplicationRetrieveService.getApplicationCaptureDownloadUrl(applicationId)); + } @Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.") @ApiResponses({ @@ -58,23 +72,6 @@ public SuccessResponse getDesignerMainInfo( return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, hairModelApplicationRetrieveService.getDesignerMainInfo(designerId, page, size)); } - @Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "제안서 작성 성공", content = @Content(schema = @Schema(implementation = SuccessNonDataResponse.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))), - }) - @SecurityRequirement(name = "JWT Auth") - @PostMapping("{applicationId}/offer") - public SuccessNonDataResponse offerCreateRequest( - @Parameter(hidden = true) @UserId Long userId, - @PathVariable(value = "applicationId") Long applicationId, - @Valid @RequestBody OfferCreateRequest offerCreateRequest) throws IOException { - designerService.postOffer(userId, applicationId, 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))), @@ -85,24 +82,46 @@ public SuccessNonDataResponse offerCreateRequest( @GetMapping("/{applicationId}") @SecurityRequirement(name = "JWT Auth") public SuccessResponse 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, designerService.getApplicationDetail(userId, applicationId)); + ApplicationDto applicationDto = hairModelApplicationRetrieveService.getApplicationDetailInfo(applicationId); + ApplicationModelInfoDto modelInfoDto = modelRetrieveService.getApplicationModelInfo(applicationDto.modelId()); + ApplicationInfoResponse applicationInfoResponse = new ApplicationInfoResponse( + applicationId, + applicationDto.modelImgUrl(), + applicationDto.hairLength(), + applicationDto.preferHairStyleList(), + applicationDto.recordResponseList(), + applicationDto.hairDetail(), + hairServiceOfferRetrieveService.getIsSendStatus(applicationId, designerId), + applicationDto.instgramId() + ); + + ModelInfoResponse modelInfoResponse = new ModelInfoResponse( + modelInfoDto.modelId(), + modelInfoDto.name(), + modelInfoDto.age(), + modelInfoDto.gender(), + modelInfoDto.regionList() + + ); + + ApplicationDetailInfoResponse applicationDetailInfoResponse = new ApplicationDetailInfoResponse(applicationInfoResponse, modelInfoResponse); + return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, applicationDetailInfoResponse); } - @Operation(summary = "[JWT] 제안서 다운로드 링크", description = "디자이너 제안서 다운로드 링크 불러오는 API") + @Operation(summary = "[JWT] 지원서 이미지 가져오기", description = "오픈채팅 뷰에서 지원서 이미지 가져오기 API입니다.") @ApiResponses({ - @ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))), - @ApiResponse(responseCode = "404", description = "해당 디자이너는 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @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))), }) - @PostMapping("/offer/download-url") + @GetMapping("/{applicationId}/img-url") @SecurityRequirement(name = "JWT Auth") - public SuccessResponse getOfferImageDownloadUrl( - @Parameter(hidden = true) @UserId Long userId, - @RequestBody OfferImageUrlRequestDto offerImageUrlRequestDto - ) { - return SuccessResponse.success(GET_PRE_SIGNED_URL_SUCCESS, designerService.getOfferImageDownloadUrl(userId, offerImageUrlRequestDto.offerImageUrl())); + public SuccessResponse getApplicationImgUrlOpenChat( + @Parameter(hidden = true) @UserId Long modelId, + @PathVariable(value = "applicationId") Long applicationId) { + return SuccessResponse.success(SuccessCode.GET_APPLICATION_IMG_URL_SUCCESS, hairModelApplicationRetrieveService.getApplicationImgUrl(applicationId)); } - } diff --git a/src/main/java/com/moddy/server/controller/application/dto/response/ApplicationInfoDetailResponse.java b/src/main/java/com/moddy/server/controller/application/dto/response/ApplicationInfoDetailResponse.java new file mode 100644 index 00000000..36e1292f --- /dev/null +++ b/src/main/java/com/moddy/server/controller/application/dto/response/ApplicationInfoDetailResponse.java @@ -0,0 +1,10 @@ +package com.moddy.server.controller.application.dto.response; + +import java.util.List; + +public record ApplicationInfoDetailResponse( + Long applicationId, + List preferStyle, + String modelApplicationDetail +) { +} diff --git a/src/main/java/com/moddy/server/controller/auth/AuthController.java b/src/main/java/com/moddy/server/controller/auth/AuthRegisterController.java similarity index 82% rename from src/main/java/com/moddy/server/controller/auth/AuthController.java rename to src/main/java/com/moddy/server/controller/auth/AuthRegisterController.java index 3504d6bf..693bd21d 100644 --- a/src/main/java/com/moddy/server/controller/auth/AuthController.java +++ b/src/main/java/com/moddy/server/controller/auth/AuthRegisterController.java @@ -5,17 +5,13 @@ import com.moddy.server.common.dto.SuccessNonDataResponse; import com.moddy.server.common.dto.SuccessResponse; import com.moddy.server.common.dto.TokenPair; -import com.moddy.server.common.exception.enums.SuccessCode; import com.moddy.server.config.resolver.kakao.KakaoCode; import com.moddy.server.config.resolver.user.UserId; import com.moddy.server.controller.auth.dto.request.PhoneNumberRequestDto; import com.moddy.server.controller.auth.dto.request.TokenRequestDto; import com.moddy.server.controller.auth.dto.request.VerifyCodeRequestDto; import com.moddy.server.controller.auth.dto.response.LoginResponseDto; -import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest; -import com.moddy.server.controller.designer.dto.response.UserCreateResponse; import com.moddy.server.service.auth.AuthService; -import com.moddy.server.service.designer.DesignerService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; @@ -27,13 +23,10 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -47,11 +40,10 @@ @RestController @RequestMapping("/auth") @RequiredArgsConstructor -public class AuthController { +public class AuthRegisterController { private static final String ORIGIN = "origin"; private final AuthService authService; - private final DesignerService designerService; @Operation(summary = "[KAKAO CODE] 로그인 API") @@ -69,20 +61,6 @@ public SuccessResponse login( return SuccessResponse.success(SOCIAL_LOGIN_SUCCESS, authService.login(request.getHeader(ORIGIN), kakaoCode)); } - @Operation(summary = "[JWT] 디자이너 회원가입 API", description = "디자이너 회원가입 조회 API입니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "디자이너 회원가입 성공", content = @Content(schema = @Schema(implementation = UserCreateResponse.class))), - @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - }) - @SecurityRequirement(name = "JWT Auth") - @PostMapping(value = "/signup/designer", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) - SuccessResponse createDesigner( - @Parameter(hidden = true) @UserId Long userId, - @RequestPart(value = "profileImg", required = false) MultipartFile profileImg, - @Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) { - return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(userId, designerInfo, profileImg)); - } - @Operation(summary = "인증번호 요청 API", description = "인증번호 요청 API입니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "전화번호 인증 요청 성공입니다."), diff --git a/src/main/java/com/moddy/server/controller/designer/DesignerRegisterController.java b/src/main/java/com/moddy/server/controller/designer/DesignerRegisterController.java new file mode 100644 index 00000000..396387b9 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/designer/DesignerRegisterController.java @@ -0,0 +1,47 @@ +package com.moddy.server.controller.designer; + +import com.moddy.server.common.dto.ErrorResponse; +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.request.DesignerCreateRequest; +import com.moddy.server.controller.designer.dto.response.UserCreateResponse; +import com.moddy.server.service.designer.DesignerRegisterService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequiredArgsConstructor +@Tag(name = "Designer Controller") +@RequestMapping("/designer") +public class DesignerRegisterController { + private final DesignerRegisterService designerRegisterService; + + @Operation(summary = "[JWT] 디자이너 회원가입 API", description = "디자이너 회원가입 조회 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "디자이너 회원가입 성공", content = @Content(schema = @Schema(implementation = UserCreateResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + }) + @SecurityRequirement(name = "JWT Auth") + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + SuccessResponse createDesigner( + @Parameter(hidden = true) @UserId Long designerId, + @RequestPart(value = "profileImg", required = false) MultipartFile profileImg, + @Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) { + return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerRegisterService.createDesigner(designerId, designerInfo, profileImg)); + } +} diff --git a/src/main/java/com/moddy/server/controller/designer/DesignerRetrieveController.java b/src/main/java/com/moddy/server/controller/designer/DesignerRetrieveController.java new file mode 100644 index 00000000..094d48d3 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/designer/DesignerRetrieveController.java @@ -0,0 +1,44 @@ +package com.moddy.server.controller.designer; + +import com.moddy.server.common.dto.ErrorResponse; +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.model.dto.DesignerInfoOpenChatDto; +import com.moddy.server.service.designer.DesignerRetrieveService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Tag(name = "Designer Controller") +@RequestMapping("/designer") +public class DesignerRetrieveController { + + private final DesignerRetrieveService designerRetrieveService; + + @Operation(summary = "[JWT] 카카오톡 오픈채팅", description = "오픈채팅 뷰에서 디자이너 정보 조회입니다") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "디자이너 정보 조회 성공", content = @Content(schema = @Schema(implementation = DesignerInfoOpenChatDto.class))), + @ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + }) + @GetMapping("/{designerId}") + @SecurityRequirement(name = "JWT Auth") + public SuccessResponse getDesignerOpenChatInfo( + @Parameter(hidden = true) @UserId Long modelId, + @Parameter(name = "designerId", description = "디자이너아이디") @PathVariable(value = "designerId") Long designerId) { + return SuccessResponse.success(SuccessCode.OPEN_CHAT_GET_SUCCESS, designerRetrieveService.getDesignerOpenChatInfo(designerId)); + } +} diff --git a/src/main/java/com/moddy/server/controller/designer/dto/response/ApplicationInfoResponse.java b/src/main/java/com/moddy/server/controller/designer/dto/response/ApplicationInfoResponse.java index bda471bc..cf3f0e16 100644 --- a/src/main/java/com/moddy/server/controller/designer/dto/response/ApplicationInfoResponse.java +++ b/src/main/java/com/moddy/server/controller/designer/dto/response/ApplicationInfoResponse.java @@ -1,8 +1,5 @@ package com.moddy.server.controller.designer.dto.response; -import com.moddy.server.domain.hair_model_application.HairLength; -import com.moddy.server.domain.prefer_hair_style.HairStyle; - import java.util.List; public record ApplicationInfoResponse( @@ -12,6 +9,7 @@ public record ApplicationInfoResponse( List preferHairstyles, List hairServiceRecords, String hairDetail, - Boolean isSend + boolean isSend, + String instagramId ) { } diff --git a/src/main/java/com/moddy/server/controller/designer/dto/response/DownloadUrlResponseDto.java b/src/main/java/com/moddy/server/controller/designer/dto/response/DownloadUrlResponseDto.java index 97b65480..ce302c72 100644 --- a/src/main/java/com/moddy/server/controller/designer/dto/response/DownloadUrlResponseDto.java +++ b/src/main/java/com/moddy/server/controller/designer/dto/response/DownloadUrlResponseDto.java @@ -1,4 +1,4 @@ package com.moddy.server.controller.designer.dto.response; -public record DownloadUrlResponseDto(String offerImageUrl) { +public record DownloadUrlResponseDto(String applicationDownloadUrl) { } diff --git a/src/main/java/com/moddy/server/controller/designer/dto/response/ModelInfoResponse.java b/src/main/java/com/moddy/server/controller/designer/dto/response/ModelInfoResponse.java index 025c2a0d..c156f32d 100644 --- a/src/main/java/com/moddy/server/controller/designer/dto/response/ModelInfoResponse.java +++ b/src/main/java/com/moddy/server/controller/designer/dto/response/ModelInfoResponse.java @@ -7,8 +7,7 @@ public record ModelInfoResponse( String name, Integer age, String gender, - List preferRegions, - String instagramId + List preferRegions ) { } diff --git a/src/main/java/com/moddy/server/controller/model/ModelController.java b/src/main/java/com/moddy/server/controller/model/ModelController.java deleted file mode 100644 index c71f94ff..00000000 --- a/src/main/java/com/moddy/server/controller/model/ModelController.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.moddy.server.controller.model; - -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.auth.dto.response.RegionResponse; -import com.moddy.server.controller.designer.dto.response.UserCreateResponse; -import com.moddy.server.controller.model.dto.request.ModelCreateRequest; -import com.moddy.server.controller.model.dto.response.ApplicationUserDetailResponse; -import com.moddy.server.controller.model.dto.response.DetailOfferResponse; -import com.moddy.server.controller.model.dto.response.OpenChatResponse; -import com.moddy.server.service.model.ModelRegisterService; -import com.moddy.server.service.model.ModelRetrieveService; -import com.moddy.server.service.model.ModelService; -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; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -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.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -import java.util.List; - -@RestController -@RequiredArgsConstructor -public class ModelController { - - private final ModelService modelService; - private final ModelRegisterService modelRegisterService; - private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService; - private final ModelRetrieveService modelRetrieveService; - - @Tag(name = "Auth Controller") - @Operation(summary = "모델 회원가입 시 희망 지역 리스트 조회 API") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "희망 지역 리스트 조회 성공입니다."), - @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) - }) - @GetMapping("/auth/regions") - public SuccessResponse> getRegionList() { - return SuccessResponse.success(SuccessCode.FIND_REGION_LIST_SUCCESS, modelRetrieveService.getRegionList()); - } - - @Tag(name = "Auth Controller", description = "로그인 및 회원 가입 관련 API 입니다.") - @Operation(summary = "[JWT] 모델 회원가입 API", description = "모델 회원가입 API입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "모델 회원가입 성공"), - @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))) - }) - @PostMapping(value = "/auth/signup/model") - @SecurityRequirement(name = "JWT Auth") - public SuccessResponse createModel( - @Parameter(hidden = true) @UserId Long userId, - @Valid @RequestBody ModelCreateRequest modelCreateRequest) { - return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelRegisterService.createModel(userId, modelCreateRequest)); - } - - @Tag(name = "ModelController") - @Operation(summary = "[JWT] 제안서 상세보기 뷰 조회", description = "제안서 상세보기 API입니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "제안서 상세보기 조회 성공", content = @Content(schema = @Schema(implementation = DetailOfferResponse.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("/model/offer/{offerId}") - @SecurityRequirement(name = "JWT Auth") - public SuccessResponse getModelDetailOfferInfo( - @Parameter(hidden = true) @UserId Long userId, - @Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) { - return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, modelService.getOfferDetail(userId, offerId)); - } - - @Tag(name = "ModelController") - @Operation(summary = "[JWT] 카카오톡 오픈채팅", description = "지원서 캡처 이미지 및 디자이너 정보 조회입니다") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = OpenChatResponse.class))), - @ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), - }) - @GetMapping("/model/{offerId}/agree") - @SecurityRequirement(name = "JWT Auth") - public SuccessResponse getOpenChat( - @Parameter(hidden = true) @UserId Long userId, - @Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) { - return SuccessResponse.success(SuccessCode.OPEN_CHAT_GET_SUCCESS, hairServiceOfferRetrieveService.getOpenChatInfo(userId, offerId)); - } - - @Tag(name = "ModelController") - @Operation(summary = "[JWT] 디자이너 제안서 승낙하기", description = "디자이너 제안서 승낙하기 API입니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "디자이너 제안서 승낙하기"), - @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))), - }) - @PutMapping("/model/offer/{offerId}") - @SecurityRequirement(name = "JWT Auth") - public SuccessNonDataResponse acceptOffer( - @Parameter(hidden = true) @UserId Long userId, - @Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) { - modelService.updateOfferAgreeStatus(offerId); - return SuccessNonDataResponse.success(SuccessCode.OFFER_ACCEPT_SUCCESS); - } - - @Tag(name = "ModelController") - @Operation(summary = "[JWT] 모델 지원서 최종 확인 시 유저 정보 조회 API", description = "[모델 뷰] 모델 지원서 최종 확인 시 유저 정보 조회 API 입니다.") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"), - @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))), - }) - @SecurityRequirement(name = "JWT Auth") - @GetMapping(value = "/model/application/user") - public SuccessResponse getUserDetailInApplication(@Parameter(hidden = true) @UserId Long userId) { - return SuccessResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS, modelService.getUserDetailInApplication(userId)); - } - -} diff --git a/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java b/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java new file mode 100644 index 00000000..f64b4f31 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java @@ -0,0 +1,47 @@ +package com.moddy.server.controller.model; + +import com.moddy.server.common.dto.ErrorResponse; +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.UserCreateResponse; +import com.moddy.server.controller.model.dto.request.ModelCreateRequest; +import com.moddy.server.service.model.ModelRegisterService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Tag(name = "Model Controller") +@RequestMapping("/model") +public class ModelRegisterController { + + private final ModelRegisterService modelRegisterService; + + @Operation(summary = "[JWT] 모델 회원가입 API", description = "모델 회원가입 API입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "모델 회원가입 성공"), + @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))) + }) + @PostMapping + @SecurityRequirement(name = "JWT Auth") + public SuccessResponse createModel( + @Parameter(hidden = true) @UserId Long userId, + @Valid @RequestBody ModelCreateRequest modelCreateRequest) { + return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelRegisterService.createModel(userId, modelCreateRequest)); + } +} diff --git a/src/main/java/com/moddy/server/controller/model/ModelRetrieveController.java b/src/main/java/com/moddy/server/controller/model/ModelRetrieveController.java new file mode 100644 index 00000000..46cea673 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/model/ModelRetrieveController.java @@ -0,0 +1,55 @@ +package com.moddy.server.controller.model; + +import com.moddy.server.common.dto.ErrorResponse; +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.auth.dto.response.RegionResponse; +import com.moddy.server.controller.model.dto.response.ApplicationUserDetailResponse; +import com.moddy.server.service.model.ModelRetrieveService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + + +@Tag(name = "Model Controller", description = "모델과 관련된 API 입니다.") +@RestController +@RequiredArgsConstructor +@RequestMapping("/model") +public class ModelRetrieveController { + private final ModelRetrieveService modelRetrieveService; + + @Operation(summary = "모델 회원가입 시 희망 지역 리스트 조회 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "희망 지역 리스트 조회 성공입니다."), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @GetMapping("/regions") + public SuccessResponse> getRegionList() { + return SuccessResponse.success(SuccessCode.FIND_REGION_LIST_SUCCESS, modelRetrieveService.getRegionList()); + } + + @Operation(summary = "[JWT] 모델 지원서 최종 확인 시 유저 정보 조회 API", description = "[모델 뷰] 모델 지원서 최종 확인 시 유저 정보 조회 API 입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"), + @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))), + }) + @SecurityRequirement(name = "JWT Auth") + @GetMapping(value = "/detail") + public SuccessResponse getUserDetailInApplication(@Parameter(hidden = true) @UserId final Long modelId) { + return SuccessResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS, modelRetrieveService.getModelDetailInApplication(modelId)); + } +} \ No newline at end of file diff --git a/src/main/java/com/moddy/server/controller/model/dto/ApplicationDto.java b/src/main/java/com/moddy/server/controller/model/dto/ApplicationDto.java new file mode 100644 index 00000000..eb1b7b8a --- /dev/null +++ b/src/main/java/com/moddy/server/controller/model/dto/ApplicationDto.java @@ -0,0 +1,16 @@ +package com.moddy.server.controller.model.dto; + +import com.moddy.server.controller.designer.dto.response.HairRecordResponse; + +import java.util.List; + +public record ApplicationDto( + Long modelId, + String modelImgUrl, + String hairLength, + List preferHairStyleList, + List recordResponseList, + String hairDetail, + String instgramId +) { +} diff --git a/src/main/java/com/moddy/server/controller/model/dto/ApplicationModelInfoDto.java b/src/main/java/com/moddy/server/controller/model/dto/ApplicationModelInfoDto.java index d5445baf..b562b436 100644 --- a/src/main/java/com/moddy/server/controller/model/dto/ApplicationModelInfoDto.java +++ b/src/main/java/com/moddy/server/controller/model/dto/ApplicationModelInfoDto.java @@ -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 regionList ) { } diff --git a/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java b/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java index 0338a9a4..2c9e9a03 100644 --- a/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java +++ b/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java @@ -2,7 +2,7 @@ import com.moddy.server.common.validation.year.ValidYear; import com.moddy.server.common.validation.prefer_regions.ValidPreferRegions; -import com.moddy.server.controller.user.dto.UserUpdateDto; +import com.moddy.server.controller.user.dto.request.UserUpdateDto; import com.moddy.server.domain.user.Gender; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.EnumType; diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/ApplicationImgUrlResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/ApplicationImgUrlResponse.java new file mode 100644 index 00000000..a6a381ae --- /dev/null +++ b/src/main/java/com/moddy/server/controller/model/dto/response/ApplicationImgUrlResponse.java @@ -0,0 +1,4 @@ +package com.moddy.server.controller.model.dto.response; + +public record ApplicationImgUrlResponse(String applicationImgUrl) { +} diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoOpenChatResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoOpenChatResponse.java deleted file mode 100644 index 1235c74d..00000000 --- a/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoOpenChatResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.moddy.server.controller.model.dto.response; - -public record DesignerInfoOpenChatResponse( - String imgUrl, - String shopName, - String name, - String introduction -) { -} diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoResponse.java index d452c8b0..dc878d6a 100644 --- a/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoResponse.java +++ b/src/main/java/com/moddy/server/controller/model/dto/response/DesignerInfoResponse.java @@ -3,6 +3,7 @@ import java.util.List; public record DesignerInfoResponse( + Long designerId, String imgUrl, String shopName, String name, diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/DetailOfferResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/DetailOfferResponse.java deleted file mode 100644 index 1f55b184..00000000 --- a/src/main/java/com/moddy/server/controller/model/dto/response/DetailOfferResponse.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.moddy.server.controller.model.dto.response; - -public record DetailOfferResponse( - DesignerInfoResponse designerInfo, - StyleDetailResponse styleDetail -) { -} diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/OpenChatResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/OpenChatResponse.java deleted file mode 100644 index d5d57fe1..00000000 --- a/src/main/java/com/moddy/server/controller/model/dto/response/OpenChatResponse.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.moddy.server.controller.model.dto.response; - -public record OpenChatResponse( - String applicationImgUrl, - String kakaoUrl, - DesignerInfoOpenChatResponse designerInfo -) { -} diff --git a/src/main/java/com/moddy/server/controller/model/dto/response/StyleDetailResponse.java b/src/main/java/com/moddy/server/controller/model/dto/response/StyleDetailResponse.java deleted file mode 100644 index 18fd28c8..00000000 --- a/src/main/java/com/moddy/server/controller/model/dto/response/StyleDetailResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.moddy.server.controller.model.dto.response; - -import java.util.List; - -public record StyleDetailResponse( - Boolean isAgree, - List preferStyle, - String designerOfferDetail, - String modelApplicationDetail, - List preferOfferConditions -) { -} \ No newline at end of file diff --git a/src/main/java/com/moddy/server/controller/offer/OfferRegisterController.java b/src/main/java/com/moddy/server/controller/offer/OfferRegisterController.java new file mode 100644 index 00000000..29fac37b --- /dev/null +++ b/src/main/java/com/moddy/server/controller/offer/OfferRegisterController.java @@ -0,0 +1,68 @@ +package com.moddy.server.controller.offer; + +import com.moddy.server.common.dto.ErrorResponse; +import com.moddy.server.common.dto.SuccessNonDataResponse; +import com.moddy.server.common.exception.enums.SuccessCode; +import com.moddy.server.config.resolver.user.UserId; +import com.moddy.server.controller.designer.dto.request.OfferCreateRequest; +import com.moddy.server.service.offer.HairServiceOfferRegisterService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + +@RestController +@RequiredArgsConstructor +@Tag(name = "Offer Controller") +@RequestMapping("/offer") +public class OfferRegisterController { + + private final HairServiceOfferRegisterService hairServiceOfferRegisterService; + + @Operation(summary = "[JWT] 디자이너 제안서 승낙하기", description = "디자이너 제안서 승낙하기 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "디자이너 제안서 승낙하기"), + @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))), + }) + @PutMapping("/{offerId}/agree") + @SecurityRequirement(name = "JWT Auth") + public SuccessNonDataResponse acceptOffer( + @Parameter(hidden = true) @UserId Long userId, + @Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) { + hairServiceOfferRegisterService.updateOfferAgreeStatus(offerId); + return SuccessNonDataResponse.success(SuccessCode.OFFER_ACCEPT_SUCCESS); + } + + @Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "제안서 작성 성공", content = @Content(schema = @Schema(implementation = SuccessNonDataResponse.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))), + }) + @SecurityRequirement(name = "JWT Auth") + @PostMapping("/{applicationId}") + public SuccessNonDataResponse offerCreateRequest( + @Parameter(hidden = true) @UserId Long designerId, + @PathVariable(value = "applicationId") Long applicationId, + @Valid @RequestBody OfferCreateRequest offerCreateRequest) throws IOException { + hairServiceOfferRegisterService.postOffer(designerId, applicationId, offerCreateRequest); + return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS); + } +} diff --git a/src/main/java/com/moddy/server/controller/offer/OfferController.java b/src/main/java/com/moddy/server/controller/offer/OfferRetrieveController.java similarity index 58% rename from src/main/java/com/moddy/server/controller/offer/OfferController.java rename to src/main/java/com/moddy/server/controller/offer/OfferRetrieveController.java index 9e2ca04b..9edbdeb9 100644 --- a/src/main/java/com/moddy/server/controller/offer/OfferController.java +++ b/src/main/java/com/moddy/server/controller/offer/OfferRetrieveController.java @@ -5,6 +5,7 @@ import com.moddy.server.common.exception.enums.SuccessCode; import com.moddy.server.config.resolver.user.UserId; import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse; +import com.moddy.server.controller.offer.dto.response.DetailOfferResponse; import com.moddy.server.service.offer.HairServiceOfferRetrieveService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -16,23 +17,26 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @RequiredArgsConstructor -public class OfferController { +@Tag(name = "Offer Controller") +@RequestMapping("/offer") +public class OfferRetrieveController { private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService; - @Tag(name = "ModelController") @Operation(summary = "[JWT] 모델 메인 뷰 조회", description = "모델 메인 뷰 조회 API입니다.") @ApiResponses({ @ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = ModelMainOfferResponse.class))), @ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), }) - @GetMapping("/model") + @GetMapping @SecurityRequirement(name = "JWT Auth") public SuccessResponse getModelMainInfo( @Parameter(hidden = true) @UserId Long modelId, @@ -40,4 +44,19 @@ public SuccessResponse getModelMainInfo( @Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) { return SuccessResponse.success(SuccessCode.FIND_MODEL_MAIN_INFO_SUCCESS, hairServiceOfferRetrieveService.getModelMainOfferInfo(modelId, page, size)); } -} + + @Operation(summary = "[JWT] 모델에게 온 디자이너 제안 상세보기", description = "제안서 상세보기 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "200", description = "제안서 상세보기 조회 성공", content = @Content(schema = @Schema(implementation = DetailOfferResponse.class))), + @ApiResponse(responseCode = "404", description = "제안서 아이디가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + }) + @GetMapping("/{offerId}") + @SecurityRequirement(name = "JWT Auth") + public SuccessResponse getModelDetailOfferInfo( + @Parameter(hidden = true) @UserId Long modelId, + @Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) { + return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, hairServiceOfferRetrieveService.getOfferDetail(offerId)); + } +} \ No newline at end of file diff --git a/src/main/java/com/moddy/server/controller/offer/dto/response/DetailOfferResponse.java b/src/main/java/com/moddy/server/controller/offer/dto/response/DetailOfferResponse.java new file mode 100644 index 00000000..5c4b1d81 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/offer/dto/response/DetailOfferResponse.java @@ -0,0 +1,13 @@ +package com.moddy.server.controller.offer.dto.response; + +import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse; +import com.moddy.server.controller.model.dto.response.DesignerInfoResponse; + +import com.moddy.server.controller.offer.dto.response.OfferInfoResponse; + +public record DetailOfferResponse( + DesignerInfoResponse designerInfo, + ApplicationInfoDetailResponse applicationInfo, + OfferInfoResponse offerInfo +) { +} diff --git a/src/main/java/com/moddy/server/controller/offer/dto/response/OfferInfoResponse.java b/src/main/java/com/moddy/server/controller/offer/dto/response/OfferInfoResponse.java new file mode 100644 index 00000000..2d125b07 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/offer/dto/response/OfferInfoResponse.java @@ -0,0 +1,13 @@ +package com.moddy.server.controller.offer.dto.response; + +import lombok.Builder; +import java.util.List; + +@Builder +public record OfferInfoResponse( + Long offerId, + Boolean isAgree, + String designerOfferDetail, + List preferOfferConditions +) { +} \ No newline at end of file diff --git a/src/main/java/com/moddy/server/controller/user/dto/UserUpdateDto.java b/src/main/java/com/moddy/server/controller/user/dto/request/UserUpdateDto.java similarity index 81% rename from src/main/java/com/moddy/server/controller/user/dto/UserUpdateDto.java rename to src/main/java/com/moddy/server/controller/user/dto/request/UserUpdateDto.java index eb325361..5e8a3cec 100644 --- a/src/main/java/com/moddy/server/controller/user/dto/UserUpdateDto.java +++ b/src/main/java/com/moddy/server/controller/user/dto/request/UserUpdateDto.java @@ -1,4 +1,4 @@ -package com.moddy.server.controller.user.dto; +package com.moddy.server.controller.user.dto.request; import com.moddy.server.domain.user.Gender; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/com/moddy/server/domain/designer/HairShop.java b/src/main/java/com/moddy/server/domain/designer/HairShop.java index 77990485..43f2e868 100644 --- a/src/main/java/com/moddy/server/domain/designer/HairShop.java +++ b/src/main/java/com/moddy/server/domain/designer/HairShop.java @@ -6,7 +6,6 @@ import lombok.*; @Embeddable -@Builder @AllArgsConstructor @NoArgsConstructor @Getter diff --git a/src/main/java/com/moddy/server/domain/designer/Portfolio.java b/src/main/java/com/moddy/server/domain/designer/Portfolio.java index cd6f0585..78d7b37d 100644 --- a/src/main/java/com/moddy/server/domain/designer/Portfolio.java +++ b/src/main/java/com/moddy/server/domain/designer/Portfolio.java @@ -8,7 +8,6 @@ @AllArgsConstructor @NoArgsConstructor @Getter -@Builder @ToString public class Portfolio { @NotNull diff --git a/src/main/java/com/moddy/server/domain/hair_service_offer/HairServiceOffer.java b/src/main/java/com/moddy/server/domain/hair_service_offer/HairServiceOffer.java index f5c2e330..404cef13 100644 --- a/src/main/java/com/moddy/server/domain/hair_service_offer/HairServiceOffer.java +++ b/src/main/java/com/moddy/server/domain/hair_service_offer/HairServiceOffer.java @@ -8,6 +8,8 @@ import jakarta.validation.constraints.NotNull; import lombok.*; +import java.time.LocalDateTime; + @Entity @Getter @Builder @@ -35,16 +37,24 @@ public class HairServiceOffer extends BaseTimeEntity { @NotNull private String offerDetail; - @NotNull - private Boolean isModelAgree; + private boolean isModelAgree; - @NotNull - private Boolean isClicked; + private boolean isClicked; - public void setIsModelAgree(final Boolean isModelAgree){ + public HairServiceOffer(HairModelApplication hairModelApplication, Model model, Designer designer, String offerDetail, boolean isModelAgree, boolean isClicked) { + this.hairModelApplication = hairModelApplication; + this.model = model; + this.designer = designer; + this.offerDetail = offerDetail; this.isModelAgree = isModelAgree; + this.isClicked = isClicked; + } + + public void agreeOfferToModel(){ + this.isModelAgree = true; } public void updateClickStatus() { this.isClicked = true; } + } diff --git a/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServcieRecordJpaRepository.java b/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServcieRecordJpaRepository.java deleted file mode 100644 index 04682336..00000000 --- a/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServcieRecordJpaRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.moddy.server.domain.hair_service_record.repository; - -import com.moddy.server.domain.hair_service_record.HairServiceRecord; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -public interface HairServcieRecordJpaRepository extends JpaRepository { - List findAllByHairModelApplicationId(Long applicationId); - -} diff --git a/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServiceRecordJpaRepository.java b/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServiceRecordJpaRepository.java index 05654fd4..da22f9d2 100644 --- a/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServiceRecordJpaRepository.java +++ b/src/main/java/com/moddy/server/domain/hair_service_record/repository/HairServiceRecordJpaRepository.java @@ -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 { void deleteAllByHairModelApplication(HairModelApplication hairModelApplication); + List findAllByHairModelApplicationId(Long applicationId); } diff --git a/src/main/java/com/moddy/server/domain/prefer_offer_condition/PreferOfferCondition.java b/src/main/java/com/moddy/server/domain/prefer_offer_condition/PreferOfferCondition.java index 58f0d1d1..eda91124 100644 --- a/src/main/java/com/moddy/server/domain/prefer_offer_condition/PreferOfferCondition.java +++ b/src/main/java/com/moddy/server/domain/prefer_offer_condition/PreferOfferCondition.java @@ -11,7 +11,6 @@ @Entity @Getter -@Builder @NoArgsConstructor @AllArgsConstructor public class PreferOfferCondition extends BaseTimeEntity { @@ -28,4 +27,8 @@ public class PreferOfferCondition extends BaseTimeEntity { @NotNull private OfferCondition offerCondition; + public PreferOfferCondition(final HairServiceOffer hairServiceOffer, final OfferCondition offerCondition){ + this.hairServiceOffer = hairServiceOffer; + this.offerCondition = offerCondition; + } } diff --git a/src/main/java/com/moddy/server/service/application/HairModelApplicationRetrieveService.java b/src/main/java/com/moddy/server/service/application/HairModelApplicationRetrieveService.java index b31c1ea4..8213992d 100644 --- a/src/main/java/com/moddy/server/service/application/HairModelApplicationRetrieveService.java +++ b/src/main/java/com/moddy/server/service/application/HairModelApplicationRetrieveService.java @@ -2,17 +2,24 @@ import com.moddy.server.common.exception.enums.ErrorCode; import com.moddy.server.common.exception.model.NotFoundException; +import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse; 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.model.dto.ApplicationDto; import com.moddy.server.controller.model.dto.ApplicationModelInfoDto; +import com.moddy.server.controller.model.dto.response.ApplicationImgUrlResponse; 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.ModelApplyStatus; +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.external.s3.S3Service; 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; @@ -20,6 +27,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -31,12 +39,9 @@ public class HairModelApplicationRetrieveService { private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; private final DesignerRetrieveService designerRetrieveService; private final ModelRetrieveService modelRetrieveService; + private final S3Service s3Service; private final PreferHairStyleJpaRepository preferHairStyleJpaRepository; - - public String getApplicationCaptureUrl(final Long applicationId){ - HairModelApplication application = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); - return application.getApplicationCaptureUrl(); - } + private final HairServiceRecordJpaRepository hairServiceRecordJpaRepository; public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int page, final int size) { @@ -54,10 +59,62 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int ); } - public boolean fetchModelApplyStatus(final Long modelId){ + public ApplicationInfoDetailResponse getOfferApplicationInfo(final Long applicationId) { + List preferHairStyleList = getPreferHairStyle(applicationId); + String applicationHairDetail = getApplicationHairDetail(applicationId); + + return new ApplicationInfoDetailResponse( + applicationId, + preferHairStyleList, + applicationHairDetail + ); + } + + public ApplicationDto getApplicationDetailInfo(final Long applicationId) { + HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); + Long modelId = hairModelApplication.getModel().getId(); + List preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId); + List preferhairStyleList = preferHairStyles.stream().map(hairStyle -> { + return hairStyle.getHairStyle().getValue(); + }).collect(Collectors.toList()); + + List hairServiceRecords = hairServiceRecordJpaRepository.findAllByHairModelApplicationId(applicationId); + hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal())); + + List recordResponseList = hairServiceRecords.stream().map(records -> { + HairRecordResponse hairRecordResponse = new HairRecordResponse( + records.getServiceRecordTerm().getValue(), + records.getServiceRecord().getValue() + ); + return hairRecordResponse; + }).collect(Collectors.toList()); + + return new ApplicationDto( + modelId, + hairModelApplication.getModelImgUrl(), + hairModelApplication.getHairLength().getValue(), + preferhairStyleList, + recordResponseList, + hairModelApplication.getHairDetail(), + hairModelApplication.getInstagramId()); + } + + public boolean fetchModelApplyStatus(final Long modelId) { return hairModelApplicationJpaRepository.existsByModelId(modelId); } + public ApplicationImgUrlResponse getApplicationImgUrl(final Long applicationId) { + + return new ApplicationImgUrlResponse(hairModelApplicationJpaRepository.findById(applicationId).get().getApplicationCaptureUrl()); + } + + public DownloadUrlResponseDto getApplicationCaptureDownloadUrl(final Long applicationId) { + final HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId) + .orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); + final String applicationDownloadUrl = s3Service.getPreSignedUrlToDownload(hairModelApplication.getApplicationCaptureUrl()); + return new DownloadUrlResponseDto(applicationDownloadUrl); + } + private Page findApplicationsByPaging(final int page, final int size) { PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id")); Page applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest); @@ -65,12 +122,26 @@ private Page findApplicationsByPaging(final int page, fina return applicationPage; } + private String getApplicationHairDetail(final Long applicationId) { + HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); + return hairModelApplication.getHairDetail(); + } + + private List getPreferHairStyle(final Long applicationId) { + List preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId); + List preferHairStyleList = preferHairStyles.stream().map(hairStyle -> { + return hairStyle.getHairStyle().getValue(); + }).collect(Collectors.toList()); + + return preferHairStyleList; + } + private HairModelApplicationResponse getApplicationResponse(final HairModelApplication application) { - Long modelId = application.getModel().getId(); List preferHairStyle = preferHairStyleJpaRepository.findTop2ByHairModelApplicationId(application.getId()); List top2hairStyles = preferHairStyle.stream().map(hairStyle -> { return hairStyle.getHairStyle().getValue(); }).collect(Collectors.toList()); + Long modelId = application.getModel().getId(); ApplicationModelInfoDto modelInfoDto = modelRetrieveService.getApplicationModelInfo(modelId); HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse( application.getId(), @@ -83,3 +154,4 @@ private HairModelApplicationResponse getApplicationResponse(final HairModelAppli return applicationResponse; } } + diff --git a/src/main/java/com/moddy/server/service/auth/AuthService.java b/src/main/java/com/moddy/server/service/auth/AuthService.java index ed666989..5b1182d4 100644 --- a/src/main/java/com/moddy/server/service/auth/AuthService.java +++ b/src/main/java/com/moddy/server/service/auth/AuthService.java @@ -90,12 +90,13 @@ public void logout(final Long userId) { } public TokenPair refresh(final TokenRequestDto tokenRequestDto) { - final String userId = jwtService.getUserIdInToken(tokenRequestDto.accessToken()); - final User user = userRepository.findById(Long.parseLong(userId)).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - if (!jwtService.compareRefreshToken(userId, tokenRequestDto.refreshToken())) + if (!jwtService.verifyToken(tokenRequestDto.refreshToken())) throw new UnAuthorizedException(TOKEN_TIME_EXPIRED_EXCEPTION); - if (!jwtService.verifyToken(tokenRequestDto.refreshToken())) + final String userId = jwtService.getUserIdInToken(tokenRequestDto.refreshToken()); + final User user = userRepository.findById(Long.parseLong(userId)).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + + if (!jwtService.compareRefreshToken(userId, tokenRequestDto.refreshToken())) throw new UnAuthorizedException(TOKEN_TIME_EXPIRED_EXCEPTION); final TokenPair tokenPair = jwtService.generateTokenPair(userId); diff --git a/src/main/java/com/moddy/server/service/designer/DesignerRegisterService.java b/src/main/java/com/moddy/server/service/designer/DesignerRegisterService.java index 4bd776b1..4f941c43 100644 --- a/src/main/java/com/moddy/server/service/designer/DesignerRegisterService.java +++ b/src/main/java/com/moddy/server/service/designer/DesignerRegisterService.java @@ -1,11 +1,28 @@ package com.moddy.server.service.designer; +import com.moddy.server.common.exception.enums.ErrorCode; +import com.moddy.server.common.exception.model.ConflictException; +import com.moddy.server.common.exception.model.NotFoundException; +import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest; +import com.moddy.server.controller.designer.dto.response.UserCreateResponse; +import com.moddy.server.domain.day_off.DayOff; import com.moddy.server.domain.day_off.repository.DayOffJpaRepository; +import com.moddy.server.domain.designer.Designer; +import com.moddy.server.domain.designer.HairShop; +import com.moddy.server.domain.designer.Portfolio; import com.moddy.server.domain.designer.repository.DesignerJpaRepository; +import com.moddy.server.domain.user.Role; import com.moddy.server.domain.user.User; +import com.moddy.server.domain.user.repository.UserRepository; import com.moddy.server.external.s3.S3Service; +import com.moddy.server.service.auth.AuthService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import static com.moddy.server.common.exception.enums.ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION; +import static com.moddy.server.common.exception.enums.ErrorCode.USER_NOT_FOUND_EXCEPTION; @Service @RequiredArgsConstructor @@ -13,10 +30,41 @@ public class DesignerRegisterService { private final DesignerJpaRepository designerJpaRepository; private final DayOffJpaRepository dayOffJpaRepository; private final S3Service s3Service; + private final AuthService authService; + private final UserRepository userRepository; + + @Transactional + public UserCreateResponse createDesigner(final Long designerId, final DesignerCreateRequest request, final MultipartFile profileImg) { + + String profileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER); + + User user = userRepository.findById(designerId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + if (designerJpaRepository.existsById(designerId)) + throw new ConflictException(ErrorCode.ALREADY_EXIST_USER_EXCEPTION); + user.update(request.name(), request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER); + HairShop hairShop = new HairShop(request.hairShop().name(), request.hairShop().address(),request.hairShop().detailAddress()); + Portfolio portfolio = new Portfolio(request.portfolio().instagramUrl(),request.portfolio().naverPlaceUrl()); + designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl()); + createDesignerDayoffs(designerId,request); + return authService.createUserToken(designerId.toString()); + } public void deleteDesignerInfo(final User designer) { dayOffJpaRepository.deleteAllByDesignerId(designer.getId()); s3Service.deleteS3Image(designer.getProfileImgUrl()); designerJpaRepository.deleteById(designer.getId()); } + + private void createDesignerDayoffs(final Long designerId, final DesignerCreateRequest request){ + Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION)); + request.dayOffs().stream() + .forEach(d -> { + DayOff dayOff = DayOff.builder() + .dayOfWeek(d) + .designer(designer) + .build(); + dayOffJpaRepository.save(dayOff); + + }); + } } diff --git a/src/main/java/com/moddy/server/service/designer/DesignerRetrieveService.java b/src/main/java/com/moddy/server/service/designer/DesignerRetrieveService.java index 2a6c677b..60fd1f03 100644 --- a/src/main/java/com/moddy/server/service/designer/DesignerRetrieveService.java +++ b/src/main/java/com/moddy/server/service/designer/DesignerRetrieveService.java @@ -3,25 +3,50 @@ import com.moddy.server.common.exception.enums.ErrorCode; import com.moddy.server.common.exception.model.NotFoundException; import com.moddy.server.controller.model.dto.DesignerInfoOpenChatDto; +import com.moddy.server.controller.model.dto.response.DesignerInfoResponse; +import com.moddy.server.domain.day_off.DayOff; +import com.moddy.server.domain.day_off.repository.DayOffJpaRepository; import com.moddy.server.domain.designer.Designer; import com.moddy.server.domain.designer.repository.DesignerJpaRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) public class DesignerRetrieveService { private final DesignerJpaRepository designerJpaRepository; - public String getDesignerName(final Long designerId){ + private final DayOffJpaRepository dayOffJpaRepository; + + public String getDesignerName(final Long designerId) { Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION)); return designer.getName(); } - public DesignerInfoOpenChatDto getDesignerOpenDetail(final Long designerId){ + public DesignerInfoOpenChatDto getDesignerOpenChatInfo(final Long designerId) { + Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION)); + return new DesignerInfoOpenChatDto(designer.getKakaoOpenChatUrl(), designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getIntroduction()); + } + + public DesignerInfoResponse getOfferDesignerInfoResponse(final Long designerId) { Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION)); - return new DesignerInfoOpenChatDto(designer.getKakaoOpenChatUrl(),designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getIntroduction()); + List dayOfWeekList = getDayOfWeekList(designerId); + + DesignerInfoResponse designerInfoResponse = new DesignerInfoResponse(designerId, designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getPortfolio().getInstagramUrl(), designer.getPortfolio().getNaverPlaceUrl(), designer.getIntroduction(), designer.getGender().getValue(), dayOfWeekList, designer.getHairShop().getAddress(), designer.getHairShop().getDetailAddress()); + return designerInfoResponse; + } + + private List getDayOfWeekList(final Long designerId) { + List dayOffList = dayOffJpaRepository.findAllByDesignerId(designerId); + List dayOfWeekList = dayOffList.stream().map(dayOff -> { + return dayOff.getDayOfWeek().getValue(); + }).collect(Collectors.toList()); + + return dayOfWeekList; } } diff --git a/src/main/java/com/moddy/server/service/designer/DesignerService.java b/src/main/java/com/moddy/server/service/designer/DesignerService.java deleted file mode 100644 index b11ec4a5..00000000 --- a/src/main/java/com/moddy/server/service/designer/DesignerService.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.moddy.server.service.designer; - -import com.moddy.server.common.exception.enums.ErrorCode; -import com.moddy.server.common.exception.model.ConflictException; -import com.moddy.server.common.exception.model.NotFoundException; -import com.moddy.server.common.util.SmsUtil; -import com.moddy.server.config.jwt.JwtService; -import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest; -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; -import com.moddy.server.domain.day_off.DayOff; -import com.moddy.server.domain.day_off.repository.DayOffJpaRepository; -import com.moddy.server.domain.designer.Designer; -import com.moddy.server.domain.designer.HairShop; -import com.moddy.server.domain.designer.Portfolio; -import com.moddy.server.domain.designer.repository.DesignerJpaRepository; -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.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; -import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository; -import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition; -import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository; -import com.moddy.server.domain.prefer_region.PreferRegion; -import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository; -import com.moddy.server.domain.user.Role; -import com.moddy.server.domain.user.User; -import com.moddy.server.domain.user.repository.UserRepository; -import com.moddy.server.external.kakao.feign.KakaoApiClient; -import com.moddy.server.external.kakao.feign.KakaoAuthApiClient; -import com.moddy.server.external.kakao.service.KakaoSocialService; -import com.moddy.server.external.s3.S3Service; -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; - -import java.io.IOException; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static com.moddy.server.common.exception.enums.ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Builder -public class DesignerService { - private final DesignerJpaRepository designerJpaRepository; - private final DayOffJpaRepository dayOffJpaRepository; - private final S3Service s3Service; - private final KakaoSocialService kakaoSocialService; - private final KakaoAuthApiClient kakaoAuthApiClient; - private final KakaoApiClient kakaoApiClient; - private final JwtService jwtService; - private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; - 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; - - @Transactional - public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest request, MultipartFile profileImg) { - - String profileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER); - - User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION)); - if (designerJpaRepository.existsById(userId)) - throw new ConflictException(ErrorCode.ALREADY_EXIST_USER_EXCEPTION); - user.update(request.name(), request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER); - - HairShop hairShop = HairShop.builder() - .name(request.hairShop().name()) - .address(request.hairShop().address()) - .detailAddress(request.hairShop().detailAddress()) - .build(); - Portfolio portfolio = Portfolio.builder() - .instagramUrl(request.portfolio().instagramUrl()) - .naverPlaceUrl(request.portfolio().naverPlaceUrl()) - .build(); - designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl()); - Designer designer = designerJpaRepository.findById(user.getId()).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION)); - request.dayOffs().stream() - .forEach(d -> { - DayOff dayOff = DayOff.builder() - .dayOfWeek(d) - .designer(designer) - .build(); - dayOffJpaRepository.save(dayOff); - - }); - return authService.createUserToken(designer.getId().toString()); - } - - - @Transactional - public void postOffer(Long userId, Long applicationId, OfferCreateRequest request) throws IOException { - Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION)); - HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); - - if (hairServiceOfferJpaRepository.existsByHairModelApplicationIdAndDesignerId(applicationId,designer.getId())) throw new ConflictException(ErrorCode.ALREADY_EXIST_OFFER_EXCEPTION); - - HairServiceOffer offer = HairServiceOffer.builder() - .model(hairModelApplication.getModel()) - .hairModelApplication(hairModelApplication) - .designer(designer) - .offerDetail(request.offerDetail()) - .isModelAgree(false) - .isClicked(false) - .build(); - hairServiceOfferJpaRepository.save(offer); - - request.preferOfferConditions().stream() - .forEach(p -> { - PreferOfferCondition preferOfferCondition = PreferOfferCondition.builder() - .offerCondition(p) - .hairServiceOffer(offer) - .build(); - preferOfferConditionJpaRepository.save(preferOfferCondition); - - }); - - final String modelName = hairModelApplication.getModel().getName(); - final String modelPhoneNumber = hairModelApplication.getModel().getPhoneNumber(); - 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 preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId); - - List preferhairStyleList = preferHairStyles.stream().map(hairStyle -> { - return hairStyle.getHairStyle().getValue(); - }).collect(Collectors.toList()); - - List hairServiceRecords = hairServiceRecordJpaRepository.findAllByHairModelApplicationId(applicationId); - hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal())); - - List preferRegions = preferRegionJpaRepository.findAllByModelId(model.getId()); - - List regionList = preferRegions.stream().map(preferregion -> { - return preferregion.getRegion().getName(); - }).collect(Collectors.toList()); - - List 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 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); - return new DownloadUrlResponseDto(preSignedUrl); - } -} diff --git a/src/main/java/com/moddy/server/service/model/ModelRegisterService.java b/src/main/java/com/moddy/server/service/model/ModelRegisterService.java index 1938a57e..4419f9f7 100644 --- a/src/main/java/com/moddy/server/service/model/ModelRegisterService.java +++ b/src/main/java/com/moddy/server/service/model/ModelRegisterService.java @@ -5,7 +5,7 @@ import com.moddy.server.common.exception.model.NotFoundException; import com.moddy.server.controller.designer.dto.response.UserCreateResponse; import com.moddy.server.controller.model.dto.request.ModelCreateRequest; -import com.moddy.server.controller.user.dto.UserUpdateDto; +import com.moddy.server.controller.user.dto.request.UserUpdateDto; import com.moddy.server.domain.model.Model; import com.moddy.server.domain.model.repository.ModelJpaRepository; import com.moddy.server.domain.prefer_region.PreferRegion; diff --git a/src/main/java/com/moddy/server/service/model/ModelRetrieveService.java b/src/main/java/com/moddy/server/service/model/ModelRetrieveService.java index c9b3201d..de799472 100644 --- a/src/main/java/com/moddy/server/service/model/ModelRetrieveService.java +++ b/src/main/java/com/moddy/server/service/model/ModelRetrieveService.java @@ -4,11 +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.controller.model.dto.response.ApplicationUserDetailResponse; import com.moddy.server.domain.model.Model; -import com.moddy.server.domain.model.ModelApplyStatus; 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 com.moddy.server.service.offer.HairServiceOfferRetrieveService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,10 +23,17 @@ public class ModelRetrieveService { private final ModelJpaRepository modelJpaRepository; private final RegionJpaRepository regionJpaRepository; + private final PreferRegionJpaRepository preferRegionJpaRepository; public ApplicationModelInfoDto getApplicationModelInfo(final Long modelId) { Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO)); - return new ApplicationModelInfoDto(model.getName(), model.getAge(), model.getGender().getValue()); + + List preferRegions = preferRegionJpaRepository.findAllByModelId(modelId); + + List 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 getRegionList() { @@ -41,4 +49,14 @@ public String getModelName(final Long modelId) { Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO)); return model.getName(); } + + public ApplicationUserDetailResponse getModelDetailInApplication(final Long modelId) { + final Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO)); + final List preferRegions = preferRegionJpaRepository.findAllByModelId(model.getId()) + .stream() + .map(p -> p.getRegion().getName()) + .toList(); + + return new ApplicationUserDetailResponse(model.getName(), model.getGender().getValue(), model.getAge(), preferRegions); + } } diff --git a/src/main/java/com/moddy/server/service/model/ModelService.java b/src/main/java/com/moddy/server/service/model/ModelService.java deleted file mode 100644 index e3731618..00000000 --- a/src/main/java/com/moddy/server/service/model/ModelService.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.moddy.server.service.model; - - -import com.moddy.server.common.exception.enums.ErrorCode; -import com.moddy.server.common.exception.model.NotFoundException; -import com.moddy.server.controller.model.dto.response.ApplicationUserDetailResponse; -import com.moddy.server.controller.model.dto.response.DesignerInfoResponse; -import com.moddy.server.controller.model.dto.response.DetailOfferResponse; -import com.moddy.server.controller.model.dto.response.StyleDetailResponse; -import com.moddy.server.domain.day_off.DayOff; -import com.moddy.server.domain.day_off.repository.DayOffJpaRepository; -import com.moddy.server.domain.designer.Designer; -import com.moddy.server.domain.designer.repository.DesignerJpaRepository; -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.model.Model; -import com.moddy.server.domain.model.repository.ModelJpaRepository; -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_offer_condition.OfferCondition; -import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition; -import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository; -import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class ModelService { - - private final ModelJpaRepository modelJpaRepository; - private final DesignerJpaRepository designerJpaRepository; - private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; - private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository; - private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository; - private final DayOffJpaRepository dayOffJpaRepository; - private final PreferHairStyleJpaRepository preferHairStyleJpaRepository; - private final PreferRegionJpaRepository preferRegionJpaRepository; - - - @Transactional - public DetailOfferResponse getOfferDetail(Long userId, Long offerId) { - - HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION)); - - DesignerInfoResponse designerInfoResponseList = getDesignerInfoResponse(hairServiceOffer, userId, offerId); - StyleDetailResponse styleDetailResponse = getStyleDetailResponse(hairServiceOffer, userId, offerId); - handleOfferClickStatus(hairServiceOffer); - - return new DetailOfferResponse(designerInfoResponseList, styleDetailResponse); - } - - @Transactional - public void updateOfferAgreeStatus(Long offerId) { - HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION)); - - hairServiceOffer.setIsModelAgree(true); - } - - public ApplicationUserDetailResponse getUserDetailInApplication(final Long userId) { - Model model = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO)); - List preferRegions = preferRegionJpaRepository.findAllByModelId(model.getId()) - .stream() - .map(p -> p.getRegion().getName()) - .toList(); - - return new ApplicationUserDetailResponse(model.getName(), model.getGender().getValue(), model.getAge(), preferRegions); - } - - private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId) { - - Designer designer = designerJpaRepository.findById(hairServiceOffer.getDesigner().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION)); - - List dayOffList = dayOffJpaRepository.findAllByDesignerId(designer.getId()); - List dayOfWeekList = dayOffList.stream().map(dayOff -> { - return dayOff.getDayOfWeek().getValue(); - }).collect(Collectors.toList()); - - DesignerInfoResponse designerInfoResponse = new DesignerInfoResponse(designer.getProfileImgUrl(), designer.getHairShop().getName(), designer.getName(), designer.getPortfolio().getInstagramUrl(), designer.getPortfolio().getNaverPlaceUrl(), designer.getIntroduction(), designer.getGender().getValue(), dayOfWeekList, designer.getHairShop().getAddress(), designer.getHairShop().getDetailAddress()); - - return designerInfoResponse; - - } - - private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId) { - - HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(hairServiceOffer.getHairModelApplication().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); - - List preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(hairServiceOffer.getHairModelApplication().getId()); - List hairStyleList = preferHairStyles.stream().map(hairStyle -> { - return hairStyle.getHairStyle().getValue(); - }).collect(Collectors.toList()); - - List preferOfferConditionList = preferOfferConditionJpaRepository.findAllByHairServiceOfferId(offerId); - List offerConditionList = preferOfferConditionList.stream().map(PreferOfferCondition::getOfferCondition).collect(Collectors.toList()); - List preferOfferConditionBooleanList = Arrays.stream(OfferCondition.values()).map(condition -> { - if (offerConditionList.contains(condition)) return true; - else return false; - }).collect(Collectors.toList()); - - StyleDetailResponse styleDetailResponse = new StyleDetailResponse(hairServiceOffer.getIsModelAgree(), hairStyleList, hairServiceOffer.getOfferDetail(), hairModelApplication.getHairDetail(), preferOfferConditionBooleanList); - - return styleDetailResponse; - } - - private void handleOfferClickStatus(HairServiceOffer hairServiceOffer) { - - if (!hairServiceOffer.getIsClicked()) { - hairServiceOffer.updateClickStatus(); - } - } - - - -} diff --git a/src/main/java/com/moddy/server/service/offer/HairServiceOfferRegisterService.java b/src/main/java/com/moddy/server/service/offer/HairServiceOfferRegisterService.java index 392e7529..ce50612c 100644 --- a/src/main/java/com/moddy/server/service/offer/HairServiceOfferRegisterService.java +++ b/src/main/java/com/moddy/server/service/offer/HairServiceOfferRegisterService.java @@ -1,18 +1,36 @@ package com.moddy.server.service.offer; +import com.moddy.server.common.exception.enums.ErrorCode; +import com.moddy.server.common.exception.model.ConflictException; +import com.moddy.server.common.exception.model.NotFoundException; +import com.moddy.server.common.util.SmsUtil; +import com.moddy.server.controller.designer.dto.request.OfferCreateRequest; +import com.moddy.server.domain.designer.Designer; +import com.moddy.server.domain.designer.repository.DesignerJpaRepository; +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.model.Model; +import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition; import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.util.List; +import static com.moddy.server.common.exception.enums.ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION; + @Service @RequiredArgsConstructor public class HairServiceOfferRegisterService { private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository; private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository; + private final DesignerJpaRepository designerJpaRepository; + private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; + private final SmsUtil smsUtil; public void deleteModelHairServiceOfferInfos(final Long modelId) { final List hairServiceOffers = hairServiceOfferJpaRepository.findAllByModelId(modelId); @@ -29,4 +47,37 @@ public void deleteDesignerHairServiceOfferInfos(final Long designerId) { hairServiceOfferJpaRepository.deleteById(hairServiceOffer.getId()); }); } + + @Transactional + public void postOffer(final Long designerId, final Long applicationId, final OfferCreateRequest request) throws IOException { + Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION)); + HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION)); + Model model = hairModelApplication.getModel(); + if (hairServiceOfferJpaRepository.existsByHairModelApplicationIdAndDesignerId(applicationId,designer.getId())) throw new ConflictException(ErrorCode.ALREADY_EXIST_OFFER_EXCEPTION); + + HairServiceOffer offer = new HairServiceOffer(hairModelApplication,model,designer, request.offerDetail(), false,false); + hairServiceOfferJpaRepository.save(offer); + + request.preferOfferConditions().stream() + .forEach(p -> { + PreferOfferCondition preferOfferCondition = new PreferOfferCondition(offer,p); + preferOfferConditionJpaRepository.save(preferOfferCondition); + + }); + + final String modelName = model.getName(); + final String modelPhoneNumber = model.getPhoneNumber(); + sendSms(smsUtil, modelPhoneNumber,modelName); + } + + public void updateOfferAgreeStatus(final Long offerId) { + HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION)); + + hairServiceOffer.agreeOfferToModel(); + } + + private void sendSms(final SmsUtil smsUtil, final String modelPhoneNumber, final String modelName) throws IOException { + smsUtil.sendOfferToModel(modelPhoneNumber, modelName); + } + } diff --git a/src/main/java/com/moddy/server/service/offer/HairServiceOfferRetrieveService.java b/src/main/java/com/moddy/server/service/offer/HairServiceOfferRetrieveService.java index 74caf175..623c6476 100644 --- a/src/main/java/com/moddy/server/service/offer/HairServiceOfferRetrieveService.java +++ b/src/main/java/com/moddy/server/service/offer/HairServiceOfferRetrieveService.java @@ -2,15 +2,17 @@ import com.moddy.server.common.exception.enums.ErrorCode; import com.moddy.server.common.exception.model.NotFoundException; -import com.moddy.server.controller.model.dto.DesignerInfoOpenChatDto; -import com.moddy.server.controller.model.dto.response.DesignerInfoOpenChatResponse; +import com.moddy.server.controller.application.dto.response.ApplicationInfoDetailResponse; +import com.moddy.server.controller.model.dto.response.DesignerInfoResponse; import com.moddy.server.controller.model.dto.response.OfferResponse; -import com.moddy.server.controller.model.dto.response.OpenChatResponse; +import com.moddy.server.controller.offer.dto.response.DetailOfferResponse; import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse; +import com.moddy.server.controller.offer.dto.response.OfferInfoResponse; import com.moddy.server.domain.designer.Designer; import com.moddy.server.domain.hair_service_offer.HairServiceOffer; import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository; import com.moddy.server.domain.model.ModelApplyStatus; +import com.moddy.server.domain.prefer_offer_condition.OfferCondition; import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition; import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository; import com.moddy.server.service.application.HairModelApplicationRetrieveService; @@ -24,7 +26,9 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Service @@ -38,19 +42,41 @@ public class HairServiceOfferRetrieveService { private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService; private final ModelRetrieveService modelRetrieveService; - public OpenChatResponse getOpenChatInfo(final Long userId, final Long offerId) { - HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUNT_OFFER_EXCEPTION)); - Long designerId = hairServiceOffer.getDesigner().getId(); - Long applicationId = hairServiceOffer.getHairModelApplication().getId(); + public boolean getIsSendStatus(final Long applicationId, final Long userId) { + Optional offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndDesignerId(applicationId, userId); + return offer.isPresent(); + } + + @Transactional + public DetailOfferResponse getOfferDetail(final Long offerId) { + + HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION)); + + DesignerInfoResponse designerInfoResponse = designerRetrieveService.getOfferDesignerInfoResponse(hairServiceOffer.getDesigner().getId()); + ApplicationInfoDetailResponse applicationInfoDetailResponse = hairModelApplicationRetrieveService.getOfferApplicationInfo(hairServiceOffer.getHairModelApplication().getId()); + OfferInfoResponse offerInfoResponse = getOfferDetailResponse(hairServiceOffer, offerId); + + handleOfferClickStatus(hairServiceOffer); - DesignerInfoOpenChatDto openChatDto = designerRetrieveService.getDesignerOpenDetail(designerId); + return new DetailOfferResponse(designerInfoResponse, applicationInfoDetailResponse, offerInfoResponse); + } + + private OfferInfoResponse getOfferDetailResponse(final HairServiceOffer hairServiceOffer, final Long offerId) { - DesignerInfoOpenChatResponse response = new DesignerInfoOpenChatResponse(openChatDto.imgUrl(), openChatDto.shopName(), openChatDto.name(), openChatDto.introduction()); + List preferOfferConditionList = preferOfferConditionJpaRepository.findAllByHairServiceOfferId(offerId); + List offerConditionList = preferOfferConditionList.stream().map(PreferOfferCondition::getOfferCondition).collect(Collectors.toList()); + List preferOfferConditionBooleanList = Arrays.stream(OfferCondition.values()).map(offerConditionList::contains).collect(Collectors.toList()); - OpenChatResponse openChatResponse = new OpenChatResponse(hairModelApplicationRetrieveService.getApplicationCaptureUrl(applicationId), openChatDto.kakaoUrl(), response); + OfferInfoResponse offerInfoResponse = OfferInfoResponse + .builder() + .offerId(hairServiceOffer.getId()) + .isAgree(hairServiceOffer.isModelAgree()) + .designerOfferDetail(hairServiceOffer.getOfferDetail()) + .preferOfferConditions(preferOfferConditionBooleanList) + .build(); - return openChatResponse; + return offerInfoResponse; } public ModelMainOfferResponse getModelMainOfferInfo(final Long modelId, final int page, final int size) { @@ -66,6 +92,12 @@ public ModelMainOfferResponse getModelMainOfferInfo(final Long modelId, final in return new ModelMainOfferResponse(page, size, totalElements, modelApplyStatus, modelName, getModelMainOfferList(offerPage)); } + private void handleOfferClickStatus(final HairServiceOffer hairServiceOffer) { + if (!hairServiceOffer.isClicked()) { + hairServiceOffer.updateClickStatus(); + } + } + private ModelApplyStatus calModelApplyAndOfferStatus(final Long modelId) { boolean applyStatus = hairModelApplicationRetrieveService.fetchModelApplyStatus(modelId); boolean offerStatus = hairServiceOfferJpaRepository.existsByModelId(modelId); @@ -84,7 +116,7 @@ private List getModelMainOfferList(final Page o return offerCondition.getOfferCondition().getValue(); }).collect(Collectors.toList()); - OfferResponse offerResponse = new OfferResponse(offer.getId(), designer.getProfileImgUrl(), designer.getName(), designer.getHairShop().getName(), offerConditionTop2List, offer.getIsClicked()); + OfferResponse offerResponse = new OfferResponse(offer.getId(), designer.getProfileImgUrl(), designer.getName(), designer.getHairShop().getName(), offerConditionTop2List, offer.isClicked()); return offerResponse; }).collect(Collectors.toList());