29 lines
939 B
Python
29 lines
939 B
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from department.models import Department
|
|
from fastapi import HTTPException
|
|
|
|
class DepartmentCreate:
|
|
def __init__(self,data,db=AsyncSession) -> None:
|
|
self.data=data
|
|
self.db=db
|
|
|
|
async def create_department(self):
|
|
try:
|
|
department=Department.create_department(self.db,self.data)
|
|
return department
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
class DepartmentGet(DepartmentCreate):
|
|
def __init__(self,department_id,db=AsyncSession) -> None:
|
|
self.department_id=department_id
|
|
super().__init__(None,self.db)
|
|
|
|
async def get_department_by_id(self):
|
|
try:
|
|
department=Department.get_department_by_id(self.db,self.department_id)
|
|
return department
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|