-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Feat: 심리지식 API 구현 #35
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
base: develop
Are you sure you want to change the base?
Conversation
# Conflicts: # src/main/java/com/example/egobook_be/domain/user/entity/User.java # src/main/java/com/example/egobook_be/domain/user/entity/UserStatus.java # src/main/java/com/example/egobook_be/domain/user/repository/UserRepository.java # src/main/java/com/example/egobook_be/global/config/SecurityConfig.java
| if (candidates.isEmpty()) candidates = psychologyKnowledgeRepository.findAll(); | ||
|
|
||
| // 3. 오늘 지식 확정 및 DB 저장 | ||
| long seed = userId + LocalDate.now().toEpochDay(); | ||
| PsychologyKnowledge picked = candidates.get(new Random(seed).nextInt(candidates.size())); | ||
|
|
||
| // 조회 기록 남기기 | ||
| UserKnowledge newHistory = new UserKnowledge(user, picked); | ||
| newHistory.setBookmarked(false); // 처음엔 조회만 한 상태 | ||
| userKnowledgeRepository.save(newHistory); | ||
|
|
||
| return createResponse(user, picked, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단순 DB 저장이 아닌, 유저 ID와 날짜를 조합한 seed 기반 랜덤을 사용해 하루 동안 결과가 일관되게 유지되는 점 좋은 것 같습니다!
다만 모든 심리 지식을 조회한 이후 리셋되어 (candidates.isEmpty())가 실행되는 흐름에서, 기존 조회 기록을 삭제하거나 별도의 처리가 없다면 그 다음 날부터도 viewedIds가 항상 전체를 포함하게 되어 매일 전체 랜덤으로 동작하게 되는 구조가 아닐지 우려됩니다. 이 경우 기존 조회 데이터를 찾아 시각을 업데이트하는 등의 처리가 선택지가 될 수도 있을 것 같습니다! 또한 리셋 이후 북마크(유리병) 여부와 상관없이 다시 오늘의 심리 지식으로 노출될 수 있는 상태가 맞는지도 궁금합니다.
| @Column(name = "created_at", nullable = false, updatable = false) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| // 데이터가 처음 저장될 때 현재 시간을 자동으로 넣어주는 마법의 메서드야! | ||
| @PrePersist | ||
| protected void onCreate() { | ||
| this.createdAt = LocalDateTime.now(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
공통으로 사용 중인 BaseTimeEntity를 상속받아 사용하는 방식도 일관성을 위해 고려해볼 수 있을 것 같습니다!
# Conflicts: # src/main/java/com/example/egobook_be/domain/user/entity/User.java
#️⃣연관된 이슈
📝작업 내용
📝 기타 참고사항