from fastapi import APIRouter, Request from services.clinicServices import ClinicServices from schemas.UpdateSchemas import ClinicStatusUpdate from schemas.ApiResponse import ApiResponse from schemas.BaseSchemas import MasterAppointmentTypeBase, ClinicOffersBase from services.authService import AuthService from services.masterAppointmentServices import MasterAppointmentServices from schemas.CreateSchemas import CreateSuperAdmin, UpdateSuperAdmin from utils.constants import DEFAULT_LIMIT, DEFAULT_PAGE router = APIRouter() @router.put("/clinic/status") async def update_clinic_status(req:Request, data: ClinicStatusUpdate): await ClinicServices().update_clinic_status(req.state.user, data.clinic_id, data.status, data.documentStatus, data.rejection_reason) return ApiResponse(data="OK", message="Clinic status updated successfully") @router.post("/user") async def create_user(req:Request, user_data: CreateSuperAdmin): await AuthService().create_super_admin(req.state.user, user_data) return ApiResponse(data="OK", message="User created successfully") @router.put("/user/{user_id}") async def update_user(req:Request, user_id: int, user_data: UpdateSuperAdmin): await AuthService().update_super_admin(req.state.user, user_id, user_data) return ApiResponse(data="OK", message="User updated successfully") @router.delete("/user/{user_id}") async def delete_user(req:Request, user_id: int): await AuthService().delete_super_admin(req.state.user, user_id) return ApiResponse(data="OK", message="User deleted successfully") @router.get("/") async def get_users(req:Request, limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = ""): if page < 1: page = 1 offset = (page - 1) * limit users = await AuthService().get_admins(req.state.user, limit, offset, search) return ApiResponse(data=users, message="Users retrieved successfully") @router.post("/master-data") async def create_master_data(appointment_type: MasterAppointmentTypeBase): await MasterAppointmentServices().create_master_appointment_type(appointment_type) return ApiResponse(data="OK", message="Master data created successfully") @router.delete("/master-data/{master_appointment_type_id}") async def delete_master_data(master_appointment_type_id: int): await MasterAppointmentServices().delete_master_appointment_type(master_appointment_type_id) return ApiResponse(data="OK", message="Master data deleted successfully") @router.put("/master-data/{master_appointment_type_id}") async def update_master_data(master_appointment_type_id: int, appointment_type: MasterAppointmentTypeBase): await MasterAppointmentServices().update_master_appointment_type(master_appointment_type_id, appointment_type) return ApiResponse(data="OK", message="Master data updated successfully") @router.get("/master-data") async def get_master_data(): appointment_types = await MasterAppointmentServices().get_master_appointment_types() return ApiResponse(data=appointment_types, message="Master data retrieved successfully") @router.get("/clinic/offers") async def get_clinic_offers( req:Request, page: int = DEFAULT_PAGE, limit: int = DEFAULT_LIMIT, search:str = "" ): if page < 1: page = 1 offset = (page - 1) * limit clinic_offers = await ClinicServices().get_clinic_offers(req.state.user, limit, offset, search) return ApiResponse(data=clinic_offers, message="Clinic offers retrieved successfully") @router.post("/clinic/offer") async def create_clinic_offer( req:Request, clinic_offer: ClinicOffersBase ): await ClinicServices().create_clinic_offer(req.state.user, clinic_offer) return ApiResponse(data="OK", message="Clinic offer created successfully") @router.put("/clinic/offer/{clinic_offer_id}") async def update_clinic_offer( req:Request, clinic_offer_id: int, clinic_offer: ClinicOffersBase ): await ClinicServices().update_clinic_offer(req.state.user, clinic_offer_id, clinic_offer) return ApiResponse(data="OK", message="Clinic offer updated successfully") @router.delete("/clinic/offer/{clinic_offer_id}") async def delete_clinic_offer( req:Request, clinic_offer_id: int ): await ClinicServices().delete_clinic_offer(req.state.user, clinic_offer_id) return ApiResponse(data="OK", message="Clinic offer deleted successfully")