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") def update_clinic_status(req:Request, data: ClinicStatusUpdate): response = ClinicServices().update_clinic_status(req.state.user, data.clinic_id, data.status, data.documentStatus, data.rejection_reason) return ApiResponse(data=response, message="Clinic status updated successfully") @router.post("/user") def create_user(req:Request, user_data: CreateSuperAdmin): AuthService().create_super_admin(req.state.user, user_data) return ApiResponse(data="OK", message="User created successfully") @router.put("/user/{user_id}") def update_user(req:Request, user_id: int, user_data: UpdateSuperAdmin): AuthService().update_super_admin(req.state.user, user_id, user_data) return ApiResponse(data="OK", message="User updated successfully") @router.delete("/user/{user_id}") def delete_user(req:Request, user_id: int): AuthService().delete_super_admin(req.state.user, user_id) return ApiResponse(data="OK", message="User deleted successfully") @router.get("/") 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 = AuthService().get_admins(req.state.user, limit, offset, search) return ApiResponse(data=users, message="Users retrieved successfully") @router.post("/master-data") def create_master_data(appointment_type: MasterAppointmentTypeBase): MasterAppointmentServices().create_master_appointment_type(appointment_type) return ApiResponse(data="OK", message="Master data created successfully") @router.delete("/master-data/{master_appointment_type_id}") def delete_master_data(master_appointment_type_id: int): 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}") def update_master_data(master_appointment_type_id: int, appointment_type: MasterAppointmentTypeBase): MasterAppointmentServices().update_master_appointment_type(master_appointment_type_id, appointment_type) return ApiResponse(data="OK", message="Master data updated successfully") @router.get("/master-data") def get_master_data(): appointment_types = 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 = 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 ): 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 ): 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 ): ClinicServices().delete_clinic_offer(req.state.user, clinic_offer_id) return ApiResponse(data="OK", message="Clinic offer deleted successfully")