bb9e0905f2
organic 사용 0 진단(트리거 없음·due 산더미·반복 감각 부재) 대응 3조각: - 오늘의 몫: /api/study/daily (문제5·카드5·개념1·검수3, 가용량 보정) + /study 홈 최상단 체크리스트/완료 상태. 진도·복습 백로그는 접이식 강등(무변경+cap, D2). - 스트릭/잔디: KST 일 단위 활동 집계(attempts+document_reads+카드평가 근사). - 아침 리마인더: study_reminder 09 KST 슬롯 한정 Synology Chat incoming webhook (STUDY_REMINDER_WEBHOOK_URL, 빈 값=off, 몫 완료 시 skip). 07-01 push 폐기 결정의 flip 조건(홈 pull 실패) 충족에 따른 사용자 합의 D1. - 마이그 383: study_memo_cards.reviewed_at (검수 처리 집계용, 승인/수정확정/폐기 시 박힘). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
108 lines
3.8 KiB
Python
108 lines
3.8 KiB
Python
"""study_concepts API — 이론공부 홈(오늘의 개념 · 진도 · 회독 SR). prefix = /api/study.
|
|
|
|
문제풀이 표면 무접촉. 개념문서(가스기사 태그) 읽기 집계 + 회독 SR write 만. 단일 토픽(가스기사=4).
|
|
경로: GET /curriculum · GET /today-concepts · POST /concepts/{doc_id}/read.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from core.auth import get_current_user
|
|
from core.database import get_session
|
|
from models.user import User
|
|
from services.study import concept_curriculum as cc
|
|
from services.study import concept_links as cl
|
|
from services.study import daily_unit as du
|
|
|
|
router = APIRouter()
|
|
|
|
# 가스기사 단일 토픽 운영(현행). 다토픽 확장 시 쿼리 파라미터로 승격.
|
|
DEFAULT_TOPIC_ID = 4
|
|
|
|
|
|
@router.get("/daily")
|
|
async def get_daily(
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
):
|
|
"""오늘의 몫(유한한 데일리 단위) + 스트릭/잔디 — 습관 루프 홈 재료. read-only."""
|
|
state = await du.daily_state(session, user.id, topic_id)
|
|
sg = await du.streak_and_grass(session, user.id)
|
|
return {**state, **sg}
|
|
|
|
|
|
@router.get("/curriculum")
|
|
async def get_curriculum(
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
):
|
|
"""과목별 회독 진도 + 개념/문항 복습 due 요약."""
|
|
return await cc.curriculum(session, user.id, topic_id)
|
|
|
|
|
|
@router.get("/today-concepts")
|
|
async def get_today_concepts(
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
limit: int = 6,
|
|
):
|
|
"""오늘 공부할 개념(재복습 → 미독 빈출순)."""
|
|
return await cc.today_concepts(session, user.id, topic_id, limit)
|
|
|
|
|
|
@router.get("/concepts/weakness-map")
|
|
async def get_weakness_map(
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
limit: int = 12,
|
|
):
|
|
"""개념 약점 지도 — 링크된 기출 정답률로 약점 개념(정답률<60%) 우선(이론↔문제)."""
|
|
name = await cc._topic_name(session, topic_id)
|
|
if not name:
|
|
return {"weak": [], "weak_total": 0, "evaluated_total": 0}
|
|
return await cl.weakness_map(session, user.id, name, limit)
|
|
|
|
|
|
@router.get("/concepts/{doc_id}")
|
|
async def get_concept_detail(
|
|
doc_id: int,
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
):
|
|
"""개념 리더 재료 — 구조 파싱(요약/본문/빈출/관련) + 백링크 해소 + 회독/SR + 이전/다음."""
|
|
detail = await cc.concept_detail(session, user.id, topic_id, doc_id)
|
|
if detail is None:
|
|
raise HTTPException(status_code=404, detail="concept not found")
|
|
return detail
|
|
|
|
|
|
@router.get("/concepts/{doc_id}/questions")
|
|
async def get_concept_questions(
|
|
doc_id: int,
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
limit: int = 20,
|
|
):
|
|
"""개념 관련 기출 + 내 정답률 (이론↔문제 브리지)."""
|
|
return await cl.related_questions(session, user.id, doc_id, limit)
|
|
|
|
|
|
@router.post("/concepts/{doc_id}/read")
|
|
async def post_concept_read(
|
|
doc_id: int,
|
|
user: Annotated[User, Depends(get_current_user)],
|
|
session: Annotated[AsyncSession, Depends(get_session)],
|
|
topic_id: int = DEFAULT_TOPIC_ID,
|
|
):
|
|
"""개념 회독 처리 → 회독 플래그 + SR 입고/전진."""
|
|
return await cc.mark_read(session, user.id, topic_id, doc_id)
|