fix: async apis
This commit is contained in:
+22
-22
@@ -13,55 +13,55 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.put("/clinic/status")
|
||||
def update_clinic_status(req:Request, data: ClinicStatusUpdate):
|
||||
ClinicServices().update_clinic_status(req.state.user, data.clinic_id, data.status, data.documentStatus, data.rejection_reason)
|
||||
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")
|
||||
def create_user(req:Request, user_data: CreateSuperAdmin):
|
||||
AuthService().create_super_admin(req.state.user, user_data)
|
||||
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}")
|
||||
def update_user(req:Request, user_id: int, user_data: UpdateSuperAdmin):
|
||||
AuthService().update_super_admin(req.state.user, user_id, user_data)
|
||||
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}")
|
||||
def delete_user(req:Request, user_id: int):
|
||||
AuthService().delete_super_admin(req.state.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("/")
|
||||
def get_users(req:Request, limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = ""):
|
||||
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 = AuthService().get_admins(req.state.user, limit, offset, search)
|
||||
users = await 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)
|
||||
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}")
|
||||
def delete_master_data(master_appointment_type_id: int):
|
||||
MasterAppointmentServices().delete_master_appointment_type(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}")
|
||||
def update_master_data(master_appointment_type_id: int, appointment_type: MasterAppointmentTypeBase):
|
||||
MasterAppointmentServices().update_master_appointment_type(master_appointment_type_id, appointment_type)
|
||||
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")
|
||||
def get_master_data():
|
||||
appointment_types = MasterAppointmentServices().get_master_appointment_types()
|
||||
async def get_master_data():
|
||||
appointment_types = await MasterAppointmentServices().get_master_appointment_types()
|
||||
return ApiResponse(data=appointment_types, message="Master data retrieved successfully")
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ async def get_clinic_offers(
|
||||
page = 1
|
||||
offset = (page - 1) * limit
|
||||
|
||||
clinic_offers = ClinicServices().get_clinic_offers(req.state.user, limit, offset, search)
|
||||
clinic_offers = await ClinicServices().get_clinic_offers(req.state.user, limit, offset, search)
|
||||
return ApiResponse(data=clinic_offers, message="Clinic offers retrieved successfully")
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ async def create_clinic_offer(
|
||||
req:Request,
|
||||
clinic_offer: ClinicOffersBase
|
||||
):
|
||||
ClinicServices().create_clinic_offer(req.state.user, clinic_offer)
|
||||
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}")
|
||||
@@ -95,7 +95,7 @@ async def update_clinic_offer(
|
||||
clinic_offer_id: int,
|
||||
clinic_offer: ClinicOffersBase
|
||||
):
|
||||
ClinicServices().update_clinic_offer(req.state.user, clinic_offer_id, clinic_offer)
|
||||
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}")
|
||||
@@ -103,6 +103,6 @@ async def delete_clinic_offer(
|
||||
req:Request,
|
||||
clinic_offer_id: int
|
||||
):
|
||||
ClinicServices().delete_clinic_offer(req.state.user, clinic_offer_id)
|
||||
await ClinicServices().delete_clinic_offer(req.state.user, clinic_offer_id)
|
||||
return ApiResponse(data="OK", message="Clinic offer deleted successfully")
|
||||
|
||||
+18
-16
@@ -4,13 +4,12 @@ from schemas.CreateSchemas import UserCreate
|
||||
from schemas.ApiResponse import ApiResponse
|
||||
from schemas.BaseSchemas import AuthBase, AuthOTP, ResetPasswordBase
|
||||
from services.clinicServices import ClinicServices
|
||||
from http import HTTPStatus
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/login")
|
||||
def login(data: AuthBase):
|
||||
token = AuthService().login(data)
|
||||
async def login(data: AuthBase):
|
||||
token = await AuthService().login(data)
|
||||
return ApiResponse(
|
||||
data=token,
|
||||
message="Login successful"
|
||||
@@ -18,16 +17,16 @@ def login(data: AuthBase):
|
||||
|
||||
|
||||
@router.post("/register")
|
||||
def register(user_data: UserCreate, background_tasks: BackgroundTasks):
|
||||
token = AuthService().register(user_data, background_tasks)
|
||||
async def register(user_data: UserCreate, background_tasks: BackgroundTasks):
|
||||
token = await AuthService().register(user_data, background_tasks)
|
||||
return ApiResponse(
|
||||
data=token,
|
||||
message="User registered successfully"
|
||||
)
|
||||
|
||||
@router.get("/clinic/latest-id")
|
||||
def get_latest_clinic_id():
|
||||
clinic_id = ClinicServices().get_latest_clinic_id()
|
||||
async def get_latest_clinic_id():
|
||||
clinic_id = await ClinicServices().get_latest_clinic_id()
|
||||
return ApiResponse(
|
||||
data=clinic_id,
|
||||
message="Latest clinic ID retrieved successfully"
|
||||
@@ -35,24 +34,27 @@ def get_latest_clinic_id():
|
||||
|
||||
|
||||
@router.post('/admin/forget-password')
|
||||
def forget_password(email: str):
|
||||
AuthService().forget_password(email)
|
||||
async def forget_password(email: str):
|
||||
await AuthService().forget_password(email)
|
||||
return ApiResponse(data="OK", message="Password reset email sent successfully")
|
||||
|
||||
@router.post('/admin/reset-password')
|
||||
def reset_password(data: ResetPasswordBase):
|
||||
AuthService().reset_password(data.token, data.password)
|
||||
async def reset_password(data: ResetPasswordBase):
|
||||
await AuthService().reset_password(data.token, data.password)
|
||||
return ApiResponse(data="OK", message="Password reset successfully")
|
||||
|
||||
|
||||
@router.post("/send-otp")
|
||||
def send_otp(email: str):
|
||||
AuthService().send_otp(email)
|
||||
return HTTPStatus.OK
|
||||
async def send_otp(email: str):
|
||||
await AuthService().send_otp(email)
|
||||
return ApiResponse(
|
||||
data="OK",
|
||||
message="OTP sent successfully"
|
||||
)
|
||||
|
||||
@router.post("/verify-otp")
|
||||
def verify_otp(data: AuthOTP):
|
||||
AuthService().verify_otp(data)
|
||||
async def verify_otp(data: AuthOTP):
|
||||
await AuthService().verify_otp(data)
|
||||
return ApiResponse(
|
||||
data="OK",
|
||||
message="OTP verified successfully"
|
||||
|
||||
@@ -7,15 +7,15 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def get_call_transcripts(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE):
|
||||
async def get_call_transcripts(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE):
|
||||
if page == 0:
|
||||
page = 1
|
||||
offset = (page - 1) * limit
|
||||
response = CallTranscriptServices().get_call_transcripts(limit, offset)
|
||||
response = await CallTranscriptServices().get_call_transcripts(limit, offset)
|
||||
return ApiResponse(data=response, message="Call transcripts retrieved successfully")
|
||||
|
||||
@router.post("/bulk-download")
|
||||
def bulk_download_call_transcripts(key_ids: list[int], background_tasks: BackgroundTasks):
|
||||
async def bulk_download_call_transcripts(key_ids: list[int], background_tasks: BackgroundTasks):
|
||||
service = CallTranscriptServices()
|
||||
response = service.bulk_download_call_transcripts(key_ids, background_tasks)
|
||||
response = await service.bulk_download_call_transcripts(key_ids, background_tasks)
|
||||
return response
|
||||
@@ -7,21 +7,21 @@ from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
def get_clinic_doctors():
|
||||
clinic_doctors = ClinicDoctorsServices().get_clinic_doctors()
|
||||
async def get_clinic_doctors():
|
||||
clinic_doctors = await ClinicDoctorsServices().get_clinic_doctors()
|
||||
return ApiResponse(data=clinic_doctors, message="Clinic doctors retrieved successfully")
|
||||
|
||||
@router.post("/")
|
||||
def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
||||
clinic_doctor = ClinicDoctorsServices().create_clinic_doctor(clinic_doctor)
|
||||
async def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
||||
clinic_doctor = await ClinicDoctorsServices().create_clinic_doctor(clinic_doctor)
|
||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor created successfully")
|
||||
|
||||
@router.put("/{clinic_doctor_id}")
|
||||
def update_clinic_doctor(clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
||||
clinic_doctor = ClinicDoctorsServices().update_clinic_doctor(clinic_doctor_id, clinic_doctor)
|
||||
async def update_clinic_doctor(clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
||||
clinic_doctor = await ClinicDoctorsServices().update_clinic_doctor(clinic_doctor_id, clinic_doctor)
|
||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor updated successfully")
|
||||
|
||||
@router.delete("/{clinic_doctor_id}")
|
||||
def delete_clinic_doctor(clinic_doctor_id: int):
|
||||
ClinicDoctorsServices().delete_clinic_doctor(clinic_doctor_id)
|
||||
async def delete_clinic_doctor(clinic_doctor_id: int):
|
||||
await ClinicDoctorsServices().delete_clinic_doctor(clinic_doctor_id)
|
||||
return ApiResponse(data="OK", message="Clinic doctor deleted successfully")
|
||||
@@ -28,17 +28,17 @@ async def get_clinics(
|
||||
if page < 1:
|
||||
page = 1
|
||||
offset = (page - 1) * limit
|
||||
clinics = ClinicServices().get_clinics(req.state.user, limit, offset, filter_type, search)
|
||||
clinics = await ClinicServices().get_clinics(req.state.user, limit, offset, filter_type, search)
|
||||
return ApiResponse(data=clinics, message="Clinics retrieved successfully" )
|
||||
|
||||
@router.get("/verified-files/{clinic_id}")
|
||||
async def get_verified_files(clinic_id: int):
|
||||
clinic = ClinicServices().get_clinic_by_id(clinic_id)
|
||||
clinic = await ClinicServices().get_clinic_by_id(clinic_id)
|
||||
return ApiResponse(data=clinic, message="Clinic retrieved successfully")
|
||||
|
||||
@router.get("/{clinic_id}")
|
||||
async def get_clinic(clinic_id: int):
|
||||
clinic = ClinicServices().get_clinic_by_id(clinic_id)
|
||||
clinic = await ClinicServices().get_clinic_by_id(clinic_id)
|
||||
return ApiResponse(data=clinic, message="Clinic retrieved successfully")
|
||||
|
||||
@router.put("/{clinic_id}")
|
||||
@@ -46,10 +46,10 @@ async def update_clinic(
|
||||
req:Request,
|
||||
clinic_id: int, clinic: ClinicUpdate
|
||||
):
|
||||
clinic = ClinicServices().update_clinic(req.state.user, clinic_id, clinic)
|
||||
clinic = await ClinicServices().update_clinic(req.state.user, clinic_id, clinic)
|
||||
return ApiResponse(data=clinic, message="Clinic updated successfully")
|
||||
|
||||
@router.delete("/{clinic_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_clinic(clinic_id: int):
|
||||
ClinicServices().delete_clinic(clinic_id)
|
||||
await ClinicServices().delete_clinic(clinic_id)
|
||||
return ApiResponse(data="OK", message="Clinic deleted successfully")
|
||||
|
||||
@@ -8,17 +8,17 @@ router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
async def get_clinic_doctor_status_count(req:Request):
|
||||
counts = DashboardService().get_dashboard_counts(isSuperAdmin=req.state.user["userType"] == UserType.SUPER_ADMIN)
|
||||
counts = await DashboardService().get_dashboard_counts(isSuperAdmin=req.state.user["userType"] == UserType.SUPER_ADMIN)
|
||||
return ApiResponse(data=counts, message="Counts fetched successfully")
|
||||
|
||||
@router.post("/signup-pricing-master")
|
||||
async def update_signup_pricing_master(req:Request, signup_pricing_master:SignupPricingMasterCreate):
|
||||
user = req.state.user
|
||||
response = DashboardService().update_signup_pricing_master(user, signup_pricing_master)
|
||||
response = await DashboardService().update_signup_pricing_master(user, signup_pricing_master)
|
||||
return ApiResponse(data=response, message="Signup pricing master updated successfully")
|
||||
|
||||
|
||||
@router.get("/signup-pricing-master")
|
||||
async def get_signup_pricing_master():
|
||||
pricing = DashboardService().get_signup_pricing_master()
|
||||
pricing = await DashboardService().get_signup_pricing_master()
|
||||
return ApiResponse(data=pricing, message="Signup pricing master fetched successfully")
|
||||
|
||||
@@ -8,10 +8,7 @@ from schemas.CreateSchemas import S3Create
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/")
|
||||
def upload_file(data:S3Create):
|
||||
try:
|
||||
resp = upload_file_service(data.folder, data.file_name)
|
||||
return ApiResponse(data=resp, message="File uploaded successfully")
|
||||
except Exception as e:
|
||||
logger.error(f"Error uploading file: {str(e)}")
|
||||
raise e
|
||||
async def upload_file(data:S3Create):
|
||||
|
||||
resp = await upload_file_service(data.folder, data.file_name)
|
||||
return ApiResponse(data=resp, message="File uploaded successfully")
|
||||
|
||||
+12
-12
@@ -9,12 +9,12 @@ from utils.constants import DEFAULT_LIMIT, DEFAULT_PAGE
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
def get_users(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = ""):
|
||||
async def get_users(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = ""):
|
||||
if page == 0:
|
||||
page = 1
|
||||
offset = (page - 1) * limit
|
||||
|
||||
user = UserServices().get_users(limit, offset, search)
|
||||
user = await UserServices().get_users(limit, offset, search)
|
||||
|
||||
return ApiResponse(
|
||||
data=user,
|
||||
@@ -22,10 +22,10 @@ def get_users(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = "
|
||||
)
|
||||
|
||||
@router.get("/me")
|
||||
def get_user(request: Request):
|
||||
async def get_user(request: Request):
|
||||
try:
|
||||
user_id = request.state.user["id"]
|
||||
user = UserServices().get_user(user_id)
|
||||
user = await UserServices().get_user(user_id)
|
||||
return ApiResponse(
|
||||
data=user,
|
||||
message="User fetched successfully"
|
||||
@@ -35,34 +35,34 @@ def get_user(request: Request):
|
||||
raise e
|
||||
|
||||
@router.get("/{user_id}")
|
||||
def get_user(request: Request, user_id: int):
|
||||
user = UserServices().get_user(user_id)
|
||||
async def get_user(request: Request, user_id: int):
|
||||
user = await UserServices().get_user(user_id)
|
||||
return ApiResponse(
|
||||
data=user,
|
||||
message="User fetched successfully"
|
||||
)
|
||||
|
||||
@router.delete("/")
|
||||
def delete_user(request: Request):
|
||||
async def delete_user(request: Request):
|
||||
user_id = request.state.user["id"]
|
||||
UserServices().delete_user(user_id)
|
||||
await UserServices().delete_user(user_id)
|
||||
return ApiResponse(
|
||||
data="OK",
|
||||
message="User deleted successfully"
|
||||
)
|
||||
|
||||
@router.put("/")
|
||||
def update_user(request: Request, user_data: UserUpdate):
|
||||
async def update_user(request: Request, user_data: UserUpdate):
|
||||
user_id = request.state.user["id"]
|
||||
user = UserServices().update_user(user_id, user_data)
|
||||
user = await UserServices().update_user(user_id, user_data)
|
||||
return ApiResponse(
|
||||
data=user,
|
||||
message="User updated successfully"
|
||||
)
|
||||
|
||||
@router.put("/{user_id}")
|
||||
def update_user(request: Request, user_id: int, user_data: UserUpdate):
|
||||
user = UserServices().update_user(user_id, user_data)
|
||||
async def update_user(request: Request, user_id: int, user_data: UserUpdate):
|
||||
user = await UserServices().update_user(user_id, user_data)
|
||||
return ApiResponse(
|
||||
data=user,
|
||||
message="User updated successfully"
|
||||
|
||||
Reference in New Issue
Block a user