-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Seasoning-Today/refactor/accountId-nicknam…
…e-validation 회원 아이디 조회, 프로필 변경 서비스 로직 리팩토링
- Loading branch information
Showing
11 changed files
with
282 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 34 additions & 0 deletions
34
src/main/java/today/seasoning/seasoning/user/domain/AccountId.java
This file contains 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,34 @@ | ||
package today.seasoning.seasoning.user.domain; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import today.seasoning.seasoning.common.exception.CustomException; | ||
|
||
public class AccountId { | ||
|
||
private final String accountId; | ||
|
||
public AccountId(String accountId) { | ||
this.accountId = accountId; | ||
selfValidate(); | ||
} | ||
|
||
/* | ||
[아이디 규칙] | ||
- 5글자 이상, 20글자 이하 | ||
- 영문 소문자, 숫자, 밑줄('_') 및 점('.')으로 구성 | ||
- 점으로 시작하거나 끝날 수 없습니다. | ||
- 연속된 점은 포함될 수 없습니다. | ||
*/ | ||
private void selfValidate() { | ||
String upperCases = ".*[A-Z].*"; | ||
String regex = "^(?!.*\\.\\.)(?!.*\\.$)[^\\W][\\w.]{4,19}$"; | ||
|
||
if (accountId == null || accountId.matches(upperCases) || !accountId.matches(regex)) { | ||
throw new CustomException(HttpStatus.FORBIDDEN, "Invalid ID Format"); | ||
} | ||
} | ||
|
||
public String get() { | ||
return accountId; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/today/seasoning/seasoning/user/domain/Nickname.java
This file contains 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,32 @@ | ||
package today.seasoning.seasoning.user.domain; | ||
|
||
import java.util.regex.Pattern; | ||
import org.springframework.http.HttpStatus; | ||
import today.seasoning.seasoning.common.exception.CustomException; | ||
|
||
public class Nickname { | ||
|
||
private final String nickname; | ||
|
||
public Nickname(String nickname) { | ||
this.nickname = nickname; | ||
selfValidate(); | ||
} | ||
|
||
/* | ||
[닉네임 규칙] | ||
- 허용 문자 : 영문 소문자 & 대문자, 한글, 숫자 | ||
- 허용 길이 : 2글자 이상, 10글자 이하 | ||
*/ | ||
private void selfValidate() { | ||
String regex = "^[a-zA-Z0-9가-힣]{2,10}$"; | ||
|
||
if (nickname == null || !Pattern.matches(regex, nickname)) { | ||
throw new CustomException(HttpStatus.FORBIDDEN, "Invalid Nickname"); | ||
} | ||
} | ||
|
||
public String get() { | ||
return nickname; | ||
} | ||
} |
This file contains 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 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 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
6 changes: 0 additions & 6 deletions
6
src/main/java/today/seasoning/seasoning/user/service/ValidateAccountIdUsability.java
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
src/main/java/today/seasoning/seasoning/user/service/ValidateAccountIdUsabilityImpl.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/main/java/today/seasoning/seasoning/user/service/VerifyAccountIdService.java
This file contains 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,21 @@ | ||
package today.seasoning.seasoning.user.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import today.seasoning.seasoning.common.exception.CustomException; | ||
import today.seasoning.seasoning.user.domain.AccountId; | ||
import today.seasoning.seasoning.user.domain.UserRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VerifyAccountIdService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public void verify(AccountId accountId) { | ||
if(userRepository.existsByAccountId(accountId.get())) { | ||
throw new CustomException(HttpStatus.CONFLICT, "아이디 중복"); | ||
} | ||
} | ||
} |
Oops, something went wrong.