29 lines
949 B
Python
29 lines
949 B
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.doctor import Doctor
|
|
from app.schemas.doctor import DoctorCreate, DoctorUpdate
|
|
|
|
|
|
class CRUDDoctor(CRUDBase[Doctor, DoctorCreate, DoctorUpdate]):
|
|
def get_by_user_id(self, db: Session, *, user_id: int) -> Optional[Doctor]:
|
|
return db.query(Doctor).filter(Doctor.user_id == user_id).first()
|
|
|
|
def get_by_license_number(self, db: Session, *, license_number: str) -> Optional[Doctor]:
|
|
return db.query(Doctor).filter(Doctor.license_number == license_number).first()
|
|
|
|
def get_multi_by_specialty(
|
|
self, db: Session, *, specialty: str, skip: int = 0, limit: int = 100
|
|
) -> List[Doctor]:
|
|
return (
|
|
db.query(Doctor)
|
|
.filter(Doctor.specialty == specialty)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
doctor = CRUDDoctor(Doctor) |