diff --git a/src/main/java/org/kkumulkkum/server/controller/AuthController.java b/src/main/java/org/kkumulkkum/server/controller/AuthController.java index 1a3250f..cb41e4c 100644 --- a/src/main/java/org/kkumulkkum/server/controller/AuthController.java +++ b/src/main/java/org/kkumulkkum/server/controller/AuthController.java @@ -7,6 +7,7 @@ import org.kkumulkkum.server.constant.Constant; import org.kkumulkkum.server.dto.auth.request.UserLoginDto; import org.kkumulkkum.server.dto.auth.response.JwtTokenDto; +import org.kkumulkkum.server.dto.auth.response.UserTokenDto; import org.kkumulkkum.server.service.auth.AuthService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -19,7 +20,7 @@ public class AuthController { private final AuthService authService; @PostMapping("/auth/signin") - public ResponseEntity signin( + public ResponseEntity signin( @NotNull @RequestHeader(Constant.AUTHORIZATION_HEADER) final String providerToken, @Valid @RequestBody final UserLoginDto userLoginDto ) { diff --git a/src/main/java/org/kkumulkkum/server/domain/UserInfo.java b/src/main/java/org/kkumulkkum/server/domain/UserInfo.java index 26e32b7..8787877 100644 --- a/src/main/java/org/kkumulkkum/server/domain/UserInfo.java +++ b/src/main/java/org/kkumulkkum/server/domain/UserInfo.java @@ -15,6 +15,8 @@ public class UserInfo extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + private String fcmToken; + private String name; private String profileImg; @@ -48,6 +50,11 @@ public UserInfo(String name, this.tardySum = 0L; } + + public void updateFcmToken(String fcmToken) { + this.fcmToken = fcmToken; + } + public void updateImage(String imageUrl) { this.profileImg = imageUrl; } diff --git a/src/main/java/org/kkumulkkum/server/dto/auth/request/UserLoginDto.java b/src/main/java/org/kkumulkkum/server/dto/auth/request/UserLoginDto.java index a8af4c8..e95a29c 100644 --- a/src/main/java/org/kkumulkkum/server/dto/auth/request/UserLoginDto.java +++ b/src/main/java/org/kkumulkkum/server/dto/auth/request/UserLoginDto.java @@ -5,6 +5,8 @@ public record UserLoginDto( @NotNull - Provider provider + Provider provider, + @NotNull + String fcmToken ) { } diff --git a/src/main/java/org/kkumulkkum/server/dto/auth/response/UserTokenDto.java b/src/main/java/org/kkumulkkum/server/dto/auth/response/UserTokenDto.java new file mode 100644 index 0000000..4777218 --- /dev/null +++ b/src/main/java/org/kkumulkkum/server/dto/auth/response/UserTokenDto.java @@ -0,0 +1,15 @@ +package org.kkumulkkum.server.dto.auth.response; + +import org.kkumulkkum.server.domain.UserInfo; + +public record UserTokenDto( + String name, + JwtTokenDto jwtTokenDto +) { + public static UserTokenDto of(UserInfo userInfo, JwtTokenDto tokens) { + return new UserTokenDto( + userInfo.getName(), + tokens + ); + } +} diff --git a/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java b/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java index 3d678c6..26db6dc 100644 --- a/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java +++ b/src/main/java/org/kkumulkkum/server/service/auth/AuthService.java @@ -12,10 +12,12 @@ import org.kkumulkkum.server.domain.enums.Role; import org.kkumulkkum.server.dto.auth.request.UserLoginDto; import org.kkumulkkum.server.dto.auth.response.JwtTokenDto; +import org.kkumulkkum.server.dto.auth.response.UserTokenDto; import org.kkumulkkum.server.exception.AuthException; import org.kkumulkkum.server.exception.code.AuthErrorCode; import org.kkumulkkum.server.service.user.UserRetriever; import org.kkumulkkum.server.service.user.UserSaver; +import org.kkumulkkum.server.service.userInfo.UserInfoRetriever; import org.kkumulkkum.server.service.userInfo.UserInfoSaver; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,14 +35,17 @@ public class AuthService { private final JwtTokenProvider jwtTokenProvider; private final TokenRetriever tokenRetriever; private final TokenRemover tokenRemover; + private final UserInfoRetriever userInfoRetriever; @Transactional - public JwtTokenDto signin(final String providerToken, final UserLoginDto userLoginDto) { + public UserTokenDto signin(final String providerToken, final UserLoginDto userLoginDto) { SocialUserDto socialUserDto = getSocialInfo(providerToken, userLoginDto); User user = loadOrCreateUser(userLoginDto.provider(), socialUserDto); + UserInfo userInfo = userInfoRetriever.findByUserId(user.getId()); + userInfo.updateFcmToken(userLoginDto.fcmToken()); JwtTokenDto tokens = jwtTokenProvider.issueTokens(user.getId()); saveToken(user.getId(), tokens); - return tokens; + return UserTokenDto.of(userInfo, tokens); } @Transactional