diff --git a/app/api/schema/exercise.py b/app/api/schema/exercise.py index 4295a16..e736890 100644 --- a/app/api/schema/exercise.py +++ b/app/api/schema/exercise.py @@ -16,8 +16,9 @@ class ExerciseRead(ExerciseCreate): id: int -class ExerciseWithSkipUnlockTime(ExerciseRead): +class ExerciseWithUnlockTimestamps(ExerciseRead): skip_unlock_time: datetime + next_grading_allowed_at: datetime class SystemState(BaseModel): diff --git a/app/api/v1/exercise.py b/app/api/v1/exercise.py index d49dbc3..6dab2b7 100644 --- a/app/api/v1/exercise.py +++ b/app/api/v1/exercise.py @@ -8,7 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from app.api.schema.exercise import ExerciseRead, ExerciseCreate, TestCaseRead, TestCaseCreate, \ - ExerciseWithSkipUnlockTime + ExerciseWithUnlockTimestamps from app.db.database import get_session from app.db.model import Tan from app.db.model.exercise import Exercise, ExerciseProgress, Competition, TestCase @@ -21,10 +21,10 @@ @router.get("/current", - response_model=ExerciseWithSkipUnlockTime, + response_model=ExerciseWithUnlockTimestamps, status_code=status.HTTP_200_OK) async def get_current_exercise(tan_code: str, session: AsyncSession = Depends(get_session), - now: datetime = Depends(get_datetime_now)) -> ExerciseWithSkipUnlockTime | Response: + now: datetime = Depends(get_datetime_now)) -> ExerciseWithUnlockTimestamps | Response: statement = select(Tan).where(Tan.code == tan_code) result = await session.execute(statement) tan = result.scalars().first() @@ -69,8 +69,9 @@ async def get_current_exercise(tan_code: str, session: AsyncSession = Depends(ge result = await session.execute(stmt) exercise = result.scalars().first() - return ExerciseWithSkipUnlockTime(**exercise.to_dict(), - skip_unlock_time=(now + timedelta(minutes=exercise.skip_delay))) + return ExerciseWithUnlockTimestamps(**exercise.to_dict(), + skip_unlock_time=(now + timedelta(minutes=exercise.skip_delay)), + next_grading_allowed_at=now) else: stmt = (select(Exercise) .join(Competition, Competition.first_exercise_id == Exercise.id) @@ -92,15 +93,18 @@ async def get_current_exercise(tan_code: str, session: AsyncSession = Depends(ge await session.refresh(first_exercise) - return ExerciseWithSkipUnlockTime(**first_exercise.to_dict(), - skip_unlock_time=(now + timedelta(minutes=first_exercise.skip_delay))) + return ExerciseWithUnlockTimestamps(**first_exercise.to_dict(), + skip_unlock_time=(now + timedelta(minutes=first_exercise.skip_delay)), + next_grading_allowed_at=now) exercise, progress = exercise_and_progress logging.info(progress.start_time.tzinfo) - return ExerciseWithSkipUnlockTime(**exercise.to_dict(), - skip_unlock_time=(progress.start_time + timedelta(minutes=exercise.skip_delay))) + return ExerciseWithUnlockTimestamps(**exercise.to_dict(), + skip_unlock_time=( + progress.start_time + timedelta(minutes=exercise.skip_delay)), + next_grading_allowed_at=progress.next_grading_allowed_at) @router.post("/current/skip", status_code=status.HTTP_204_NO_CONTENT) diff --git a/tests/test_exercise.py b/tests/test_exercise.py index 61ecd8e..8e90929 100644 --- a/tests/test_exercise.py +++ b/tests/test_exercise.py @@ -68,6 +68,10 @@ def test_get_current_exercise(self): exercise_1 = dict(EXERCISES[1]) exercise_1["skip_unlock_time"] = datetime(year=2025, month=10, day=7, hour=19, minute=35, second=0).isoformat() + exercise_1["next_grading_allowed_at"] = datetime(year=2025, month=10, day=7, hour=19, minute=35, + second=0).isoformat() + + print(response.json()) assert response.status_code == 200 assert response.json() == exercise_1 @@ -90,6 +94,7 @@ def test_get_current_exercise_with_missing_current_progress_entry_1(self): exercise_2 = dict(EXERCISES[2]) exercise_2["skip_unlock_time"] = "2025-10-07T19:40:00Z" + exercise_2["next_grading_allowed_at"] = "2025-10-07T19:35:00Z" assert response.status_code == 200 assert response.json() == exercise_2 @@ -104,6 +109,7 @@ def test_get_current_exercise_with_missing_current_progress_entry_2(self): exercise_0 = dict(EXERCISES[0]) exercise_0["skip_unlock_time"] = "2025-10-07T19:40:00Z" + exercise_0["next_grading_allowed_at"] = "2025-10-07T19:35:00Z" assert response.status_code == 200 assert response.json() == exercise_0