Skip to content

Commit

Permalink
feat: 사용자 마지막 로그인한 날짜 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho committed Dec 16, 2023
1 parent 61e703a commit 7e2acdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/in/koreatech/koin/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,8 @@ public User(String password, String nickname, String name, String phoneNumber, U
public boolean isSamePassword(String password) {
return this.password.equals(password);
}

public void updateLastLoggedTime(LocalDateTime lastLoggedTime) {
lastLoggedAt = lastLoggedTime;
}
}
5 changes: 4 additions & 1 deletion src/main/java/in/koreatech/koin/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import in.koreatech.koin.dto.UserLoginResponse;
import in.koreatech.koin.repository.UserRepository;
import in.koreatech.koin.repository.UserTokenRepository;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -33,7 +34,9 @@ public UserLoginResponse login(UserLoginRequest request) {
String accessToken = jwtProvider.createToken(user);
String refreshToken = String.format("%s%d", UUID.randomUUID(), user.getId());
UserToken savedToken = userTokenRepository.save(UserToken.create(user.getId(), refreshToken));
user.updateLastLoggedTime(LocalDateTime.now());
User saved = userRepository.save(user);

return UserLoginResponse.of(accessToken, savedToken.getRefreshToken(), user.getUserType().getValue());
return UserLoginResponse.of(accessToken, savedToken.getRefreshToken(), saved.getUserType().getValue());
}
}
3 changes: 2 additions & 1 deletion src/test/java/in/koreatech/koin/acceptance/UserApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void userLoginSuccess() {
.extract();

User userResult = userRepository.findById(user.getId()).get();
UserToken token = tokenRepository.findById(user.getId()).get();
UserToken token = tokenRepository.findById(userResult.getId()).get();

assertSoftly(
softly -> {
Expand All @@ -70,6 +70,7 @@ void userLoginSuccess() {
softly.assertThat(response.jsonPath().getString("refresh_token"))
.isEqualTo(token.getRefreshToken());
softly.assertThat(response.jsonPath().getString("user_type")).isEqualTo("STUDENT");
softly.assertThat(userResult.getLastLoggedAt()).isNotNull();
}
);
}
Expand Down

0 comments on commit 7e2acdd

Please sign in to comment.