-
Notifications
You must be signed in to change notification settings - Fork 0
add: signup 구현 #45
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
Open
Song-H-H
wants to merge
1
commit into
main
Choose a base branch
from
hhsong/add_signup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add: signup 구현 #45
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/neorang/neims/globals/exceptionhandler/CustomExceptionHandler.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,23 @@ | ||
| package com.neorang.neims.globals.exceptionhandler; | ||
|
|
||
| import com.neorang.neims.users.exception.DuplicatedException; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @Slf4j | ||
| @RestControllerAdvice | ||
| public class CustomExceptionHandler { | ||
|
|
||
| ErrorResult getErrorResult(String errorCd, String msg) { | ||
| return new ErrorResult(errorCd, msg); | ||
| } | ||
|
|
||
| @ExceptionHandler(DuplicatedException.class) | ||
| protected ResponseEntity<ErrorResult> handleCustomException(DuplicatedException e) { | ||
| ErrorResult errorResult = getErrorResult("BAD_REQUEST", e.getMessage()); | ||
| return new ResponseEntity<>(errorResult, HttpStatus.BAD_REQUEST); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/neorang/neims/globals/exceptionhandler/ErrorResult.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,11 @@ | ||
| package com.neorang.neims.globals.exceptionhandler; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public class ErrorResult { | ||
| private String errorType; | ||
| private String errorMsg; | ||
| } |
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,14 @@ | ||
| package com.neorang.neims.users; | ||
|
|
||
| import com.neorang.neims.users.domain.Users; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface UserRepository extends JpaRepository<Users, String> { | ||
|
|
||
| Optional<Users> findByEmail(String email); | ||
|
|
||
| Optional<Users> findByIgnoreCaseUserId(String userId); | ||
|
|
||
| } |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/neorang/neims/users/exception/DuplicatedException.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,16 @@ | ||
| package com.neorang.neims.users.exception; | ||
|
|
||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
|
|
||
|
|
||
| @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
| public class DuplicatedException extends RuntimeException { | ||
|
|
||
| public DuplicatedException(String message) { | ||
| super(message + " is Duplicated"); | ||
| } | ||
|
|
||
| } |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/neorang/neims/users/service/UserSerivce.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,53 @@ | ||
| package com.neorang.neims.users.service; | ||
|
|
||
|
|
||
| import com.neorang.neims.users.exception.DuplicatedException; | ||
| import com.neorang.neims.users.UserRepository; | ||
| import com.neorang.neims.users.domain.Role; | ||
| import com.neorang.neims.users.domain.Users; | ||
| import com.neorang.neims.users.dto.SignupForm; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.util.Assert; | ||
| import org.springframework.util.ObjectUtils; | ||
|
|
||
| @Service | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public class UserSerivce { | ||
|
|
||
| private final UserRepository userRepository; | ||
|
|
||
| private final PasswordEncoder passwordEncoder; | ||
|
|
||
| public void save(SignupForm signupForm){ | ||
| Assert.notNull(signupForm.getUserId(), "ID must be provided"); | ||
| Assert.notNull(signupForm.getEmail(), "Email must be provided"); | ||
| Assert.notNull(signupForm.getPassword(), "Password must be provided"); | ||
|
|
||
| Users duplicatedUserId = findByIgnoreCaseId(signupForm.getUserId()); | ||
| Users duplicatedUserEmail = findByEmail(signupForm.getEmail()); | ||
| String encodePassword = passwordEncoder.encode(signupForm.getPassword()); | ||
|
|
||
| if(!ObjectUtils.isEmpty(duplicatedUserId)) throw new DuplicatedException(signupForm.getUserId()); | ||
| if(!ObjectUtils.isEmpty(duplicatedUserEmail)) throw new DuplicatedException(signupForm.getEmail()); | ||
|
|
||
| Users user = signupForm.toEntity(); | ||
| user.setPassword(encodePassword); | ||
| user.setRole(Role.USER); | ||
|
|
||
| userRepository.save(user); | ||
| } | ||
|
|
||
| public Users findById(String userId){ | ||
| return userRepository.findById(userId).orElse(null); | ||
| } | ||
|
|
||
| public Users findByIgnoreCaseId(String userId){ return userRepository.findByIgnoreCaseUserId(userId).orElse(null); } | ||
|
|
||
| public Users findByEmail(String userId){ return userRepository.findByEmail(userId).orElse(null); } | ||
|
|
||
|
|
||
| } | ||
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.
필수 값 Assert 및 사용자 권한 기본값은 도메인의 책임이 더 크므로
SignupForm으로 이동, 혹은 Validation 적용