-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 유저 정보 등록 API 구현 #72
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd23fda
[feat] 유저 정보 등록 관련 Dto 구현
seung-in-Yoo d146578
[feat] 유저 엔티티에 장애 유형 및 이동 보조 수단 필드 추가, 정보 update를 위한 setter 추가
seung-in-Yoo 61bf2e2
[feat] 유저 정보 등록 관련 ErrorCase 추가
seung-in-Yoo 24c3d03
[feat] 유저 정보 등록 관련 서비스 로직 구현
seung-in-Yoo d8e8ece
[feat] 유저 정보 등록 관련 컨트롤러 로직 구현
seung-in-Yoo de40911
[fix] 회원가입 로직 변경에 따른 로그인 요청 필드 변경
seung-in-Yoo de51266
[reafactor] 코드리뷰 반영하여 리팩토링 완료
seung-in-Yoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/wayble/server/user/dto/UserInfoRegisterRequestDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.wayble.server.user.dto; | ||
|
|
||
|
|
||
| import com.wayble.server.user.entity.Gender; | ||
| import com.wayble.server.user.entity.UserType; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class UserInfoRegisterRequestDto { | ||
| @NotBlank(message = "닉네임은 필수입니다.") | ||
| @Size(max = 8, message = "닉네임은 8자 이하여야 합니다.") | ||
| private String nickname; | ||
|
|
||
| @NotBlank(message = "생년월일은 필수입니다.") | ||
| private String birthDate; // YYYY-MM-DD | ||
|
|
||
| @NotNull(message = "성별은 필수입니다.") | ||
| private Gender gender; | ||
|
|
||
| @NotNull(message = "유저 타입은 필수입니다.") | ||
| private UserType userType; | ||
|
|
||
| private String disabilityType; // 장애 유형, (userType == DISABLED만 값 존재) | ||
| private String mobilityAid; // 이동보조수단, (userType == DISABLED만 값 존재) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/wayble/server/user/service/UserInfoService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.wayble.server.user.service; | ||
|
|
||
|
|
||
| import com.wayble.server.common.exception.ApplicationException; | ||
| import com.wayble.server.user.dto.UserInfoRegisterRequestDto; | ||
| import com.wayble.server.user.entity.User; | ||
| import com.wayble.server.user.entity.UserType; | ||
| import com.wayble.server.user.exception.UserErrorCase; | ||
| import com.wayble.server.user.repository.UserRepository; | ||
| import jakarta.transaction.Transactional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeParseException; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserInfoService { | ||
| private final UserRepository userRepository; | ||
|
|
||
| @Transactional | ||
| public void registerUserInfo(Long userId, UserInfoRegisterRequestDto dto) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND)); | ||
|
|
||
| // 이미 등록된 정보가 있으면 에러 처리 | ||
| if (user.getNickname() != null) { | ||
| throw new ApplicationException(UserErrorCase.USER_INFO_ALREADY_EXISTS); | ||
| } | ||
|
|
||
| user.setNickname(dto.getNickname()); | ||
| try { | ||
| user.setBirthDate(LocalDate.parse(dto.getBirthDate())); | ||
| } catch (DateTimeParseException e) { | ||
| throw new ApplicationException(UserErrorCase.INVALID_BIRTH_DATE); | ||
| } | ||
| user.setGender(dto.getGender()); | ||
| user.setUserType(dto.getUserType()); | ||
|
|
||
| if (dto.getUserType() == UserType.DISABLED) { | ||
| // 장애 유형,이동보조수단 설정 | ||
| user.setDisabilityType(dto.getDisabilityType()); | ||
| user.setMobilityAid(dto.getMobilityAid()); | ||
| } else { | ||
| user.setDisabilityType(null); | ||
| user.setMobilityAid(null); | ||
| } | ||
|
|
||
| userRepository.save(user); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dto의 userType은 String이고 UserType.DISABLED는 구조체값인데 둘이 == 비교 연산이 가능한지 궁금합니다..!
둘의 타입을 다르게 할 거라면 UserType.DISABLED.name()로 String 값 구한 뒤, equals() 연산하는게 맞을 것 같아요..!
(제가 잘못 알고 있을 수도 있습니다!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 UserInfoRegisterRequestDto의 userType 필드는 UserType에서 enum 타입이라서 == 비교를 써도 되는거 같다고 생각했는데 혹시 제가 잘못 생각한거일까요!? 추가로 궁금해서 찾아봤더니 만약에 프론트에서 "DISABLED" 같은 String 값이 넘어온다면, 컨트롤러에서 UserType userType으로 받으면 Spring이 알아서 변환해준다고 하는데 그렇다면 이 코드를 고쳐야하는지 그대로 둬도 되는지도 궁금합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 제가 잘못봤네요! register dto에서 disabilityType이 String인데, userType이 String으로 저장된 걸로 잘못 봤어요 ㅎㅎ