Skip to content

Commit

Permalink
[FIX] entity 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Jan 15, 2024
1 parent 84d6727 commit 205d1c5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions http/google-login.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET https://startlion.kro.kr/login/oauth2/code/google?code=4%2F0AfJohXn5fnJAmsF1_he4grGBOJd8IjZlQKWwUGiQZ8f6GSMTJ5YEsu8rg6v0flWor6n_VQ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class Part {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long partId;

// BE FE DESIGN PM
Expand All @@ -26,7 +25,6 @@ public class Part {
@Column(columnDefinition = "TEXT")
private String partContent;

@Column(length = 200)
private String typeOfTalent;

@Column(columnDefinition = "TEXT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AuthService {
@Transactional
public OAuthResponse authenticateUser(String authCode) throws Exception {

GoogleOAuthRequest googleOAuthRequest = GoogleOAuthRequest
val googleOAuthRequest = GoogleOAuthRequest
.builder()
.clientId(valueConfig.getGoogleClientId())
.clientSecret(valueConfig.getGoogleClientSecret())
Expand All @@ -45,7 +45,6 @@ public OAuthResponse authenticateUser(String authCode) throws Exception {
.build();

RestTemplate restTemplate = new RestTemplate();

ResponseEntity<GoogleLoginResponse> apiResponse = restTemplate.postForEntity(valueConfig.getGoogleAuthUrl() + "/token", googleOAuthRequest, GoogleLoginResponse.class);

GoogleLoginResponse googleLoginResponse = apiResponse.getBody();
Expand All @@ -59,13 +58,15 @@ public OAuthResponse authenticateUser(String authCode) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(resultJson);
val email = jsonNode.get("email").asText();
val socialId = "google";
val username = jsonNode.get("name").asText();
val imageUrl = jsonNode.get("picture").asText();
val newUser = User.create(email, username, socialId, imageUrl);

val newUser = User.create(
email,
jsonNode.get("name").asText(),
"google",
jsonNode.get("picture").asText());

User user = userRepository.findByEmail(email).orElseGet(() -> userRepository.save(newUser));
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, null);
val authentication = new UsernamePasswordAuthenticationToken(user, null, null);
val tokenVO = generateToken(authentication);
user.updateRefreshToken(tokenVO.refreshToken());
return OAuthResponse.of(tokenVO.accessToken(), tokenVO.refreshToken());
Expand All @@ -74,6 +75,6 @@ public OAuthResponse authenticateUser(String authCode) throws Exception {
private TokenVO generateToken(Authentication authentication){
val accessToken = jwtTokenProvider.generateToken(authentication,ACCESS_TOKEN_EXPIRATION);
val refreshToken = jwtTokenProvider.generateToken(authentication,REFRESH_TOKEN_EXPIRATION);
return new TokenVO(accessToken,refreshToken);
return TokenVO.of(accessToken, refreshToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.startlion.startlionserver.service;


import lombok.Builder;

public record TokenVO(
String accessToken,
String refreshToken
) {

public TokenVO(String accessToken, String refreshToken) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
public static TokenVO of(String accessToken, String refreshToken) {
return new TokenVO(accessToken, refreshToken);
}
}

0 comments on commit 205d1c5

Please sign in to comment.