Skip to content

Commit fd6dfac

Browse files
authored
fix: 추천 여러번 생성한 경우 읽음 버그 해결 (#24)
1 parent 1af8285 commit fd6dfac

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/lotto/repository.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,22 @@ async def get_recommendation_by_user_and_round(
204204
LottoRecommendations.user_id == user_id,
205205
LottoRecommendations.round == round,
206206
)
207+
.order_by(desc(LottoRecommendations.created_at))
207208
.limit(1)
208209
)
209210
result = await self.session.execute(query)
210211
return result.scalar_one_or_none()
211212

212-
async def mark_recommendation_read(self, recommendation_id: int, read_at: datetime) -> None:
213-
"""추천 레코드를 읽음 처리합니다."""
213+
async def mark_all_recommendations_read_by_user_and_round(
214+
self, user_id: str, round: int, read_at: datetime
215+
) -> None:
216+
"""특정 사용자와 회차의 모든 추천을 읽음 처리합니다."""
214217
stmt = (
215218
update(LottoRecommendations)
216-
.where(LottoRecommendations.id == recommendation_id)
219+
.where(
220+
LottoRecommendations.user_id == user_id,
221+
LottoRecommendations.round == round,
222+
)
217223
.values(is_read=True, read_at=read_at)
218224
)
219-
await self.session.execute(stmt)
225+
await self.session.execute(stmt)

src/lotto/service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,12 @@ async def check_recommendation_result(
380380
rank = self._judge_rank(matched_count, has_bonus)
381381
prize_amount = self._pick_prize_amount(draw, rank)
382382

383-
# 5) 읽음 처리
384-
if not rec.is_read:
385-
kst = ZoneInfo("Asia/Seoul")
386-
await self.lotto_repository.mark_recommendation_read(
387-
rec.id, read_at=datetime.now(tz=kst)
388-
)
389-
# 필요 시: await self.lotto_repository.session.commit()
383+
# 5) 읽음 처리 - 해당 라운드의 모든 추천을 읽음 처리
384+
kst = ZoneInfo("Asia/Seoul")
385+
await self.lotto_repository.mark_all_recommendations_read_by_user_and_round(
386+
user_id=user_id, round=round, read_at=datetime.now(tz=kst)
387+
)
388+
# 필요 시: await self.lotto_repository.session.commit()
390389

391390
# 6) 응답
392391
return LottoResultCheckResponse(

0 commit comments

Comments
 (0)