File size: 1,306 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
from cruds.base import CRUDBase
from schemas import TeacherNoteCreate, TeacherNoteUpdate
from schemas.teacher_note import TeacherNoteBase as TeacherNoteSchema
from models.teacher_note import TeacherNote
from typing import Any, List

from cruds.base import CRUDBase
from cruds.user import crud_user
from models import ClassSession
from models import User
from schemas import ClassSessionCreate, ClassSessionUpdate
from sqlalchemy.orm import Session
from core.config import settings


class CRUDTeacherNote(CRUDBase[TeacherNote, TeacherNoteCreate, TeacherNoteUpdate]):
    def create_with_user(self, db: Session, *, obj_in: TeacherNoteCreate, user: User):
        obj_in = TeacherNoteSchema(user_id=user.id, **obj_in)
        return self.create(db=db, obj_in=obj_in)

    def get_user_teacher_note(self, db: Session, user: User, id: int = None):
        teacher_notes = db.query(self.model)
        if id:
            teacher_notes = (
                teacher_notes.filter(TeacherNote.id == id)
                .filter(TeacherNote.user_id == user.id)
                .first()
            )
            return teacher_notes
        else:
            teacher_notes = teacher_notes.filter(TeacherNote.user_id == user.id).all()
            return teacher_notes


crud_teacher_note = CRUDTeacherNote(TeacherNote)