-
Notifications
You must be signed in to change notification settings - Fork 2
[REFACTOR/#229] 1차 리팩(1/4회의 수정사항 반영 완료) #230
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9cc5ab
[refactor/#229] 1차 리팩
eeeeeaaan bf5197c
[refactor/#229] 1차 리팩 _ reids 사용 후 db삽입으로 전환
eeeeeaaan 6ce39d5
[refactor/#229] api 삭제 복구
eeeeeaaan 9ca6737
[refactor/#229] api 삭제 복구 빠진부분
eeeeeaaan d07052e
[refactor/#229] api 삭제 복구 빠진부분22
eeeeeaaan fccde10
[refactor/#229] private 메소드 뒤로 옮김
eeeeeaaan 860545e
[refactor/#229] 임시 QR 관련 api
eeeeeaaan 7301e68
[refactor/#229] 컨버터 로직 dto로 이전
eeeeeaaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 0 additions & 47 deletions
47
src/main/java/com/assu/server/domain/certification/SessionTimeoutManager.java
This file was deleted.
Oops, something went wrong.
122 changes: 38 additions & 84 deletions
122
...main/java/com/assu/server/domain/certification/component/CertificationSessionManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,122 +1,76 @@ | ||
| package com.assu.server.domain.certification.component; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.data.redis.core.StringRedisTemplate; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| // | ||
| // @Slf4j // ⭐️ SLF4j 로그 사용을 위해 추가 | ||
| // @Component | ||
| // public class CertificationSessionManager { | ||
| // private final Map<Long, Set<Long>> sessionUserMap = new ConcurrentHashMap<>(); | ||
| // | ||
| // public void openSession(Long sessionId) { | ||
| // sessionUserMap.put(sessionId, ConcurrentHashMap.newKeySet()); | ||
| // // ⭐️ 로그 추가 | ||
| // log.info("✅ New certification session opened. SessionID: {}", sessionId); | ||
| // } | ||
| // | ||
| // public void addUserToSession(Long sessionId, Long userId) { | ||
| // Set<Long> users = sessionUserMap.computeIfAbsent(sessionId, k -> { | ||
| // log.warn("Attempted to add user to a non-existent session. Creating new set for SessionID: {}", k); | ||
| // return ConcurrentHashMap.newKeySet(); | ||
| // }); | ||
| // | ||
| // boolean isAdded = users.add(userId); | ||
| // | ||
| // // ⭐️ 요청하신 멤버 추가 확인 로그 | ||
| // if (isAdded) { | ||
| // log.info("👤 User added to session. SessionID: {}, UserID: {}. Current participants: {}", | ||
| // sessionId, userId, users.size()); | ||
| // } else { | ||
| // log.info("👤 User already in session. SessionID: {}, UserID: {}. Current participants: {}", | ||
| // sessionId, userId, users.size()); | ||
| // } | ||
| // } | ||
| // | ||
| // public int getCurrentUserCount(Long sessionId) { | ||
| // return sessionUserMap.getOrDefault(sessionId, Set.of()).size(); | ||
| // } | ||
| // | ||
| // public boolean hasUser(Long sessionId, Long userId) { | ||
| // return sessionUserMap.getOrDefault(sessionId, Set.of()).contains(userId); | ||
| // } | ||
| // | ||
| // public List<Long> snapshotUserIds(Long sessionId) { | ||
| // return List.copyOf(sessionUserMap.getOrDefault(sessionId, Set.of())); | ||
| // } | ||
| // | ||
| // | ||
| // | ||
| // public void removeSession(Long sessionId) { | ||
| // sessionUserMap.remove(sessionId); | ||
| // // ⭐️ 로그 추가 | ||
| // log.info("❌ Certification session removed. SessionID: {}", sessionId); | ||
| // } | ||
| // } | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CertificationSessionManager { | ||
|
|
||
| // RedisTemplate을 주입받습니다. | ||
| private final StringRedisTemplate redisTemplate; | ||
| private static final String ID_COUNTER_KEY = "certification:id:seq"; | ||
| private static final String SESSION_INIT_MARKER = "STATUS_OPEN"; | ||
|
|
||
| // 세션 ID를 위한 KEY를 만드는 헬퍼 메서드 | ||
| private String getKey(Long sessionId) { | ||
| return "certification:session:" + sessionId; | ||
| } | ||
|
|
||
| public void openSession(Long sessionId) { | ||
| String key = getKey(sessionId); | ||
| // 세션을 연다는 것은 키를 만드는 것과 같습니다. | ||
| // addUserToSession에서 자동으로 키가 생성되므로 이 메서드는 비워두거나, | ||
| // 만료 시간 설정 등 초기화 로직을 넣을 수 있습니다. | ||
| // 예: 10분 후 만료 | ||
| private String getInfoKey(Long sessionId) { | ||
| return "certification:info:" + sessionId; | ||
| } | ||
|
|
||
| public Long openSession(Long storeId, Integer peopleNumber) { | ||
| Long newSessionId = redisTemplate.opsForValue().increment(ID_COUNTER_KEY); | ||
| if (newSessionId == null) throw new RuntimeException("ID 생성 실패"); | ||
|
|
||
| String key = getKey(newSessionId); | ||
| String infoKey = getInfoKey(newSessionId); | ||
|
|
||
| redisTemplate.opsForSet().add(key, SESSION_INIT_MARKER); | ||
| redisTemplate.expire(key, 10, TimeUnit.MINUTES); | ||
|
|
||
| redisTemplate.opsForHash().put(infoKey, "storeId", String.valueOf(storeId)); | ||
| redisTemplate.opsForHash().put(infoKey, "peopleNumber", String.valueOf(peopleNumber)); | ||
| redisTemplate.expire(infoKey, 10, TimeUnit.MINUTES); | ||
|
|
||
| return newSessionId; | ||
| } | ||
|
|
||
| public void addUserToSession(Long sessionId, Long userId) { | ||
| String key = getKey(sessionId); | ||
| // Redis의 Set 자료구조에 userId를 추가합니다. | ||
| redisTemplate.opsForSet().add(key, String.valueOf(userId)); | ||
| public boolean exists(Long sessionId) { | ||
| return Boolean.TRUE.equals(redisTemplate.hasKey(getKey(sessionId))); | ||
| } | ||
|
|
||
| public int getCurrentUserCount(Long sessionId) { | ||
| String key = getKey(sessionId); | ||
| // Redis Set의 크기를 반환합니다. | ||
| Long size = redisTemplate.opsForSet().size(key); | ||
| return size != null ? size.intValue() : 0; | ||
| public String getSessionInfo(Long sessionId, String field) { | ||
| return (String) redisTemplate.opsForHash().get(getInfoKey(sessionId), field); | ||
| } | ||
|
|
||
| public void addUserToSession(Long sessionId, Long userId) { | ||
| redisTemplate.opsForSet().add(getKey(sessionId), String.valueOf(userId)); | ||
| } | ||
|
|
||
| public boolean hasUser(Long sessionId, Long userId) { | ||
| String key = getKey(sessionId); | ||
| // Redis Set에 해당 멤버가 있는지 확인합니다. | ||
| return redisTemplate.opsForSet().isMember(key, String.valueOf(userId)); | ||
| return redisTemplate.opsForSet().isMember(getKey(sessionId), String.valueOf(userId)); | ||
| } | ||
|
|
||
| public List<Long> snapshotUserIds(Long sessionId) { | ||
| String key = getKey(sessionId); | ||
| // Redis Set의 모든 멤버를 가져옵니다. | ||
| Set<String> members = redisTemplate.opsForSet().members(key); | ||
| if (members == null) { | ||
| return List.of(); | ||
| } | ||
| Set<String> members = redisTemplate.opsForSet().members(getKey(sessionId)); | ||
| if (members == null) return List.of(); | ||
|
|
||
| return members.stream() | ||
| .filter(m -> !SESSION_INIT_MARKER.equals(m)) | ||
| .map(Long::valueOf) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public void removeSession(Long sessionId) { | ||
| String key = getKey(sessionId); | ||
| // 세션 키 자체를 삭제합니다. | ||
| redisTemplate.delete(key); | ||
| redisTemplate.delete(getKey(sessionId)); | ||
| redisTemplate.delete(getInfoKey(sessionId)); | ||
| } | ||
| } | ||
37 changes: 0 additions & 37 deletions
37
src/main/java/com/assu/server/domain/certification/config/CertifyWebSocketConfig.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.