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

[BE] FIX: User BlackholedAt 갱신 로직 추가 & 42API 로그인 이후 블랙홀이 DB와 불일치할 경우 … #1674

Merged
merged 2 commits into from
Aug 13, 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 @@ -81,6 +81,10 @@ public void handleUserLogin(HttpServletRequest req, HttpServletResponse res, Str
FtProfile profile = userOauthService.getProfileByCode(code);
User user = userQueryService.findUser(profile.getIntraName())
.orElseGet(() -> userCommandService.createUserByFtProfile(profile));
// 블랙홀이 API에서 가져온 날짜와 다르다면 갱신
if (!user.isSameBlackholedAt(profile.getBlackHoledAt())) {
userCommandService.updateUserBlackholedAtById(user.getId(), profile.getBlackHoledAt());
}
String token = tokenProvider.createUserToken(user, LocalDateTime.now());
Cookie cookie = cookieManager.cookieOf(TokenProvider.USER_TOKEN_NAME, token);
cookieManager.setCookieToClient(res, cookie, "/", req.getServerName());
Expand Down
15 changes: 15 additions & 0 deletions backend/src/main/java/org/ftclub/cabinet/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ public boolean isBlackholed() {
return blackholedAt != null && blackholedAt.isBefore(LocalDateTime.now());
}

/**
* this.blackholedAt과 전달인자 blackholedAt 중 어느 하나가 null인 경우 false를 반환
*
* @param blackholedAt
* @return
*/
public boolean isSameBlackholedAt(LocalDateTime blackholedAt) {
if (this.blackholedAt == null || blackholedAt == null) {
return this.blackholedAt == null && blackholedAt == null;
}

return this.blackholedAt.isEqual(blackholedAt);
}


public void addCoin(Long reward) {
this.coin += reward;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
* @param name 유저 이름
* @return {@link User}
*/
@Query("SELECT u FROM User u WHERE u.name = :name AND u.deletedAt IS NULL")
@Query("SELECT u FROM User u WHERE u.name = :name")
Optional<User> findByName(@Param("name") String name);

/**
Expand Down
25 changes: 25 additions & 0 deletions backend/src/test/java/org/ftclub/cabinet/user/domain/UserTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
package org.ftclub.cabinet.user.domain;

import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@RequiredArgsConstructor
public class UserTest {

@Test
void isSameBlackholedAt_test_both_null() {
User test = User.of("test", "[email protected]", null);
boolean sameBlackholedAt = test.isSameBlackholedAt(null);
Assertions.assertTrue(sameBlackholedAt);
}

@Test
void isSameBlackholedAt_test_one_null() {
User test = User.of("test", "[email protected]", null);
boolean sameBlackholedAt = test.isSameBlackholedAt(LocalDateTime.now());
Assertions.assertFalse(sameBlackholedAt);
}

@Test
void isSameBlackholedAt_test_same() {
LocalDateTime now = LocalDateTime.now();
User test = User.of("test", "[email protected]", now);
boolean sameBlackholedAt = test.isSameBlackholedAt(now);
Assertions.assertTrue(sameBlackholedAt);
}

// @Test
// @DisplayName("유저 생성 성공 - 일반적인 이메일 형식")
// void of_성공_일반적인_이메일_형식() {
Expand Down
Loading