Skip to content

Commit

Permalink
Merge pull request #225 from TEAM-MODDY/refactor/#224
Browse files Browse the repository at this point in the history
#224 [refactor]  디자이너 회원가입 service 분리
  • Loading branch information
pkl0912 authored Feb 7, 2024
2 parents edbd217 + 37f5c57 commit cfdb1ac
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.designer.dto.response.ApplicationDetailInfoResponse;
import com.moddy.server.controller.designer.dto.response.ApplicationInfoResponse;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.controller.designer.dto.response.ModelInfoResponse;
import com.moddy.server.controller.model.dto.ApplicationDto;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
Expand All @@ -29,6 +30,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -41,6 +43,7 @@ public class ApplicationController {
private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;
private final ModelRetrieveService modelRetrieveService;
private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.")
@ApiResponses({
Expand All @@ -59,6 +62,21 @@ public SuccessNonDataResponse submitModelApplication(
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}
@Tag(name = "DesignerController")
@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "디자이너 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = DesignerMainResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping(value = "/designer")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
@Parameter(hidden = true) @UserId Long designerId,
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, hairModelApplicationRetrieveService.getDesignerMainInfo(designerId, page, size));
}
@Tag(name = "DesignerController")
@Operation(summary = "[JWT] 모델 지원서 상세 조회", description = "모델 지원서 상세 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/moddy/server/controller/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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 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;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class AuthController {

private static final String ORIGIN = "origin";
private final AuthService authService;
private final DesignerService designerService;
private final DesignerRegisterService designerRegisterService;


@Operation(summary = "[KAKAO CODE] 로그인 API")
Expand All @@ -69,20 +69,6 @@ public SuccessResponse<LoginResponseDto> 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<UserCreateResponse> 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 = "전화번호 인증 요청 성공입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
import com.moddy.server.common.dto.ErrorResponse;
import com.moddy.server.common.dto.SuccessNonDataResponse;
import com.moddy.server.common.dto.SuccessResponse;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.enums.SuccessCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.request.OfferCreateRequest;
import com.moddy.server.controller.designer.dto.request.OfferImageUrlRequestDto;
import com.moddy.server.controller.designer.dto.response.ApplicationDetailInfoResponse;
import com.moddy.server.controller.designer.dto.response.ApplicationInfoResponse;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.controller.designer.dto.response.DownloadUrlResponseDto;
import com.moddy.server.controller.designer.dto.response.ModelInfoResponse;
import com.moddy.server.controller.model.dto.ApplicationDto;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.service.application.HairModelApplicationRetrieveService;
import com.moddy.server.service.designer.DesignerRegisterService;
import com.moddy.server.service.designer.DesignerService;
import com.moddy.server.service.model.ModelRetrieveService;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -31,13 +24,14 @@
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.http.MediaType;
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.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

Expand All @@ -50,21 +44,22 @@
public class DesignerController {

private final DesignerService designerService;
private final DesignerRegisterService designerRegisterService;
private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;

@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@Tag(name = "Auth Controller", description = "로그인 및 회원 가입 관련 API 입니다.")
@Operation(summary = "[JWT] 디자이너 회원가입 API", description = "디자이너 회원가입 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "디자이너 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = DesignerMainResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "200", description = "디자이너 회원가입 성공", content = @Content(schema = @Schema(implementation = UserCreateResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
@PostMapping(value = "/auth/signup/designer", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
SuccessResponse<UserCreateResponse> createDesigner(
@Parameter(hidden = true) @UserId Long designerId,
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, hairModelApplicationRetrieveService.getDesignerMainInfo(designerId, page, size));
@RequestPart(value = "profileImg", required = false) MultipartFile profileImg,
@Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerRegisterService.createDesigner(designerId, designerInfo, profileImg));
}

@Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,6 @@ public SuccessResponse<UserCreateResponse> createModel(
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelRegisterService.createModel(userId, modelCreateRequest));
}

@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<OpenChatResponse> 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] 모델 지원서 최종 확인 시 유저 정보 조회 API", description = "[모델 뷰] 모델 지원서 최종 확인 시 유저 정보 조회 API 입니다.")
@ApiResponses({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.response.OpenChatResponse;
import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse;
import com.moddy.server.controller.offer.response.DetailOfferResponse;
import com.moddy.server.service.offer.HairServiceOfferRegisterService;
Expand All @@ -31,6 +32,21 @@ public class OfferController {
private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;
private final HairServiceOfferRegisterService hairServiceOfferRegisterService;

@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<OpenChatResponse> 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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.*;

@Embeddable
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Builder
@ToString
public class Portfolio {
@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,70 @@
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
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);

});
}
}
Loading

0 comments on commit cfdb1ac

Please sign in to comment.