Skip to content

Commit

Permalink
Merge pull request #108 from UMC-CommonPlant/#105_refactor_login_logic
Browse files Browse the repository at this point in the history
[Refactor] Refactor join User Logic
  • Loading branch information
uhyunglee authored Mar 2, 2024
2 parents bdcf4b5 + 45d9371 commit 95869c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static class join{
private String name;
@Schema(description = "소셜로그인", example = "kakao")
private String provider;
@Schema(description = "회원번호", example = "0123456789")
private String providerId;
}
@NotBlank(message = "사용할 이름을 입력해주세요.")
@Pattern(regexp = "^[가-힣a-zA-Z0-9]{2,10}$" , message = "이름은 특수문자를 포함하지 않은 2~10자리여야 합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public class User extends BaseTime {
private String uuid;

@Builder
public User(String name, String email, String provider, String imgUrl, String uuid){
public User(String name, String email, String provider, String providerId, String imgUrl, String uuid){
this.name = name;
this.email = email;
this.provider = provider;
this.providerId = providerId;
this.imgUrl = imgUrl;
this.uuid = uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByname(String name);
Optional<User> findByEmail(String email);
Optional<User> findByUuid(String uuid);
Optional<User> findByProviderId(String providerId);

@Query("select u from User u where u.email=?1 and u.provider=?2")
User findByEmail(String email, String loginType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class UserService {
public User getUser(String uuid){ // User 조회
return userRepository.findByUuid(uuid).orElseThrow(() -> new BadRequestException((NOT_FOUND_USER)));
}

public User getUserByProviderId(String providerId){
return userRepository.findByProviderId(providerId).orElseThrow(() -> new BadRequestException(NOT_FOUND_USER));
}

public User saveUser(UserDto.join req){
User user = User.builder()
.name(req.getName())
Expand All @@ -48,8 +53,9 @@ public String joinUser(UserDto.join req, MultipartFile image){
.imgUrl(imageUrl)
.uuid(uuid)
.email(req.getEmail())
.provider(req.getProvider()).
build();
.provider(req.getProvider())
.providerId(req.getProviderId())
.build();
userRepository.save(user);

return jwtService.createToken(user.getUuid());
Expand Down

0 comments on commit 95869c8

Please sign in to comment.