Skip to content

Commit a580102

Browse files
authored
Merge pull request #5 from telling-me/fix/answer
[🐛 fix: answer count 로직 12/16일 기준으로 재편성]
2 parents 08401cc + 3264ddd commit a580102

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

src/app/v2/answers/models/answer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SELECT_ANSWER_BY_USER_UUID_QUERY,
1010
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY,
1111
SELECT_MOST_RECENT_ANSWER_BY_USER_UUID_QUERY,
12+
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2,
1213
)
1314
from app.v2.users.models.user import User
1415
from common.utils.query_executor import QueryExecutor
@@ -45,6 +46,12 @@ async def get_answer_count_by_user_id(cls, user_id: str) -> Any:
4546
value = user_id
4647
return await QueryExecutor.execute_query(query, values=value, fetch_type="single")
4748

49+
@classmethod
50+
async def get_answer_count_by_user_id_v2(cls, user_id: str) -> Any:
51+
query = SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2
52+
value = user_id
53+
return await QueryExecutor.execute_query(query, values=value, fetch_type="single")
54+
4855
@classmethod
4956
async def find_all_by_user(cls, user_id: str, start_date: datetime, end_date: datetime) -> Any:
5057
query = SELECT_ANSWER_BY_USER_UUID_QUERY

src/app/v2/answers/querys/answer_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY = f"SELECT COUNT(*) as answer_count FROM answer WHERE {USER_ID_QUERY}"
44

5+
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2 = f"""
6+
SELECT COUNT(*) as answer_count
7+
FROM answer
8+
WHERE {USER_ID_QUERY} AND created_time >= '2024-12-16 00:00:00'
9+
"""
10+
11+
512
SELECT_ANSWER_BY_USER_UUID_QUERY = f"""
613
SELECT * FROM answer
714
WHERE {USER_ID_QUERY}

src/app/v2/answers/services/answer_service.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77
class AnswerService:
88
@classmethod
99
async def get_answer_count(cls, user_id: str) -> int:
10+
"""
11+
과거부터 현재까지 총 답변 수
12+
"""
1013
answer_count_raw = await Answer.get_answer_count_by_user_id(user_id=user_id)
1114
if answer_count_raw is None:
1215
return 0
1316
return int(answer_count_raw.get("answer_count", 0))
1417

18+
@classmethod
19+
async def get_answer_count_v2(cls, user_id: str) -> int:
20+
"""
21+
v2 이후 총 답변 수
22+
"""
23+
answer_count_raw = await Answer.get_answer_count_by_user_id_v2(user_id=user_id)
24+
if answer_count_raw is None:
25+
return 0
26+
return int(answer_count_raw.get("answer_count", 0))
27+
1528
@classmethod
1629
async def get_answer_record(cls, user_id: str) -> int:
1730
end_date = datetime.now()

src/app/v2/levels/services/level_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def calculate_days_to_level_up(cls, user_id: str, current_exp: int, requir
6363
remaining_exp = required_exp - current_exp
6464
days_needed = 0
6565

66-
answer_count = await AnswerService.get_answer_count(user_id=user_id)
66+
answer_count = await AnswerService.get_answer_count_v2(user_id=user_id) + 1
6767
bonus_points = await AnswerService.calculate_consecutive_answer_points(user_id=user_id)
6868

6969
while remaining_exp > 0:

src/app/v2/missions/services/mission_service.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import asyncio
22
from datetime import date, datetime, timedelta, timezone
3-
from typing import Any, Optional
3+
from typing import Optional
44

55
from fastapi import HTTPException
66
from tortoise.exceptions import DoesNotExist
77
from tortoise.transactions import atomic
88

9-
from app.v2.answers.models.answer import Answer
109
from app.v2.answers.services.answer_service import AnswerService
1110
from app.v2.badges.services.badge_service import BadgeService
1211
from app.v2.cheese_managers.services.cheese_service import CheeseService
@@ -148,11 +147,11 @@ async def evaluate_mission_condition(self, user_id: str, mission_code: str) -> i
148147

149148
@staticmethod
150149
async def check_first_post(user_id: str) -> bool:
151-
return await AnswerService.get_answer_count(user_id=user_id) > 0
150+
return await AnswerService.get_answer_count_v2(user_id=user_id) > 0
152151

153152
@staticmethod
154153
async def get_answer_count(user_id: str) -> int:
155-
return await AnswerService.get_answer_count(user_id=user_id)
154+
return await AnswerService.get_answer_count_v2(user_id=user_id)
156155

157156
@staticmethod
158157
async def check_post_count_range(answer_count: int, min_count: int, max_count: int) -> bool:

0 commit comments

Comments
 (0)