Skip to content

Commit

Permalink
Merge pull request #121 from TEAM-MODDY/fix/#117
Browse files Browse the repository at this point in the history
#117 [fix] 모델 회원가입 로직 변경
  • Loading branch information
hellozo0 authored Jan 16, 2024
2 parents a18e0b8 + 8a58519 commit 1f8bbad
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 47 deletions.
23 changes: 10 additions & 13 deletions src/main/java/com/moddy/server/controller/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {

private static final String ORIGIN = "origin";
private final AuthService authService;
private final DesignerService designerService;
Expand All @@ -62,8 +63,7 @@ public class AuthController {
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<LoginResponseDto> login(
@Parameter(hidden = true) @KakaoCode String kakaoCode,
@Parameter(hidden = true) HttpServletRequest request
) {
@Parameter(hidden = true) HttpServletRequest request) {
return SuccessResponse.success(SOCIAL_LOGIN_SUCCESS, authService.login(request.getHeader(ORIGIN), kakaoCode));
}

Expand All @@ -87,26 +87,23 @@ public SuccessResponse<List<RegionResponse>> getRegionList() {
SuccessResponse<UserCreateResponse> createDesigner(
@Parameter(hidden = true) @UserId Long userId,
@RequestPart("profileImg") MultipartFile profileImg,
@RequestPart("designerInfo") DesignerCreateRequest designerInfo
) {
@RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(userId, designerInfo, profileImg));
}

@Operation(summary = "[KAKAO CODE] 모델 회원가입 API", description = "모델 회원가입 API입니다.")
@Operation(summary = "[JWT] 모델 회원가입 API", description = "모델 회원가입 API입니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "모델 회원가입 성공"),
@ApiResponse(responseCode = "400", description = "유효하지 않은 카카오 코드를 입력했습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.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(value = "/signup/model")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<UserCreateResponse> createModel(
@Parameter(hidden = true) @KakaoCode String kakaoCode,
@Parameter(hidden = true) HttpServletRequest request,
@RequestBody ModelCreateRequest modelCreateRequest
) {
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelService.createModel(request.getHeader(ORIGIN), kakaoCode, modelCreateRequest));
@Parameter(hidden = true) @UserId Long userId,
@RequestBody ModelCreateRequest modelCreateRequest) {
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelService.createModel(userId, modelCreateRequest));
}

@Operation(summary = "[SMS 기능 미완성] 인증번호 요청 API", description = "인증번호 요청 API입니다.")
Expand All @@ -129,8 +126,7 @@ public SuccessNonDataResponse sendVerificationCodeMessageToUser(@RequestBody Pho
responseCode = "400",
description = "1. 인증번호가 일치하지 않습니다."
+ "2. 만료된 인증 코드입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
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)))
})
Expand All @@ -153,4 +149,5 @@ public SuccessNonDataResponse logout(@UserId Long userId) {
authService.logout(userId);
return SuccessNonDataResponse.success(LOGOUT_SUCCESS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
@Tag(name = "DesignerController")
@RequiredArgsConstructor
public class DesignerController {

private final DesignerService designerService;

@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "디자이너 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = DesignerMainResponse.class))),
Expand All @@ -37,8 +39,7 @@ public class DesignerController {
public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size
){
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, designerService.getDesignerMainInfo(userId, page, size));
}

Expand All @@ -54,8 +55,7 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
public SuccessNonDataResponse offerCreateRequest(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId,
@RequestBody OfferCreateRequest offerCreateRequest
) {
@RequestBody OfferCreateRequest offerCreateRequest) {
designerService.postOffer(userId, applicationId, offerCreateRequest);
return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS);
}
Expand All @@ -71,8 +71,8 @@ public SuccessNonDataResponse offerCreateRequest(
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ApplicationDetailInfoResponse> getApplicationDetailInfo(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId
){
@PathVariable(value = "applicationId") Long applicationId) {
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, designerService.getApplicationDetail(userId, applicationId));
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.moddy.server.controller.designer.dto.response;

import com.moddy.server.domain.prefer_hair_style.HairStyle;
import com.moddy.server.domain.user.Gender;

import java.util.List;

public record HairModelApplicationResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ModelController {
public SuccessResponse<ModelMainResponse> getModelMainInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size){
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_MAIN_INFO_SUCCESS, modelService.getModelMainInfo(userId, page, size));
}

Expand All @@ -60,7 +60,7 @@ public SuccessResponse<ModelMainResponse> getModelMainInfo(
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<DetailOfferResponse> getModelDetailOfferInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId){
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, modelService.getOfferDetail(userId, offerId));
}

Expand Down Expand Up @@ -89,10 +89,9 @@ public SuccessResponse<OpenChatResponse> getOpenChat(
@SecurityRequirement(name = "JWT Auth")
public SuccessNonDataResponse acceptOffer(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId){
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
modelService.updateOfferAgreeStatus(offerId);
return SuccessNonDataResponse.success(SuccessCode.OFFER_ACCEPT_SUCCESS);

}

@Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.")
Expand All @@ -105,8 +104,7 @@ public SuccessNonDataResponse acceptOffer(
@PostMapping(value = "/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public SuccessNonDataResponse submitModelApplication(
@Parameter(hidden = true) @UserId Long userId,
@ModelAttribute ModelApplicationRequest request
) {
@ModelAttribute ModelApplicationRequest request) {
modelService.postApplication(userId, request);
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import java.util.Optional;

public interface DesignerJpaRepository extends JpaRepository<Designer, Long> {

@Modifying(clearAutomatically = true)
@Query(value = "insert into Designer (id, hair_shop_address, hair_shop_detail_address, hair_shop_name, instagram_url, naver_place_url, introduction, kakao_open_chat_url) VALUES (:id, :hairShopAddress, :hairShopDetailAddress, :hairShopName, :instagramUrl, :naverPlaceUrl, :introduction, :kakaoOpenChatUrl)", nativeQuery = true)
void designerRegister(@Param("id") Long id, @Param("hairShopAddress") String hairShopAddress, @Param("hairShopDetailAddress") String hairShopDetailAddress, @Param("hairShopName") String hairShopName, @Param("instagramUrl") String instagramUrl, @Param("naverPlaceUrl") String naverPlaceUrl, @Param("introduction") String introduction, @Param("kakaoOpenChatUrl") String kakaoOpenChatUrl);

Optional<Designer> findById(Long userId);
}
5 changes: 5 additions & 0 deletions src/main/java/com/moddy/server/domain/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.moddy.server.domain.user.User;
import jakarta.persistence.Entity;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@Getter
Expand All @@ -13,5 +15,8 @@
@AllArgsConstructor
@SuperBuilder
public class Model extends User {

@NotNull
private String year;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import com.moddy.server.domain.model.Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ModelJpaRepository extends JpaRepository<Model, Long> {
Optional<Model> findById(Long userId);

@Modifying(clearAutomatically = true)
@Query(value = "insert into Model (id, year) VALUES (:id, :year)", nativeQuery = true)
void modelRegister(@Param("id") Long id, @Param("year") String year);

}

3 changes: 2 additions & 1 deletion src/main/java/com/moddy/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class User extends BaseTimeEntity {

@Enumerated(EnumType.STRING)
private Role role;
public Integer getAge(String year) {

public Integer getAge(String year){
LocalDateTime currentDateTime = LocalDateTime.now();
Integer age = currentDateTime.getYear() - Integer.parseInt(year) + 1;
return age;
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/com/moddy/server/service/model/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.moddy.server.domain.region.repository.RegionJpaRepository;
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.service.KakaoSocialService;
import com.moddy.server.external.s3.S3Service;
import com.moddy.server.service.auth.AuthService;
Expand All @@ -62,6 +63,7 @@
public class ModelService {

private final ModelJpaRepository modelJpaRepository;
private final UserRepository userRepository;
private final DesignerJpaRepository designerJpaRepository;
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
Expand All @@ -71,7 +73,6 @@ public class ModelService {
private final PreferRegionJpaRepository preferRegionJpaRepository;
private final RegionJpaRepository regionJpaRepository;
private final HairServiceRecordJpaRepository hairServiceRecordJpaRepository;
private final KakaoSocialService kakaoSocialService;
private final AuthService authService;
private final S3Service s3Service;

Expand Down Expand Up @@ -127,22 +128,13 @@ public ModelMainResponse getModelMainInfo(Long userId, int page, int size) {
}

@Transactional
public UserCreateResponse createModel(String baseUrl, String code, ModelCreateRequest request) {

String kakaoId = kakaoSocialService.getIdFromKakao(baseUrl, code);

Model model = Model.builder()
.name(request.name())
.year(request.year())
.gender(request.gender())
.phoneNumber(request.phoneNumber())
.isMarketingAgree(request.isMarketingAgree())
.profileImgUrl(s3Service.getDefaultProfileImageUrl())
.kakaoId(kakaoId)
.role(Role.MODEL)
.build();
public UserCreateResponse createModel(long userId, ModelCreateRequest request) {

User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));
user.update(request.name(),request.gender(), request.phoneNumber(), request.isMarketingAgree(), s3Service.getDefaultProfileImageUrl(), Role.MODEL);

modelJpaRepository.save(model);
modelJpaRepository.modelRegister(userId, request.year());
Model model = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.MODEL_NOT_FOUND_EXCEPTION));

request.preferRegions().stream().forEach(preferRegionId -> {
Region region = regionJpaRepository.findById(preferRegionId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_REGION_EXCEPTION));
Expand Down

0 comments on commit 1f8bbad

Please sign in to comment.