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

[COZY-411] feat : 사용자 관련 validation 고도화 #198

Merged
merged 8 commits into from
Dec 3, 2024

Conversation

genius00hwan
Copy link
Contributor

⚒️develop의 최신 커밋을 pull 받았나요?

#️⃣ 작업 내용

어떤 기능을 구현했나요?
기존 기능에서 어떤 점이 달라졌나요?
자세한 로직이 필요하다면 함께 적어주세요!
코드에 대한 설명이라면, 코맨트를 통해서 어떤 부분이 어떤 코드인지 설명해주세요!

동작 확인

invalidSiginRequest
clientId, socialType validation

invalidNickname
InvalidNicknameResponse
nickname validation

InvalidGender
gender validation

💬 리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
고민사항도 적어주세요.

Copy link

github-actions bot commented Dec 1, 2024

리뷰해드려요~

ClientIdMaker.java - Review

  • 변경사항: ':' 기호로 클라이언트 아이디를 만드는 방식이 변경되었습니다.

Member.java - Review

  • 추가: 'persona' 필드에 대한 범위 제한이 추가되었습니다.

MemberController.java - Review

  • 제거: 'BindingResult' 파라미터가 제거되었습니다.
  • 추가: 'Nickname' 필드에 대한 길이 제한이 추가되었습니다.
  • 추가: 'persona' 필드에 대한 범위 제한이 추가되었습니다.

SignInRequestDTO.java - Review

  • 추가: 'SocialType' 필드에 대한 유효성 검사가 추가되었습니다.

SignUpRequestDTO.java - Review

  • 제거: 'max' 및 'min' 제한 정보가 제거되었습니다.
  • 추가: 'nickname' 필드에 대한 길이 제한이 추가되었습니다.
  • 추가: 'gender' 필드에 대한 유효성 검사가 추가되었습니다.
  • 추가: 'birthday' 필드에 대한 날짜 형식 제한이 추가되었습니다.
  • 추가: 'persona' 필드에 대한 범위 제한이 추가되었습니다.

Gender.java - Review

  • 제거: 'ErrorStatus' 및 'GeneralException' 클래스가 제거되었습니다.

SocialType.java - Review

  • 제거: 'ErrorStatus' 및 'GeneralException' 클래스가 제거되었습니다.

MemberCommandService.java - Review

  • 제거: 'isValidNickName' 메서드가 제거되었습니다.

MemberQueryService.java - Review

  • 제거: 'isValidNickName' 메서드가 제거되었습니다.
  • 추가: 'isValidNickName' 메서드에 대한 예외 처리가 추가되었습니다.

MessageSourceConfig.java - Review

  • 추가: 'MessageSource' 구성 파일이 추가되었습니다.

ErrorStatus.java - Review

  • 추가: '_INVALID_NICKNAME_PATTERN' 및 '_INVALID_NICKNAME_LENGTH' 코드가 추가되었습니다.

EnumValidator.java - Review

  • 변경: 'equals' 메서드에서 'equalsIgnoreCase' 메서드로 변경되었습니다.

EnumValue.java - Review

  • 추가: 'getValue' 메서드가 추가되었습니다.

Copy link

github-actions bot commented Dec 1, 2024

리뷰해드려요~

ClientIdMaker.java - Review

  • Changed clientId = "12345@KAKAO" to clientId = "12345:KAKAO"

Member.java - Review

  • Added @Range(min = 1, max = 16) annotation to persona field

MemberController.java - Review

  • Changed @Max(value = 16) and @Min(value = 1) annotations to @Range(min = 1, max = 16) annotation for persona parameter
  • Added @NotEmpty and @NotNull annotations to nickname parameter
  • Added @NotEmpty and @NotNull annotations to majorName parameter

SignInRequestDTO.java - Review

  • Added @NotEmpty and @NotNull annotations to clientId field
  • Added @NotEmpty and @NotNull annotations to socialType field

SignUpRequestDTO.java - Review

  • Added @NotEmpty and @NotNull annotations to nickname field
  • Added @NotEmpty and @NotNull annotations to gender field
  • Added @DateTimeFormat(pattern = "yyyy-MM-dd") annotation to birthday field
  • Added @Range(min = 1, max = 16) annotation to persona field

Gender.java - Review

  • Removed unused imports

SocialType.java - Review

  • Removed unused imports

MemberCommandService.java - Review

  • Changed log.debug to log.info

MemberQueryService.java - Review

  • Changed isValidNickName method to throw an exception if the nickname already exists
  • Changed isValidNickName method to throw an exception if the nickname does not match the pattern
  • Changed isValidNickName method to throw an exception if the nickname length is not between 2 and 8
  • Removed unused method searchByNickname

MessageSourceConfig.java - Review

  • Added new file

ErrorStatus.java - Review

  • Added new error codes for invalid nickname pattern and length

EnumValidator.java - Review

  • Changed equals method to equalsIgnoreCase method

EnumValue.java - Review

  • Added new file for getting enum value by name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

베로가 만든 @EnumValid 를 가져다 쓰면서 수정하고 싶은 부분을 수정했습니다.
원래 Enum Name과 일치한지를 봤는데 대소문자 건너 뛰고 검증합니다.

@@ -0,0 +1,12 @@
package com.cozymate.cozymate_server.global.utils;
Copy link
Contributor Author

@genius00hwan genius00hwan Dec 1, 2024

Choose a reason for hiding this comment

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

enum 쓰실 때 valueOf()대신 이거 구현하셔서 getValue()쓰시는걸 추천합니다. 대소문자 상관없이 값을 추출합니다

Copy link
Contributor

Choose a reason for hiding this comment

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

getValue를 어떤 이유 때문에 추천하시나요?

.filter(socialType -> socialType.name().equalsIgnoreCase(socialTypeString))
.findFirst()
.orElseThrow( () -> new GeneralException(ErrorStatus._INVALID_SOCIAL_TYPE));
public static SocialType getValue(String socialTypeString){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enum 쓰신다면 밑에 EnumValue 인터페이스 어케 생긴지 보시고 이것처럼 구현 하시면 좋을 것 같습니다!!

Copy link

github-actions bot commented Dec 1, 2024

리뷰해드려요~

  1. {ClientIdMaker.java}
  • Changed clientId = "12345@KAKAO" to clientId = "12345:KAKAO"
  • This change is likely to ensure that the client id format follows a specific pattern.
  1. {Member.java}
  • Added @Range(min = 1, max = 16) annotation to the persona field
  • This change is likely to ensure that the persona value is within a specific range.
  1. {MemberController.java}
  • Added @Range(min = 1, max = 16) annotation to the persona parameter in the updatePersona method
  • This change is likely to ensure that the persona value passed to the method is within a specific range.
  1. {SignInRequestDTO.java}
  • Added @NotNull and @NotEmpty annotations to the clientId and socialType fields
  • This change is likely to ensure that these fields cannot be null or empty.
  1. {SignUpRequestDTO.java}
  • Added @NotNull and @NotEmpty annotations to the nickname, gender, and universityId fields
  • Added @Length(min = 2, max = 8) annotation to the nickname field
  • Added @Range(min = 1, max = 16) annotation to the persona field
  • This change is likely to ensure that these fields cannot be null or empty and that the nickname length and persona value are within specific ranges.
  1. {Gender.java}
  • Removed unused imports and methods
  • This change is likely to simplify the code and remove unnecessary dependencies.
  1. {SocialType.java}
  • Removed unused imports and methods
  • This change is likely to simplify the code and remove unnecessary dependencies.
  1. {MemberCommandService.java}
  • Changed log.debug to log.info for the clientId log message
  • This change is likely to ensure that the log message is more visible in the logs.
  1. {MemberQueryService.java}
  • Added NICKNAME_PATTERN constant and updated the isValidNickName method
  • This change is likely to ensure that the nickname follows a specific pattern and is not already in use.
  1. {ErrorStatus.java}
  • Added _INVALID_NICKNAME_PATTERN and _INVALID_NICKNAME_LENGTH constants
  • This change is likely to provide more specific error messages for invalid nicknames.
  1. {EnumValidator.java}
  • Changed value.equals(enumValue.toString()) to value.equalsIgnoreCase(enumValue.toString())
  • This change is likely to ensure that the enum value comparison is case-insensitive.
  1. {EnumValue.java}
  • Added EnumValue interface and implementation
  • This change is likely to provide a reusable method for getting enum values based on a string value.

It's important to note that these changes are based on a code review and may not reflect the full context or reasoning behind each change. It's always best to consult with the developer or team responsible for the code to fully understand the changes and their implications.

@genius00hwan genius00hwan added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Dec 2, 2024
Copy link
Member

@veronees veronees left a comment

Choose a reason for hiding this comment

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

LGTM~ 제 코드도 getValue()로 바꿔야겠네요

Comment on lines +13 to +14
@NotNull(message = "null일 수 없습니다.")
@NotEmpty(message = "비어 있을 수 없습니다.")
Copy link
Member

Choose a reason for hiding this comment

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

이부분 @notblank 하나로 대체 가능할 것 같은데,
상황별로 자세한 메시지 응답하려는 의도인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넹 그런 이유로 나눴습니다

Copy link
Member

@eple0329 eple0329 left a comment

Choose a reason for hiding this comment

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

좋은거같아용

@@ -59,7 +64,7 @@ public SignInResponseDTO signIn(SignInRequestDTO signInRequestDTO) {

String clientId = ClientIdMaker.makeClientId(signInRequestDTO.clientId(), socialType);

log.debug("사용자 로그인 : {}",clientId);
log.info("사용자 로그인 : {}", clientId);
Copy link
Member

Choose a reason for hiding this comment

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

해당 부분이 실행되는 API를 호출했을 때 REQUEST에 UserID 출력 안되나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아 이거 지금 바꿀게여 debug로 바꿔서 pr올린다는걸 빼먹었네여

Copy link
Contributor

@jpark0506 jpark0506 left a comment

Choose a reason for hiding this comment

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

LGTM~ 고생하셨습니다

@@ -0,0 +1,12 @@
package com.cozymate.cozymate_server.global.utils;
Copy link
Contributor

Choose a reason for hiding this comment

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

getValue를 어떤 이유 때문에 추천하시나요?

Copy link

github-actions bot commented Dec 3, 2024

리뷰해드려요~

  1. ClientIdMaker.java
  • Changed @ to : in the generateClientId method.
  1. Member.java
  • Added @Range annotation to the persona field.
  1. MemberController.java
  • Changed @Max and @Min to @Range annotation for the persona field in the updatePersona method.
  • Added @NotEmpty and @NotNull annotations to the majorName field in the updateMajorName method.
  1. SignInRequestDTO.java
  • Added @NotEmpty and @NotNull annotations to the clientId and socialType fields.
  1. SignUpRequestDTO.java
  • Added @NotEmpty and @NotNull annotations to the nickname, gender, and universityId fields.
  • Added @Range annotation to the persona field.
  1. Gender.java
  • Removed unnecessary code.
  1. SocialType.java
  • Removed unnecessary code.
  1. MemberCommandService.java
  • Changed isValidNickName method to checkNickname and added exception handling.
  1. MemberQueryService.java
  • Changed isValidNickName method to throw an exception instead of returning a boolean value.
  • Removed unnecessary code.
  1. ErrorStatus.java
  • Added two new error status codes for invalid nickname pattern and length.
  1. EnumValidator.java
  • Changed equals to equalsIgnoreCase in the isValid method.
  1. EnumValue.java
  • Added a new interface for getting enum values.

These changes improve the code by adding more validations, simplifying the code, and making it more readable.

@genius00hwan genius00hwan merged commit be332a0 into develop Dec 3, 2024
1 check passed
eple0329 pushed a commit that referenced this pull request Dec 4, 2024
* [COZY-411] feat : 예외 메시지 기본 틀 생성

* [COZY-411] feat : enum값 관련 interface 생성

* [COZY-411] feat : 사용자 관련 validation 고도화

* [COZY-411] fix : 에러 메시지 안 쓰게돼서 설정에서 삭제

* [COZY-411] rename : 에러 메시지 안 쓰게돼서 설정파일 삭제

* [COZY-411] fix : log 타입 수정
@eple0329 eple0329 deleted the feature/COZY-411 branch December 4, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants