fix: list api response
This commit is contained in:
parent
b6e390f77c
commit
287b6e5761
|
|
@ -6,6 +6,10 @@ from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/")
|
||||||
|
def get_clinic_doctors():
|
||||||
|
clinic_doctors = ClinicDoctorsServices().get_clinic_doctors()
|
||||||
|
return ApiResponse(data=clinic_doctors, message="Clinic doctors retrieved successfully")
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/")
|
||||||
def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,18 @@ from middleware.auth_dependency import auth_required
|
||||||
from services.userServices import UserServices
|
from services.userServices import UserServices
|
||||||
from schemas.ApiResponse import ApiResponse
|
from schemas.ApiResponse import ApiResponse
|
||||||
from schemas.UpdateSchemas import UserUpdate
|
from schemas.UpdateSchemas import UserUpdate
|
||||||
|
from utils.constants import DEFAULT_LIMIT, DEFAULT_PAGE
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_users():
|
async def get_users(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = ""):
|
||||||
user = await UserServices().get_users()
|
if page == 0:
|
||||||
|
page = 1
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
user = await UserServices().get_users(limit, offset, search)
|
||||||
|
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
message="User fetched successfully"
|
message="User fetched successfully"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from models import ClinicDoctors
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from services.clinicServices import ClinicServices
|
from services.clinicServices import ClinicServices
|
||||||
from exceptions import ResourceNotFoundException
|
from exceptions import ResourceNotFoundException
|
||||||
|
from interface.common_response import CommonResponse
|
||||||
|
|
||||||
class ClinicDoctorsServices:
|
class ClinicDoctorsServices:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -68,3 +69,12 @@ class ClinicDoctorsServices:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_clinic_doctors(self):
|
||||||
|
clinic_doctors = self.db.query(ClinicDoctors).all()
|
||||||
|
|
||||||
|
total = self.db.query(ClinicDoctors).count()
|
||||||
|
|
||||||
|
response = CommonResponse(data=[ClinicDoctorResponse(**clinic_doctor.__dict__.copy()) for clinic_doctor in clinic_doctors], total=total)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@ from models import Clinics
|
||||||
from enums.enums import ClinicStatus, UserType
|
from enums.enums import ClinicStatus, UserType
|
||||||
from schemas.UpdateSchemas import UserUpdate
|
from schemas.UpdateSchemas import UserUpdate
|
||||||
from exceptions.unauthorized_exception import UnauthorizedException
|
from exceptions.unauthorized_exception import UnauthorizedException
|
||||||
|
from interface.common_response import CommonResponse
|
||||||
from utils.password_utils import hash_password
|
from utils.password_utils import hash_password
|
||||||
from schemas.CreateSchemas import UserCreate
|
from schemas.CreateSchemas import UserCreate
|
||||||
from exceptions.resource_not_found_exception import ResourceNotFoundException
|
from exceptions.resource_not_found_exception import ResourceNotFoundException
|
||||||
|
|
@ -131,11 +132,14 @@ class UserServices:
|
||||||
Users.userType.contains(search)
|
Users.userType.contains(search)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
users = query.limit(limit).offset(offset).all()
|
users = query.limit(limit).offset(offset).all()
|
||||||
|
|
||||||
user_response = [UserResponse(**user.__dict__.copy()) for user in users]
|
total = self.db.query(Users).count()
|
||||||
|
|
||||||
return user_response
|
response = CommonResponse(data=[UserResponse(**user.__dict__.copy()) for user in users], total=total)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
async def get_user_by_email(self, email: str) -> UserResponse:
|
async def get_user_by_email(self, email: str) -> UserResponse:
|
||||||
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue