-
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 #91 from TeamSobokSobok/develop
Release
- Loading branch information
Showing
12 changed files
with
83 additions
and
161 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
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
88 changes: 0 additions & 88 deletions
88
src/main/java/io/sobok/SobokSobok/auth/application/KakaoSocialService.java
This file was deleted.
Oops, something went wrong.
76 changes: 72 additions & 4 deletions
76
src/main/java/io/sobok/SobokSobok/auth/application/SocialService.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 |
---|---|---|
@@ -1,10 +1,78 @@ | ||
package io.sobok.SobokSobok.auth.application; | ||
|
||
import io.sobok.SobokSobok.auth.ui.dto.*; | ||
import io.sobok.SobokSobok.auth.domain.Role; | ||
import io.sobok.SobokSobok.auth.domain.SocialInfo; | ||
import io.sobok.SobokSobok.auth.domain.SocialType; | ||
import io.sobok.SobokSobok.auth.domain.User; | ||
import io.sobok.SobokSobok.auth.infrastructure.UserRepository; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginRequest; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialLoginResponse; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupRequest; | ||
import io.sobok.SobokSobok.auth.ui.dto.SocialSignupResponse; | ||
import io.sobok.SobokSobok.exception.ErrorCode; | ||
import io.sobok.SobokSobok.exception.model.ConflictException; | ||
import io.sobok.SobokSobok.exception.model.NotFoundException; | ||
import io.sobok.SobokSobok.external.kakao.KakaoService; | ||
import io.sobok.SobokSobok.security.jwt.Jwt; | ||
import io.sobok.SobokSobok.security.jwt.JwtProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
public abstract class SocialService { | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SocialService { | ||
|
||
public abstract SocialSignupResponse signup(SocialSignupRequest request); | ||
private final KakaoService kakaoService; | ||
|
||
public abstract SocialLoginResponse login(SocialLoginRequest request); | ||
private final UserRepository userRepository; | ||
|
||
private final JwtProvider jwtProvider; | ||
|
||
@Transactional | ||
public SocialSignupResponse signup(SocialSignupRequest request) { | ||
if (userRepository.existsBySocialInfoSocialId(request.socialId())) { | ||
throw new ConflictException(ErrorCode.ALREADY_EXISTS_USER); | ||
} | ||
|
||
if (userRepository.existsByUsername(request.username())) { | ||
throw new ConflictException(ErrorCode.ALREADY_USING_USERNAME); | ||
} | ||
|
||
User signupUser = userRepository.save(User.builder() | ||
.username(request.username()) | ||
.socialInfo(SocialInfo.builder() | ||
.socialId(request.socialId()) | ||
.build()) | ||
.deviceToken(request.deviceToken()) | ||
.roles(Role.USER.name()) | ||
.build()); | ||
|
||
Jwt jwt = jwtProvider.getUserJwt(signupUser.getSocialInfo().getSocialId()); | ||
|
||
return SocialSignupResponse.builder() | ||
.id(signupUser.getId()) | ||
.username(signupUser.getUsername()) | ||
.socialId(signupUser.getSocialInfo().getSocialId()) | ||
.accessToken(jwt.accessToken()) | ||
.refreshToken(jwt.refreshToken()) | ||
.build(); | ||
} | ||
|
||
@Transactional | ||
public SocialLoginResponse login(SocialLoginRequest request) { | ||
User loginUser = userRepository.findBySocialInfoSocialId(request.socialId()) | ||
.orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_USER)); | ||
|
||
if (!request.deviceToken().equals(loginUser.getDeviceToken())) { | ||
loginUser.updateDeviceToken(request.deviceToken()); | ||
} | ||
|
||
Jwt jwt = jwtProvider.getUserJwt(loginUser.getSocialInfo().getSocialId()); | ||
|
||
return SocialLoginResponse.builder() | ||
.accessToken(jwt.accessToken()) | ||
.refreshToken(jwt.refreshToken()) | ||
.build(); | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/io/sobok/SobokSobok/auth/application/SocialServiceProvider.java
This file was deleted.
Oops, something went wrong.
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
8 changes: 1 addition & 7 deletions
8
src/main/java/io/sobok/SobokSobok/auth/ui/dto/SocialLoginRequest.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
8 changes: 1 addition & 7 deletions
8
src/main/java/io/sobok/SobokSobok/auth/ui/dto/SocialSignupRequest.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
2 changes: 0 additions & 2 deletions
2
src/main/java/io/sobok/SobokSobok/auth/ui/dto/UsernameResponse.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