Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#117 [fix] 모델 회원가입 로직 변경 #121

Merged
merged 15 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,20 @@ SuccessResponse<UserCreateResponse> createDesigner(
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(servletRequest.getHeader(ORIGIN), kakaoCode, 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 = "400", description = "인증오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2
access token 관련 오류이기 때문에 400이 아닌 401 에러인 것 같습니다..!

@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,
@Parameter(hidden = true) @UserId Long userId,
@RequestBody ModelCreateRequest modelCreateRequest
) {
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelService.createModel(request.getHeader(ORIGIN), kakaoCode, modelCreateRequest));
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelService.createModel(userId, modelCreateRequest));
}

@Operation(summary = "[SMS 기능 미완성] 인증번호 요청 API", description = "인증번호 요청 API입니다.")
Expand Down
6 changes: 6 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,16 +2,22 @@

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
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class Model extends User {

@NotNull
private String year;

}
8 changes: 1 addition & 7 deletions src/main/java/com/moddy/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@Entity
@Getter
@Setter
@SuperBuilder
@Inheritance(strategy = InheritanceType.JOINED)
@NoArgsConstructor
Expand All @@ -24,27 +25,20 @@ public class User extends BaseTimeEntity {
@NotNull
private String kakaoId;

@NotNull
private String name;

@Enumerated(value = EnumType.STRING)
@NotNull
private Gender gender;

@NotNull
private String phoneNumber;

@NotNull
private Boolean isMarketingAgree;

@NotNull
private String profileImgUrl;

@NotNull
@Enumerated(EnumType.STRING)
private Role role;


public Integer getAge(String year){
LocalDateTime currentDateTime = LocalDateTime.now();
Integer age = currentDateTime.getYear() - Integer.parseInt(year) + 1 ;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/moddy/server/service/model/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
import com.moddy.server.domain.user.Gender;
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;
import lombok.RequiredArgsConstructor;
import org.hibernate.Length;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
Expand All @@ -60,6 +62,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 @@ -69,7 +72,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 @@ -240,20 +242,19 @@ public void updateOfferAgreeStatus(Long offerId){
}

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

String kakaoId = kakaoSocialService.getIdFromKakao(baseUrl, code);
User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

Model model = Model.builder()
.kakaoId(user.getKakaoId())
.name(request.name())
.year(request.year())
.gender(request.gender())
.phoneNumber(request.phoneNumber())
.isMarketingAgree(request.isMarketingAgree())
.profileImgUrl(s3Service.getDefaultProfileImageUrl())
.kakaoId(kakaoId)
.role(Role.MODEL)
.build();
.year(request.year()).build();

modelJpaRepository.save(model);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2
현재 로직은 새로운 model을 하나 더 만드는 로직입니다.

find by id를 통해 기존 user를 불러온 뒤, 해당 setter를 통해 해당 user의 정보를 update 한 뒤,
Model 객체를 builder를 통해 만들어서 save 하도록 로직을 수정해야 할 것 같습니다.

Copy link
Member Author

@hellozo0 hellozo0 Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KWY0218

Builder를 통해 Model 객체를 만들어서 저장을 하게 되면 기존에 만들어진 userId에 대한 정보를 이어받아서 Model만 생성되는 것이 아니라 새로운 User 정보도 생성된다는 문제가 있습니다! 기존의 User가 1번 이였다면, 2번 유저를 가르키고 있는 Model이 만들어 지는데 혹시 이러한 방법을 하는게 맞을까요..?

-- 제 코드가 문제가 있을 수도 있어서 방금 수정 코드 다시 올려두었습니다!

User 2 번이 생성안되고 Model 객체가 User 1을 참조할 수 있는 방법 좀 더 생각해서 PR 올릴께욤!


Expand Down