Implement Task 16: Murphy Grammar Engine & Handwritten Journaling
This commit is contained in:
1 parent
3fae321322
commit
4d58002b48
11 files changed
+3267
-10
No files matched your search
+97
@@ -37,6 +37,14 @@ from app.cefr import (
|
||||
process_cefr_answer,
|
||||
reset_user_cefr_level,
|
||||
)
|
||||
from app.grammar import (
|
||||
get_grammar_units_list,
|
||||
get_grammar_unit_detail,
|
||||
process_grammar_answer,
|
||||
record_grammar_completion,
|
||||
update_handwritten_status,
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -177,6 +185,24 @@ class CefrResetRequest(BaseModel):
|
||||
level: str
|
||||
|
||||
|
||||
class GrammarAnswerRequest(BaseModel):
|
||||
unit_id: int
|
||||
exercise_idx: int
|
||||
selected_option: str
|
||||
|
||||
|
||||
class GrammarCompleteRequest(BaseModel):
|
||||
unit_id: int
|
||||
score: int = Field(..., ge=0, le=100)
|
||||
handwritten_logged: bool = False
|
||||
|
||||
|
||||
class GrammarHandwrittenRequest(BaseModel):
|
||||
unit_id: int
|
||||
handwritten: bool
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1439,3 +1465,74 @@ async def api_cefr_reset(
|
||||
deleted = reset_user_cefr_level(conn, user["id"], req.level)
|
||||
return {"status": "ok", "level": req.level.upper(), "reset_count": deleted}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Task 16: Murphy Grammar Engine & Handwritten Journaling Endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@app.get("/api/grammar/units")
|
||||
async def api_grammar_units(user: dict = Depends(require_user)):
|
||||
"""
|
||||
Returns the list of all curated Murphy grammar units with user progress.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
units = get_grammar_units_list(conn, user["id"])
|
||||
return {"units": units}
|
||||
|
||||
|
||||
@app.get("/api/grammar/units/{unit_id}")
|
||||
async def api_grammar_unit_detail(unit_id: int, user: dict = Depends(require_user)):
|
||||
"""
|
||||
Returns full content of a unit for lesson mode.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
unit = get_grammar_unit_detail(conn, user["id"], unit_id)
|
||||
if not unit:
|
||||
raise HTTPException(status_code=404, detail="Unit not found")
|
||||
return unit
|
||||
|
||||
|
||||
@app.post("/api/grammar/answer")
|
||||
async def api_grammar_answer(
|
||||
req: GrammarAnswerRequest,
|
||||
user: dict = Depends(require_user),
|
||||
):
|
||||
"""
|
||||
Checks answer for a Cloze Tap grammar exercise.
|
||||
If wrong, performs automated gap ingestion into active SRS vocabulary.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
result = process_grammar_answer(
|
||||
conn, user["id"], req.unit_id, req.exercise_idx, req.selected_option
|
||||
)
|
||||
if "error" in result:
|
||||
raise HTTPException(status_code=404, detail=result["error"])
|
||||
return result
|
||||
|
||||
|
||||
@app.post("/api/grammar/complete")
|
||||
async def api_grammar_complete(
|
||||
req: GrammarCompleteRequest,
|
||||
user: dict = Depends(require_user),
|
||||
):
|
||||
"""
|
||||
Records completion of a grammar unit and user's score.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
return record_grammar_completion(
|
||||
conn, user["id"], req.unit_id, req.score, req.handwritten_logged
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/grammar/handwritten")
|
||||
async def api_grammar_handwritten(
|
||||
req: GrammarHandwrittenRequest,
|
||||
user: dict = Depends(require_user),
|
||||
):
|
||||
"""
|
||||
Toggles handwritten paper notebook checkbox for a unit.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
return update_handwritten_status(conn, user["id"], req.unit_id, req.handwritten)
|
||||
|
||||
|
||||
Reference in new issue
Block a user