Skip to content

Conversation

@1Seob
Copy link
Collaborator

@1Seob 1Seob commented Dec 28, 2025

📝 요약(Summary)

테이블 및 엔티티

  • emotions, daily_reports 테이블 생성 및 엔티티 구현 + 시드

오늘의 리포트 생성 API 구현

전체적인 플로우는 아래와 같습니다. 이와 같이 구성한 이유는
LLM을 사용한 리포트 생성 시에 약 3~4초의 시간이 소요되기 때문에
리포트 생성을 포함해서 모든 과정을 하나의 트랜잭션으로 묶으면
DB 커넥션 점유/락 경합/타임아웃/스루풋 저하 등 여러 문제가 발생할 수 있기 때문입니다.

1. Tx-Prepare(짧게)
- AnswerEntry 없으면 생성(있으면 조회)
- DailyReport(PENDING) 생성(있으면 조회)

2. Tx 없음: LLM 호출

3. Tx-Finalize(짧게)
- 성공: Report COMPLETED
- 성공 시점에 10 크리스탈 충전 + CrystalLog 기록
- 실패: Report FAILED (충전 없음)
  • 오늘의 질문에 대해 일단 한번 입력된 답변은 저장되기 때문에,
    실패 시 오늘의 리포트 생성을 다시 시도하여도 동일한 답변으로 시도됩니다.
  • 소요 시간은 최대 3~4초 정도기 때문에 동기 처리로 구현하였습니다(주/월/전체 분석은 비동기로 구현해야함).

오늘의 리포트 조회 API 구현

🔗 Related Issue

💬 공유사항

✅ PR Checklist

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • PR 제목을 커밋 메시지 컨벤션에 맞게 작성했습니다.

@coldsunn
Copy link
Collaborator

오늘의 질문에 대해 일단 한번 입력된 답변은 저장되기 때문에,
실패 시 오늘의 리포트 생성을 다시 시도하여도 동일한 답변으로 시도됩니다.
-> 혹시 이게 어떤 의미인지 궁금합니다!

DailyQuestion question = dailyQuestionRepository.findById(request.questionId())
.orElseThrow(() -> new NotFoundException("질문을 찾을 수 없습니다. id: " + request.questionId()));

PrepareDailyResultDto prep = dailyReportTxService.prepareDaily(user, question, request.answer());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepareDaily 메서드에서 answerEntryService.getOrCreateTodayAnswerEntry()로 answerEntry를 조회하고 그 후에 answerEntryRepository.findById()로 또 조회해서 중복되는거 같은데 한 번 조회하도록 줄일 수 있을까요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dto에 AnswerEntry 자체를 포함시켜서 중복 제거했습니다

throw e;
}

long balanceAfter = dailyReportTxService.confirmDailyAndReward(prep, dto);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분에서도 confirmDailyAndReward 메서드에서 emotionRepository.findByName을 호출하는데 그 후에 emotionRepository.findByName로 중복 호출되는거 같아서 확인 부탁드립니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 Emotion 객체와 balanceAfter를 필드로 갖는 Dto를 따로 두어 중복을 제거했습니다

prepareDaily 메소드에서 AnswerEntry 조회 중복 제거, confirmDailyAndReward 메소드에서 Emotion 조회 중복 제거
@coldsunn
Copy link
Collaborator

고생하셨어요!!

@1Seob 1Seob merged commit 35e5b08 into develop Dec 28, 2025
1 check passed
@1Seob 1Seob deleted the feat/daily-report branch December 28, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Epic] 오늘의 리포트 구현

3 participants