|
21 | 21 | from app.models.user import User |
22 | 22 | from app.models.enums import SkillCategory |
23 | 23 | from app.schemas.badge import Badge as BadgeSchema |
| 24 | +from app.schemas.grades import GradeStats as GradeStatsSchema |
| 25 | +from app.schemas.grades import HighestRank as HighestRankSchema |
24 | 26 | from app.schemas.profile import Profile as ProfileSchema |
25 | 27 | from app.schemas.profile import ProfileCreate, ProfileUpdate |
26 | 28 | from app.schemas.quest_progress import QuestProgress as QuestProgressSchema |
27 | 29 | from app.schemas.skill_tree import SkillTree as SkillTreeSchema |
28 | 30 | from app.schemas.user import User as UserSchema |
29 | 31 | from app.schemas.user import UserUpdate |
| 32 | +from app.services import grades_service |
30 | 33 |
|
31 | 34 | router = APIRouter() |
32 | 35 |
|
@@ -140,3 +143,34 @@ def get_my_quest_progress( |
140 | 143 | ) -> list[QuestProgressSchema]: |
141 | 144 | """認証済みユーザー自身のクエスト進捗一覧取得。""" |
142 | 145 | return crud_quest_progress.get_quest_progress_by_user(db, current_user.id) |
| 146 | + |
| 147 | + |
| 148 | +@router.get("/me/grade-stats", response_model=GradeStatsSchema) |
| 149 | +def get_my_grade_stats( |
| 150 | + db: Session = Depends(get_db), |
| 151 | + current_user: User = Depends(get_current_user), |
| 152 | +) -> GradeStatsSchema: |
| 153 | + """認証済みユーザー自身の成績統計情報を取得。""" |
| 154 | + # 連続記録日数を取得 |
| 155 | + consecutive_days = grades_service.get_consecutive_days(db, current_user.id) |
| 156 | + |
| 157 | + # 修了したクエスト数を取得 |
| 158 | + completed_quests = grades_service.get_completed_quests_count(db, current_user.id) |
| 159 | + |
| 160 | + # 最も進捗が高いカテゴリを取得 |
| 161 | + category, _ = grades_service.get_highest_progress_category(db, current_user.id) |
| 162 | + |
| 163 | + # 最高ランク情報を構築(現在の実装では全体で一つのrankを使用) |
| 164 | + highest_rank = HighestRankSchema( |
| 165 | + rank=current_user.rank, |
| 166 | + category=category, |
| 167 | + category_name=grades_service.CATEGORY_NAMES.get(category, "総合"), |
| 168 | + rank_name=grades_service.RANK_NAMES.get(current_user.rank, "種子"), |
| 169 | + color=grades_service.CATEGORY_COLORS.get(category, "#55aaff"), |
| 170 | + ) |
| 171 | + |
| 172 | + return GradeStatsSchema( |
| 173 | + consecutive_days=consecutive_days, |
| 174 | + completed_quests=completed_quests, |
| 175 | + highest_rank=highest_rank, |
| 176 | + ) |
0 commit comments