Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/v2/answers/models/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
SELECT_ANSWER_BY_USER_UUID_QUERY,
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY,
SELECT_MOST_RECENT_ANSWER_BY_USER_UUID_QUERY,
SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2,
)
from app.v2.users.models.user import User
from common.utils.query_executor import QueryExecutor
Expand Down Expand Up @@ -45,6 +46,12 @@ async def get_answer_count_by_user_id(cls, user_id: str) -> Any:
value = user_id
return await QueryExecutor.execute_query(query, values=value, fetch_type="single")

@classmethod
async def get_answer_count_by_user_id_v2(cls, user_id: str) -> Any:
query = SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2
value = user_id
return await QueryExecutor.execute_query(query, values=value, fetch_type="single")

@classmethod
async def find_all_by_user(cls, user_id: str, start_date: datetime, end_date: datetime) -> Any:
query = SELECT_ANSWER_BY_USER_UUID_QUERY
Expand Down
7 changes: 7 additions & 0 deletions src/app/v2/answers/querys/answer_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

SELECT_ANSWER_COUNT_BY_USER_UUID_QUERY_V2 = f"""
SELECT COUNT(*) as answer_count
FROM answer
WHERE {USER_ID_QUERY} AND created_time >= '2024-12-16 00:00:00'
"""


SELECT_ANSWER_BY_USER_UUID_QUERY = f"""
SELECT * FROM answer
WHERE {USER_ID_QUERY}
Expand Down
13 changes: 13 additions & 0 deletions src/app/v2/answers/services/answer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@
class AnswerService:
@classmethod
async def get_answer_count(cls, user_id: str) -> int:
"""
๊ณผ๊ฑฐ๋ถ€ํ„ฐ ํ˜„์žฌ๊นŒ์ง€ ์ด ๋‹ต๋ณ€ ์ˆ˜
"""
answer_count_raw = await Answer.get_answer_count_by_user_id(user_id=user_id)
if answer_count_raw is None:
return 0
return int(answer_count_raw.get("answer_count", 0))

@classmethod
async def get_answer_count_v2(cls, user_id: str) -> int:
"""
v2 ์ดํ›„ ์ด ๋‹ต๋ณ€ ์ˆ˜
"""
answer_count_raw = await Answer.get_answer_count_by_user_id_v2(user_id=user_id)
if answer_count_raw is None:
return 0
return int(answer_count_raw.get("answer_count", 0))

@classmethod
async def get_answer_record(cls, user_id: str) -> int:
end_date = datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion src/app/v2/levels/services/level_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def calculate_days_to_level_up(cls, user_id: str, current_exp: int, requir
remaining_exp = required_exp - current_exp
days_needed = 0

answer_count = await AnswerService.get_answer_count(user_id=user_id)
answer_count = await AnswerService.get_answer_count_v2(user_id=user_id) + 1
bonus_points = await AnswerService.calculate_consecutive_answer_points(user_id=user_id)

while remaining_exp > 0:
Expand Down
7 changes: 3 additions & 4 deletions src/app/v2/missions/services/mission_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import asyncio
from datetime import date, datetime, timedelta, timezone
from typing import Any, Optional
from typing import Optional

from fastapi import HTTPException
from tortoise.exceptions import DoesNotExist
from tortoise.transactions import atomic

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

@staticmethod
async def check_first_post(user_id: str) -> bool:
return await AnswerService.get_answer_count(user_id=user_id) > 0
return await AnswerService.get_answer_count_v2(user_id=user_id) > 0

@staticmethod
async def get_answer_count(user_id: str) -> int:
return await AnswerService.get_answer_count(user_id=user_id)
return await AnswerService.get_answer_count_v2(user_id=user_id)

@staticmethod
async def check_post_count_range(answer_count: int, min_count: int, max_count: int) -> bool:
Expand Down
Loading