Skip to content

Commit

Permalink
fix: 세션 조회 로직 변경 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
Choi-JJunho authored Oct 19, 2023
1 parent 7c3b63d commit 59ba087
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface SessionGroupRepository extends JpaRepository<SessionGroup, Long

void deleteBySessionValue(String sessionValue);

boolean existsBySessionIdAndSessionKey(String sessionId, String key);
boolean existsBySessionIdAndSessionValue(String sessionId, String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ private void extendsSession(SessionGroup sessionGroup, LocalDateTime currentTime

@Transactional
public void add(String sessionId, String key, String value) {
if (sessionGroupRepository.existsBySessionIdAndSessionKey(sessionId, key)) {
if (sessionGroupRepository.existsBySessionIdAndSessionValue(sessionId, value)) {
return;
}

SessionGroup sessionGroup = SessionGroup.builder()
.sessionId(sessionId)
.sessionKey(key)
.sessionValue(value)
.expireTime(LocalDateTime.now().plusMinutes(EXTEND_EXPIRED_DAY))
.expireTime(LocalDateTime.now().plusDays(EXTEND_EXPIRED_DAY))
.build();
sessionGroupRepository.save(sessionGroup);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE session_group DROP INDEX uniq_sessions;
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ class SessionGroupRepositoryTest extends RepositoryTest {
.sessionId("UUID.randomUUID().toString()")
.sessionKey("KAKAO_ID")
.sessionValue("1234546426")
.expireTime(LocalDateTime.now().plusMinutes(30))
.expireTime(LocalDateTime.now().plusDays(30))
.build();
SessionGroup savedSessionGroup = sessionGroupRepository.save(sessionGroup);

boolean existsBySessionIdAndSessionKey = sessionGroupRepository.existsBySessionIdAndSessionKey(
boolean existsBySessionIdAndSessionValue = sessionGroupRepository.existsBySessionIdAndSessionValue(
savedSessionGroup.getSessionId(),
savedSessionGroup.getSessionKey()
savedSessionGroup.getSessionValue()
);

assertThat(existsBySessionIdAndSessionKey).isTrue();
assertThat(existsBySessionIdAndSessionValue).isTrue();
}

@Test
void 기존_세션이_존재하지않으면_False() {
boolean existsBySessionIdAndSessionKey = sessionGroupRepository.existsBySessionIdAndSessionKey(
"id", "sessionKey"
boolean existsBySessionIdAndSessionKey = sessionGroupRepository.existsBySessionIdAndSessionValue(
"id", "sessionValue"
);

assertThat(existsBySessionIdAndSessionKey).isFalse();
Expand Down

0 comments on commit 59ba087

Please sign in to comment.