mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init assignments UI and fix bugs
This commit is contained in:
parent
10e9be1d33
commit
6a4e16ec29
16 changed files with 436 additions and 47 deletions
|
|
@ -0,0 +1,31 @@
|
|||
"""Add reference for AssignmentTasks
|
||||
|
||||
Revision ID: d8bc71595932
|
||||
Revises: 6295e05ff7d0
|
||||
Create Date: 2024-07-12 18:59:50.242716
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlmodel
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'd8bc71595932'
|
||||
down_revision: Union[str, None] = '6295e05ff7d0'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('assignmenttask', sa.Column('reference_file', sa.VARCHAR(), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('assignmenttask', 'reference_file')
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -29,8 +29,8 @@ class ActivitySubTypeEnum(str, Enum):
|
|||
|
||||
class ActivityBase(SQLModel):
|
||||
name: str
|
||||
activity_type: ActivityTypeEnum = ActivityTypeEnum.TYPE_CUSTOM
|
||||
activity_sub_type: ActivitySubTypeEnum = ActivitySubTypeEnum.SUBTYPE_CUSTOM
|
||||
activity_type: ActivityTypeEnum
|
||||
activity_sub_type: ActivitySubTypeEnum
|
||||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
published: bool = False
|
||||
|
||||
|
|
@ -51,12 +51,16 @@ class Activity(ActivityBase, table=True):
|
|||
|
||||
class ActivityCreate(ActivityBase):
|
||||
chapter_id: int
|
||||
activity_type: ActivityTypeEnum = ActivityTypeEnum.TYPE_CUSTOM
|
||||
activity_sub_type: ActivitySubTypeEnum = ActivitySubTypeEnum.SUBTYPE_CUSTOM
|
||||
pass
|
||||
|
||||
|
||||
class ActivityUpdate(ActivityBase):
|
||||
name: Optional[str]
|
||||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
activity_type: Optional[ActivityTypeEnum]
|
||||
activity_sub_type: Optional[ActivitySubTypeEnum]
|
||||
published_version: Optional[int]
|
||||
version: Optional[int]
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ class AssignmentTaskBase(SQLModel):
|
|||
title: str
|
||||
description: str
|
||||
hint: str
|
||||
reference_file: Optional[str]
|
||||
assignment_type: AssignmentTaskTypeEnum
|
||||
contents: Dict = Field(default={}, sa_column=Column(JSON))
|
||||
max_grade_value: int = 0 # Value is always between 0-100
|
||||
|
|
@ -108,7 +109,7 @@ class AssignmentTaskBase(SQLModel):
|
|||
activity_id: int
|
||||
|
||||
|
||||
class AssignmentTaskCreate(AssignmentTaskBase ):
|
||||
class AssignmentTaskCreate(AssignmentTaskBase):
|
||||
"""Model for creating a new assignment task."""
|
||||
|
||||
pass # Inherits all fields from AssignmentTaskBase
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from src.services.courses.activities.assignments import (
|
|||
delete_assignment_task,
|
||||
delete_assignment_task_submission,
|
||||
read_assignment,
|
||||
read_assignment_from_activity_uuid,
|
||||
read_assignment_submissions,
|
||||
read_assignment_task_submissions,
|
||||
read_assignment_tasks,
|
||||
|
|
@ -62,6 +63,18 @@ async def api_read_assignment(
|
|||
"""
|
||||
return await read_assignment(request, assignment_uuid, current_user, db_session)
|
||||
|
||||
@router.get("/activity/{activity_uuid}")
|
||||
async def api_read_assignment_from_activity(
|
||||
request: Request,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
db_session=Depends(get_db_session),
|
||||
) -> AssignmentRead:
|
||||
"""
|
||||
Read an assignment
|
||||
"""
|
||||
return await read_assignment_from_activity_uuid(request, activity_uuid, current_user, db_session)
|
||||
|
||||
|
||||
@router.put("/{assignment_uuid}")
|
||||
async def api_update_assignment(
|
||||
|
|
|
|||
|
|
@ -104,6 +104,48 @@ async def read_assignment(
|
|||
# return assignment read
|
||||
return AssignmentRead.model_validate(assignment)
|
||||
|
||||
async def read_assignment_from_activity_uuid(
|
||||
request: Request,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
# Check if activity exists
|
||||
statement = select(Activity).where(Activity.activity_uuid == activity_uuid)
|
||||
activity = db_session.exec(statement).first()
|
||||
|
||||
if not activity:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Activity not found",
|
||||
)
|
||||
|
||||
# Check if course exists
|
||||
statement = select(Course).where(Course.id == activity.course_id)
|
||||
course = db_session.exec(statement).first()
|
||||
|
||||
if not course:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Course not found",
|
||||
)
|
||||
|
||||
# Check if assignment exists
|
||||
statement = select(Assignment).where(Assignment.activity_id == activity.id)
|
||||
assignment = db_session.exec(statement).first()
|
||||
|
||||
if not assignment:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Assignment not found",
|
||||
)
|
||||
|
||||
# RBAC check
|
||||
await rbac_check(request, course.course_uuid, current_user, "read", db_session)
|
||||
|
||||
# return assignment read
|
||||
return AssignmentRead.model_validate(assignment)
|
||||
|
||||
|
||||
async def update_assignment(
|
||||
request: Request,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue