Spaces:
Build error
Build error
File size: 1,902 Bytes
b7a7f32 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
from typing import Any, List
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from utils import deps
from cruds import crud_teacher_note
from schemas import TeacherNote, TeacherNoteUpdate, TeacherNoteCreate
router = APIRouter()
# TODO: Search by student ??
@router.get("/teacher_note/", response_model=List[TeacherNote])
async def get_teacher_note(
user=Depends(deps.get_current_active_teacher),
db: Session = Depends(deps.get_db),
skip: int = 0,
limit: int = 100,
) -> Any:
teacher_note = crud_teacher_note.get_user_teacher_note(db, user=user)
return teacher_note
# TODO: Teacher can only post notes on students that are his student
@router.post("/teacher_note/", response_model=TeacherNote)
async def create_teacher_note(
user=Depends(deps.get_current_active_teacher),
db: Session = Depends(deps.get_db),
*,
obj_in: TeacherNoteCreate
) -> Any:
teacher_note = crud_teacher_note.create(db, obj_in=obj_in)
return teacher_note
@router.get("/teacher_note/{id}/", response_model=TeacherNote)
async def get_specific_teacher_note(
user=Depends(deps.get_current_active_teacher),
db: Session = Depends(deps.get_db),
*,
id: int
) -> Any:
teacher_note = crud_teacher_note.get_user_teacher_note(db=db, user=user, id=id)
return teacher_note
@router.put("/teacher_note/{id}/", response_model=TeacherNote)
async def update_teacher_note(
user=Depends(deps.get_current_active_teacher),
db: Session = Depends(deps.get_db),
*,
id: int,
obj_in: TeacherNoteUpdate
) -> Any:
teacher_note = crud_teacher_note.get_user_teacher_note(db=db, user=user, id=id)
if not teacher_note:
raise HTTPException(status_code=403, detail="Error ID: 127") # Access denied!
teacher_note = crud_teacher_note.update(db, db_obj=teacher_note, obj_in=obj_in)
return teacher_note
|