Skip to content
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

[feat] 소셜 로그인 API 관련 수정 작업 (fcm Token 추가) #48

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -19,7 +20,7 @@ public class AuthController {
private final AuthService authService;

@PostMapping("/auth/signin")
public ResponseEntity<JwtTokenDto> signin(
public ResponseEntity<UserTokenDto> signin(
@NotNull @RequestHeader(Constant.AUTHORIZATION_HEADER) final String providerToken,
@Valid @RequestBody final UserLoginDto userLoginDto
) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/kkumulkkum/server/domain/UserInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

public record UserLoginDto(
@NotNull
Provider provider
Provider provider,
@NotNull
String fcmToken
) {
}
Original file line number Diff line number Diff line change
@@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Loading