diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserJoinFacade.java b/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserJoinFacade.java index 9044c1ae..3961761f 100644 --- a/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserJoinFacade.java +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserJoinFacade.java @@ -69,7 +69,8 @@ public TokenDto signUp(final UserSignUpRequest request) { private TokenDto getUserSignUpResponse(User user) { final TokenDto tokenDto = tokenProvider.generateJWT(user); - userTokenService.create(user.getUserUuid(), tokenDto.accessToken()); + + userTokenService.generateUserToken(user.getUserUuid(), tokenDto.accessToken()); return tokenDto; } diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserLoginFacade.java b/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserLoginFacade.java index f3ea9ddd..40a3506a 100644 --- a/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserLoginFacade.java +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/user/UserLoginFacade.java @@ -38,7 +38,7 @@ public TokenDto login(final UserLoginRequest request) { private TokenDto getGenerateJWT(final User user) { final TokenDto tokenDto = tokenProvider.generateJWT(user); - userTokenService.findByUserUuid(user.getUserUuid()).refresh(tokenDto.accessToken()); + userTokenService.refresh(user.getUserUuid(), tokenDto.accessToken()); return tokenDto; } diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/user/request/ModifiedIntroductionRequest.java b/tht-apis/src/main/java/com/tht/thtapis/facade/user/request/ModifiedIntroductionRequest.java new file mode 100644 index 00000000..33d33801 --- /dev/null +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/user/request/ModifiedIntroductionRequest.java @@ -0,0 +1,6 @@ +package com.tht.thtapis.facade.user.request; + +public record ModifiedIntroductionRequest( + String introduction +) { +} diff --git a/tht-apis/src/main/java/com/tht/thtapis/ui/UserController.java b/tht-apis/src/main/java/com/tht/thtapis/ui/UserController.java index 3169832e..28529adc 100644 --- a/tht-apis/src/main/java/com/tht/thtapis/ui/UserController.java +++ b/tht-apis/src/main/java/com/tht/thtapis/ui/UserController.java @@ -111,9 +111,9 @@ public ResponseEntity updateNickName( @PatchMapping("/user/introduction") public ResponseEntity updateSelfIntroduce( @AuthenticationPrincipal final User user, - @RequestBody final String introduction) { + @RequestBody final ModifiedIntroductionRequest request) { - userFacade.updateIntroduction(user, introduction); + userFacade.updateIntroduction(user, request.introduction()); return ResponseEntity.ok().build(); } diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/user/service/UserTokenService.java b/tht-core/domain/src/main/java/com/tht/domain/entity/user/service/UserTokenService.java index ceb377f3..f361d1e4 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/user/service/UserTokenService.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/user/service/UserTokenService.java @@ -7,6 +7,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @Service @Transactional @RequiredArgsConstructor @@ -27,7 +29,23 @@ public UserToken findByUserUuid(final String userUuid) { } - public void create(final String userUuid, final String accessToken) { + + public void refresh(final String userUuid, final String accessToken) { + UserToken userToken = findByUserUuid(userUuid); + userToken.refresh(accessToken); + } + + public void generateUserToken(final String userUuid, final String accessToken) { + final Optional userToken = userTokenRepository.findByUserUuid(userUuid); + + if(userToken.isPresent()) { + userToken.get().refresh(accessToken); + return; + } + create(userUuid, accessToken); + } + + private void create(final String userUuid, final String accessToken) { userTokenRepository.save(UserToken.create(userUuid, accessToken)); } }