fix: async apis
This commit is contained in:
parent
8159d34c65
commit
b2fb39ff87
|
|
@ -13,55 +13,55 @@ router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.put("/clinic/status")
|
@router.put("/clinic/status")
|
||||||
def update_clinic_status(req:Request, data: ClinicStatusUpdate):
|
async 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)
|
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")
|
return ApiResponse(data="OK", message="Clinic status updated successfully")
|
||||||
|
|
||||||
@router.post("/user")
|
@router.post("/user")
|
||||||
def create_user(req:Request, user_data: CreateSuperAdmin):
|
async def create_user(req:Request, user_data: CreateSuperAdmin):
|
||||||
AuthService().create_super_admin(req.state.user, user_data)
|
await AuthService().create_super_admin(req.state.user, user_data)
|
||||||
return ApiResponse(data="OK", message="User created successfully")
|
return ApiResponse(data="OK", message="User created successfully")
|
||||||
|
|
||||||
@router.put("/user/{user_id}")
|
@router.put("/user/{user_id}")
|
||||||
def update_user(req:Request, user_id: int, user_data: UpdateSuperAdmin):
|
async def update_user(req:Request, user_id: int, user_data: UpdateSuperAdmin):
|
||||||
AuthService().update_super_admin(req.state.user, user_id, user_data)
|
await AuthService().update_super_admin(req.state.user, user_id, user_data)
|
||||||
return ApiResponse(data="OK", message="User updated successfully")
|
return ApiResponse(data="OK", message="User updated successfully")
|
||||||
|
|
||||||
@router.delete("/user/{user_id}")
|
@router.delete("/user/{user_id}")
|
||||||
def delete_user(req:Request, user_id: int):
|
async def delete_user(req:Request, user_id: int):
|
||||||
AuthService().delete_super_admin(req.state.user, user_id)
|
await AuthService().delete_super_admin(req.state.user, user_id)
|
||||||
return ApiResponse(data="OK", message="User deleted successfully")
|
return ApiResponse(data="OK", message="User deleted successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@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:
|
if page < 1:
|
||||||
page = 1
|
page = 1
|
||||||
offset = (page - 1) * limit
|
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")
|
return ApiResponse(data=users, message="Users retrieved successfully")
|
||||||
|
|
||||||
@router.post("/master-data")
|
@router.post("/master-data")
|
||||||
def create_master_data(appointment_type: MasterAppointmentTypeBase):
|
async def create_master_data(appointment_type: MasterAppointmentTypeBase):
|
||||||
MasterAppointmentServices().create_master_appointment_type(appointment_type)
|
await MasterAppointmentServices().create_master_appointment_type(appointment_type)
|
||||||
return ApiResponse(data="OK", message="Master data created successfully")
|
return ApiResponse(data="OK", message="Master data created successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/master-data/{master_appointment_type_id}")
|
@router.delete("/master-data/{master_appointment_type_id}")
|
||||||
def delete_master_data(master_appointment_type_id: int):
|
async def delete_master_data(master_appointment_type_id: int):
|
||||||
MasterAppointmentServices().delete_master_appointment_type(master_appointment_type_id)
|
await MasterAppointmentServices().delete_master_appointment_type(master_appointment_type_id)
|
||||||
return ApiResponse(data="OK", message="Master data deleted successfully")
|
return ApiResponse(data="OK", message="Master data deleted successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.put("/master-data/{master_appointment_type_id}")
|
@router.put("/master-data/{master_appointment_type_id}")
|
||||||
def update_master_data(master_appointment_type_id: int, appointment_type: MasterAppointmentTypeBase):
|
async def update_master_data(master_appointment_type_id: int, appointment_type: MasterAppointmentTypeBase):
|
||||||
MasterAppointmentServices().update_master_appointment_type(master_appointment_type_id, appointment_type)
|
await MasterAppointmentServices().update_master_appointment_type(master_appointment_type_id, appointment_type)
|
||||||
return ApiResponse(data="OK", message="Master data updated successfully")
|
return ApiResponse(data="OK", message="Master data updated successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/master-data")
|
@router.get("/master-data")
|
||||||
def get_master_data():
|
async def get_master_data():
|
||||||
appointment_types = MasterAppointmentServices().get_master_appointment_types()
|
appointment_types = await MasterAppointmentServices().get_master_appointment_types()
|
||||||
return ApiResponse(data=appointment_types, message="Master data retrieved successfully")
|
return ApiResponse(data=appointment_types, message="Master data retrieved successfully")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ async def get_clinic_offers(
|
||||||
page = 1
|
page = 1
|
||||||
offset = (page - 1) * limit
|
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")
|
return ApiResponse(data=clinic_offers, message="Clinic offers retrieved successfully")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ async def create_clinic_offer(
|
||||||
req:Request,
|
req:Request,
|
||||||
clinic_offer: ClinicOffersBase
|
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")
|
return ApiResponse(data="OK", message="Clinic offer created successfully")
|
||||||
|
|
||||||
@router.put("/clinic/offer/{clinic_offer_id}")
|
@router.put("/clinic/offer/{clinic_offer_id}")
|
||||||
|
|
@ -95,7 +95,7 @@ async def update_clinic_offer(
|
||||||
clinic_offer_id: int,
|
clinic_offer_id: int,
|
||||||
clinic_offer: ClinicOffersBase
|
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")
|
return ApiResponse(data="OK", message="Clinic offer updated successfully")
|
||||||
|
|
||||||
@router.delete("/clinic/offer/{clinic_offer_id}")
|
@router.delete("/clinic/offer/{clinic_offer_id}")
|
||||||
|
|
@ -103,6 +103,6 @@ async def delete_clinic_offer(
|
||||||
req:Request,
|
req:Request,
|
||||||
clinic_offer_id: int
|
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")
|
return ApiResponse(data="OK", message="Clinic offer deleted successfully")
|
||||||
|
|
||||||
|
|
@ -4,13 +4,12 @@ from schemas.CreateSchemas import UserCreate
|
||||||
from schemas.ApiResponse import ApiResponse
|
from schemas.ApiResponse import ApiResponse
|
||||||
from schemas.BaseSchemas import AuthBase, AuthOTP, ResetPasswordBase
|
from schemas.BaseSchemas import AuthBase, AuthOTP, ResetPasswordBase
|
||||||
from services.clinicServices import ClinicServices
|
from services.clinicServices import ClinicServices
|
||||||
from http import HTTPStatus
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/login")
|
||||||
def login(data: AuthBase):
|
async def login(data: AuthBase):
|
||||||
token = AuthService().login(data)
|
token = await AuthService().login(data)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=token,
|
data=token,
|
||||||
message="Login successful"
|
message="Login successful"
|
||||||
|
|
@ -18,16 +17,16 @@ def login(data: AuthBase):
|
||||||
|
|
||||||
|
|
||||||
@router.post("/register")
|
@router.post("/register")
|
||||||
def register(user_data: UserCreate, background_tasks: BackgroundTasks):
|
async def register(user_data: UserCreate, background_tasks: BackgroundTasks):
|
||||||
token = AuthService().register(user_data, background_tasks)
|
token = await AuthService().register(user_data, background_tasks)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=token,
|
data=token,
|
||||||
message="User registered successfully"
|
message="User registered successfully"
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.get("/clinic/latest-id")
|
@router.get("/clinic/latest-id")
|
||||||
def get_latest_clinic_id():
|
async def get_latest_clinic_id():
|
||||||
clinic_id = ClinicServices().get_latest_clinic_id()
|
clinic_id = await ClinicServices().get_latest_clinic_id()
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=clinic_id,
|
data=clinic_id,
|
||||||
message="Latest clinic ID retrieved successfully"
|
message="Latest clinic ID retrieved successfully"
|
||||||
|
|
@ -35,24 +34,27 @@ def get_latest_clinic_id():
|
||||||
|
|
||||||
|
|
||||||
@router.post('/admin/forget-password')
|
@router.post('/admin/forget-password')
|
||||||
def forget_password(email: str):
|
async def forget_password(email: str):
|
||||||
AuthService().forget_password(email)
|
await AuthService().forget_password(email)
|
||||||
return ApiResponse(data="OK", message="Password reset email sent successfully")
|
return ApiResponse(data="OK", message="Password reset email sent successfully")
|
||||||
|
|
||||||
@router.post('/admin/reset-password')
|
@router.post('/admin/reset-password')
|
||||||
def reset_password(data: ResetPasswordBase):
|
async def reset_password(data: ResetPasswordBase):
|
||||||
AuthService().reset_password(data.token, data.password)
|
await AuthService().reset_password(data.token, data.password)
|
||||||
return ApiResponse(data="OK", message="Password reset successfully")
|
return ApiResponse(data="OK", message="Password reset successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.post("/send-otp")
|
@router.post("/send-otp")
|
||||||
def send_otp(email: str):
|
async def send_otp(email: str):
|
||||||
AuthService().send_otp(email)
|
await AuthService().send_otp(email)
|
||||||
return HTTPStatus.OK
|
return ApiResponse(
|
||||||
|
data="OK",
|
||||||
|
message="OTP sent successfully"
|
||||||
|
)
|
||||||
|
|
||||||
@router.post("/verify-otp")
|
@router.post("/verify-otp")
|
||||||
def verify_otp(data: AuthOTP):
|
async def verify_otp(data: AuthOTP):
|
||||||
AuthService().verify_otp(data)
|
await AuthService().verify_otp(data)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data="OK",
|
data="OK",
|
||||||
message="OTP verified successfully"
|
message="OTP verified successfully"
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@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:
|
if page == 0:
|
||||||
page = 1
|
page = 1
|
||||||
offset = (page - 1) * limit
|
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")
|
return ApiResponse(data=response, message="Call transcripts retrieved successfully")
|
||||||
|
|
||||||
@router.post("/bulk-download")
|
@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()
|
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
|
return response
|
||||||
|
|
@ -7,21 +7,21 @@ from services.clinicDoctorsServices import ClinicDoctorsServices
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
def get_clinic_doctors():
|
async def get_clinic_doctors():
|
||||||
clinic_doctors = ClinicDoctorsServices().get_clinic_doctors()
|
clinic_doctors = await ClinicDoctorsServices().get_clinic_doctors()
|
||||||
return ApiResponse(data=clinic_doctors, message="Clinic doctors retrieved successfully")
|
return ApiResponse(data=clinic_doctors, message="Clinic doctors retrieved successfully")
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/")
|
||||||
def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
async def create_clinic_doctor(clinic_doctor: ClinicDoctorCreate):
|
||||||
clinic_doctor = ClinicDoctorsServices().create_clinic_doctor(clinic_doctor)
|
clinic_doctor = await ClinicDoctorsServices().create_clinic_doctor(clinic_doctor)
|
||||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor created successfully")
|
return ApiResponse(data=clinic_doctor, message="Clinic doctor created successfully")
|
||||||
|
|
||||||
@router.put("/{clinic_doctor_id}")
|
@router.put("/{clinic_doctor_id}")
|
||||||
def update_clinic_doctor(clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
async def update_clinic_doctor(clinic_doctor_id: int, clinic_doctor: ClinicDoctorUpdate):
|
||||||
clinic_doctor = ClinicDoctorsServices().update_clinic_doctor(clinic_doctor_id, clinic_doctor)
|
clinic_doctor = await ClinicDoctorsServices().update_clinic_doctor(clinic_doctor_id, clinic_doctor)
|
||||||
return ApiResponse(data=clinic_doctor, message="Clinic doctor updated successfully")
|
return ApiResponse(data=clinic_doctor, message="Clinic doctor updated successfully")
|
||||||
|
|
||||||
@router.delete("/{clinic_doctor_id}")
|
@router.delete("/{clinic_doctor_id}")
|
||||||
def delete_clinic_doctor(clinic_doctor_id: int):
|
async def delete_clinic_doctor(clinic_doctor_id: int):
|
||||||
ClinicDoctorsServices().delete_clinic_doctor(clinic_doctor_id)
|
await ClinicDoctorsServices().delete_clinic_doctor(clinic_doctor_id)
|
||||||
return ApiResponse(data="OK", message="Clinic doctor deleted successfully")
|
return ApiResponse(data="OK", message="Clinic doctor deleted successfully")
|
||||||
|
|
@ -28,17 +28,17 @@ async def get_clinics(
|
||||||
if page < 1:
|
if page < 1:
|
||||||
page = 1
|
page = 1
|
||||||
offset = (page - 1) * limit
|
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" )
|
return ApiResponse(data=clinics, message="Clinics retrieved successfully" )
|
||||||
|
|
||||||
@router.get("/verified-files/{clinic_id}")
|
@router.get("/verified-files/{clinic_id}")
|
||||||
async def get_verified_files(clinic_id: int):
|
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")
|
return ApiResponse(data=clinic, message="Clinic retrieved successfully")
|
||||||
|
|
||||||
@router.get("/{clinic_id}")
|
@router.get("/{clinic_id}")
|
||||||
async def get_clinic(clinic_id: int):
|
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")
|
return ApiResponse(data=clinic, message="Clinic retrieved successfully")
|
||||||
|
|
||||||
@router.put("/{clinic_id}")
|
@router.put("/{clinic_id}")
|
||||||
|
|
@ -46,10 +46,10 @@ async def update_clinic(
|
||||||
req:Request,
|
req:Request,
|
||||||
clinic_id: int, clinic: ClinicUpdate
|
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")
|
return ApiResponse(data=clinic, message="Clinic updated successfully")
|
||||||
|
|
||||||
@router.delete("/{clinic_id}", status_code=status.HTTP_204_NO_CONTENT)
|
@router.delete("/{clinic_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||||
async def delete_clinic(clinic_id: int):
|
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")
|
return ApiResponse(data="OK", message="Clinic deleted successfully")
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,17 @@ router = APIRouter()
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_clinic_doctor_status_count(req:Request):
|
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")
|
return ApiResponse(data=counts, message="Counts fetched successfully")
|
||||||
|
|
||||||
@router.post("/signup-pricing-master")
|
@router.post("/signup-pricing-master")
|
||||||
async def update_signup_pricing_master(req:Request, signup_pricing_master:SignupPricingMasterCreate):
|
async def update_signup_pricing_master(req:Request, signup_pricing_master:SignupPricingMasterCreate):
|
||||||
user = req.state.user
|
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")
|
return ApiResponse(data=response, message="Signup pricing master updated successfully")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/signup-pricing-master")
|
@router.get("/signup-pricing-master")
|
||||||
async def 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")
|
return ApiResponse(data=pricing, message="Signup pricing master fetched successfully")
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,7 @@ from schemas.CreateSchemas import S3Create
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/")
|
||||||
def upload_file(data:S3Create):
|
async def upload_file(data:S3Create):
|
||||||
try:
|
|
||||||
resp = upload_file_service(data.folder, data.file_name)
|
resp = await upload_file_service(data.folder, data.file_name)
|
||||||
return ApiResponse(data=resp, message="File uploaded successfully")
|
return ApiResponse(data=resp, message="File uploaded successfully")
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error uploading file: {str(e)}")
|
|
||||||
raise e
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ from utils.constants import DEFAULT_LIMIT, DEFAULT_PAGE
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/")
|
@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:
|
if page == 0:
|
||||||
page = 1
|
page = 1
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
user = UserServices().get_users(limit, offset, search)
|
user = await UserServices().get_users(limit, offset, search)
|
||||||
|
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
|
|
@ -22,10 +22,10 @@ def get_users(limit:int = DEFAULT_LIMIT, page:int = DEFAULT_PAGE, search:str = "
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.get("/me")
|
@router.get("/me")
|
||||||
def get_user(request: Request):
|
async def get_user(request: Request):
|
||||||
try:
|
try:
|
||||||
user_id = request.state.user["id"]
|
user_id = request.state.user["id"]
|
||||||
user = UserServices().get_user(user_id)
|
user = await UserServices().get_user(user_id)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
message="User fetched successfully"
|
message="User fetched successfully"
|
||||||
|
|
@ -35,34 +35,34 @@ def get_user(request: Request):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@router.get("/{user_id}")
|
@router.get("/{user_id}")
|
||||||
def get_user(request: Request, user_id: int):
|
async def get_user(request: Request, user_id: int):
|
||||||
user = UserServices().get_user(user_id)
|
user = await UserServices().get_user(user_id)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
message="User fetched successfully"
|
message="User fetched successfully"
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.delete("/")
|
@router.delete("/")
|
||||||
def delete_user(request: Request):
|
async def delete_user(request: Request):
|
||||||
user_id = request.state.user["id"]
|
user_id = request.state.user["id"]
|
||||||
UserServices().delete_user(user_id)
|
await UserServices().delete_user(user_id)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data="OK",
|
data="OK",
|
||||||
message="User deleted successfully"
|
message="User deleted successfully"
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.put("/")
|
@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_id = request.state.user["id"]
|
||||||
user = UserServices().update_user(user_id, user_data)
|
user = await UserServices().update_user(user_id, user_data)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
message="User updated successfully"
|
message="User updated successfully"
|
||||||
)
|
)
|
||||||
|
|
||||||
@router.put("/{user_id}")
|
@router.put("/{user_id}")
|
||||||
def update_user(request: Request, user_id: int, user_data: UserUpdate):
|
async def update_user(request: Request, user_id: int, user_data: UserUpdate):
|
||||||
user = UserServices().update_user(user_id, user_data)
|
user = await UserServices().update_user(user_id, user_data)
|
||||||
return ApiResponse(
|
return ApiResponse(
|
||||||
data=user,
|
data=user,
|
||||||
message="User updated successfully"
|
message="User updated successfully"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ async def auth_required(request: Request ,credentials: HTTPAuthorizationCredenti
|
||||||
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
||||||
|
|
||||||
# Get user from database
|
# Get user from database
|
||||||
user = UserServices().get_user(payload["id"])
|
user = await UserServices().get_user(payload["id"])
|
||||||
|
|
||||||
# set user to request state
|
# set user to request state
|
||||||
request.state.user = user
|
request.state.user = user
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ class AuthService:
|
||||||
self.email_service = EmailService()
|
self.email_service = EmailService()
|
||||||
self.url = os.getenv("FRONTEND_URL")
|
self.url = os.getenv("FRONTEND_URL")
|
||||||
|
|
||||||
def login(self, data: AuthBase) -> str:
|
async def login(self, data: AuthBase) -> str:
|
||||||
|
|
||||||
# get user
|
# get user
|
||||||
user = self.user_service.get_user_by_email(data.email)
|
user = await self.user_service.get_user_by_email(data.email)
|
||||||
|
|
||||||
# verify password
|
# verify password
|
||||||
if not verify_password(data.password, user.password):
|
if not verify_password(data.password, user.password):
|
||||||
|
|
@ -53,8 +53,8 @@ class AuthService:
|
||||||
token = create_jwt_token(user_dict)
|
token = create_jwt_token(user_dict)
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def register(self, user_data: UserCreate, background_tasks=None):
|
async def register(self, user_data: UserCreate, background_tasks=None):
|
||||||
response = self.user_service.create_user(user_data, background_tasks)
|
response = await self.user_service.create_user(user_data, background_tasks)
|
||||||
user = {
|
user = {
|
||||||
"id": response.id,
|
"id": response.id,
|
||||||
"username": response.username,
|
"username": response.username,
|
||||||
|
|
@ -93,7 +93,7 @@ class AuthService:
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
def send_otp(self, email:str):
|
async def send_otp(self, email:str):
|
||||||
otp = generateOTP()
|
otp = generateOTP()
|
||||||
self.email_service.send_otp_email(email, otp)
|
self.email_service.send_otp_email(email, otp)
|
||||||
|
|
||||||
|
|
@ -105,7 +105,7 @@ class AuthService:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def verify_otp(self, data: AuthOTP):
|
async def verify_otp(self, data: AuthOTP):
|
||||||
db_otp = self.db.query(OTP).filter(OTP.email == data.email, OTP.otp == data.otp).first()
|
db_otp = self.db.query(OTP).filter(OTP.email == data.email, OTP.otp == data.otp).first()
|
||||||
if not db_otp:
|
if not db_otp:
|
||||||
raise ValidationException("Invalid OTP")
|
raise ValidationException("Invalid OTP")
|
||||||
|
|
@ -121,7 +121,7 @@ class AuthService:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_admins(self, user, limit:int, offset:int, search:str):
|
async def get_admins(self, user, limit:int, offset:int, search:str):
|
||||||
try:
|
try:
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("User is not authorized to perform this action")
|
raise UnauthorizedException("User is not authorized to perform this action")
|
||||||
|
|
@ -150,7 +150,7 @@ class AuthService:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def create_super_admin(self, user, data: CreateSuperAdmin):
|
async def create_super_admin(self, user, data: CreateSuperAdmin):
|
||||||
|
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("User is not authorized to perform this action")
|
raise UnauthorizedException("User is not authorized to perform this action")
|
||||||
|
|
@ -191,7 +191,7 @@ class AuthService:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def update_super_admin(self, user, user_id: int, data: UpdateSuperAdmin):
|
async def update_super_admin(self, user, user_id: int, data: UpdateSuperAdmin):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("User is not authorized to perform this action")
|
raise UnauthorizedException("User is not authorized to perform this action")
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ class AuthService:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete_super_admin(self, user, user_id: int):
|
async def delete_super_admin(self, user, user_id: int):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("User is not authorized to perform this action")
|
raise UnauthorizedException("User is not authorized to perform this action")
|
||||||
|
|
||||||
|
|
@ -221,7 +221,7 @@ class AuthService:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def forget_password(self, email: str):
|
async def forget_password(self, email: str):
|
||||||
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
|
|
@ -240,7 +240,7 @@ class AuthService:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def reset_password(self, token: str, password: str):
|
async def reset_password(self, token: str, password: str):
|
||||||
reset_password = self.db.query(ResetPasswordTokens).filter(ResetPasswordTokens.token == token).first()
|
reset_password = self.db.query(ResetPasswordTokens).filter(ResetPasswordTokens.token == token).first()
|
||||||
|
|
||||||
if not reset_password:
|
if not reset_password:
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class CallTranscriptServices:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db:Session = next(get_db())
|
self.db:Session = next(get_db())
|
||||||
|
|
||||||
def get_call_transcripts(self, limit:int, offset:int):
|
async def get_call_transcripts(self, limit:int, offset:int):
|
||||||
call_transcripts = self.db.query(CallTranscripts).limit(limit).offset(offset).all()
|
call_transcripts = self.db.query(CallTranscripts).limit(limit).offset(offset).all()
|
||||||
|
|
||||||
total = self.db.query(CallTranscripts).count()
|
total = self.db.query(CallTranscripts).count()
|
||||||
|
|
@ -84,7 +84,7 @@ class CallTranscriptServices:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error during cleanup: {e}")
|
print(f"Error during cleanup: {e}")
|
||||||
|
|
||||||
def bulk_download_call_transcripts(self, key_ids: list[int], background_tasks: BackgroundTasks):
|
async def bulk_download_call_transcripts(self, key_ids: list[int], background_tasks: BackgroundTasks):
|
||||||
|
|
||||||
transcript_ids = self.db.query(CallTranscripts).filter(CallTranscripts.id.in_(key_ids)).all()
|
transcript_ids = self.db.query(CallTranscripts).filter(CallTranscripts.id.in_(key_ids)).all()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,15 @@ 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
|
from interface.common_response import CommonResponse
|
||||||
|
from sqlalchemy import func
|
||||||
|
from enums.enums import ClinicDoctorStatus
|
||||||
|
|
||||||
class ClinicDoctorsServices:
|
class ClinicDoctorsServices:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.db: Session = next(get_db())
|
self.db: Session = next(get_db())
|
||||||
self.clinic_services = ClinicServices()
|
self.clinic_services = ClinicServices()
|
||||||
|
|
||||||
def create_clinic_doctor(self, clinic_doctor: ClinicDoctorCreate) -> ClinicDoctorResponse:
|
async def create_clinic_doctor(self, clinic_doctor: ClinicDoctorCreate) -> ClinicDoctorResponse:
|
||||||
|
|
||||||
# check if clinic exists
|
# check if clinic exists
|
||||||
self.clinic_services.get_clinic_by_id(clinic_doctor.clinic_id)
|
self.clinic_services.get_clinic_by_id(clinic_doctor.clinic_id)
|
||||||
|
|
@ -24,7 +26,7 @@ class ClinicDoctorsServices:
|
||||||
self.db.refresh(clinic_doctor)
|
self.db.refresh(clinic_doctor)
|
||||||
return ClinicDoctorResponse(**clinic_doctor.__dict__.copy())
|
return ClinicDoctorResponse(**clinic_doctor.__dict__.copy())
|
||||||
|
|
||||||
def update_clinic_doctor(self, clinic_doctor_id: int, clinic_doctor_data: ClinicDoctorUpdate) -> ClinicDoctorResponse:
|
async def update_clinic_doctor(self, clinic_doctor_id: int, clinic_doctor_data: ClinicDoctorUpdate) -> ClinicDoctorResponse:
|
||||||
# check if clinic doctor exists
|
# check if clinic doctor exists
|
||||||
clinic_doctor = self.db.query(ClinicDoctors).filter(ClinicDoctors.id == clinic_doctor_id).first()
|
clinic_doctor = self.db.query(ClinicDoctors).filter(ClinicDoctors.id == clinic_doctor_id).first()
|
||||||
if clinic_doctor is None:
|
if clinic_doctor is None:
|
||||||
|
|
@ -44,15 +46,12 @@ class ClinicDoctorsServices:
|
||||||
self.db.refresh(clinic_doctor)
|
self.db.refresh(clinic_doctor)
|
||||||
return ClinicDoctorResponse(**clinic_doctor.__dict__.copy())
|
return ClinicDoctorResponse(**clinic_doctor.__dict__.copy())
|
||||||
|
|
||||||
def delete_clinic_doctor(self, clinic_doctor_id: int):
|
async def delete_clinic_doctor(self, clinic_doctor_id: int):
|
||||||
clinic_doctor = self.db.query(ClinicDoctors).filter(ClinicDoctors.id == clinic_doctor_id).first()
|
clinic_doctor = self.db.query(ClinicDoctors).filter(ClinicDoctors.id == clinic_doctor_id).first()
|
||||||
self.db.delete(clinic_doctor)
|
self.db.delete(clinic_doctor)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
|
|
||||||
def get_doctor_status_count(self):
|
async def get_doctor_status_count(self):
|
||||||
# Use SQLAlchemy's func.count to get the count for each status
|
|
||||||
from sqlalchemy import func
|
|
||||||
from enums.enums import ClinicDoctorStatus
|
|
||||||
|
|
||||||
# Query to count doctors by status
|
# Query to count doctors by status
|
||||||
status_counts = self.db.query(
|
status_counts = self.db.query(
|
||||||
|
|
@ -69,7 +68,7 @@ class ClinicDoctorsServices:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_clinic_doctors(self):
|
async def get_clinic_doctors(self):
|
||||||
clinic_doctors = self.db.query(ClinicDoctors).all()
|
clinic_doctors = self.db.query(ClinicDoctors).all()
|
||||||
|
|
||||||
total = self.db.query(ClinicDoctors).count()
|
total = self.db.query(ClinicDoctors).count()
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from sqlalchemy import or_,not_
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
|
||||||
from services.s3Service import get_file_key, get_signed_url
|
from services.s3Service import get_file_key, get_signed_url
|
||||||
from models import ClinicFileVerifications, ClinicOffers, Clinics
|
from models import ClinicFileVerifications, ClinicOffers, Clinics, Users
|
||||||
from schemas.BaseSchemas import ClinicFileVerificationBase, ClinicOffersBase
|
from schemas.BaseSchemas import ClinicFileVerificationBase, ClinicOffersBase
|
||||||
from services.emailService import EmailService
|
from services.emailService import EmailService
|
||||||
|
|
||||||
|
|
@ -20,12 +20,12 @@ class ClinicServices:
|
||||||
self.db: Session = next(get_db())
|
self.db: Session = next(get_db())
|
||||||
self.email_service = EmailService()
|
self.email_service = EmailService()
|
||||||
|
|
||||||
def get_clinics(self, user, limit:int, offset:int, filter_type: Union[Literal["UNREGISTERED"], Literal["REGISTERED"]] = "UNREGISTERED", search:str = ""):
|
async def get_clinics(self, user, limit:int, offset:int, filter_type: Union[Literal["UNREGISTERED"], Literal["REGISTERED"]] = "UNREGISTERED", search:str = ""):
|
||||||
|
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to get clinics")
|
raise UnauthorizedException("You are not authorized to get clinics")
|
||||||
|
|
||||||
clinics_query = self.db.query(Clinics)
|
clinics_query = self.db.query(Clinics).order_by(Clinics.update_time.desc())
|
||||||
|
|
||||||
if filter_type == "UNREGISTERED":
|
if filter_type == "UNREGISTERED":
|
||||||
clinics_query = clinics_query.filter(not_(Clinics.status == ClinicStatus.ACTIVE),not_(Clinics.status == ClinicStatus.INACTIVE))
|
clinics_query = clinics_query.filter(not_(Clinics.status == ClinicStatus.ACTIVE),not_(Clinics.status == ClinicStatus.INACTIVE))
|
||||||
|
|
@ -43,7 +43,7 @@ class ClinicServices:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
clinics = clinics_query.limit(limit).offset(offset).all()
|
clinics = clinics_query.offset(offset).limit(limit).all()
|
||||||
|
|
||||||
count_query = text("""
|
count_query = text("""
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -62,7 +62,7 @@ class ClinicServices:
|
||||||
clinic_response = [Clinic(**clinic.__dict__.copy()) for clinic in clinics]
|
clinic_response = [Clinic(**clinic.__dict__.copy()) for clinic in clinics]
|
||||||
|
|
||||||
for clinic in clinic_response:
|
for clinic in clinic_response:
|
||||||
clinic.logo = get_signed_url(clinic.logo) if clinic.logo else None
|
clinic.logo = await get_signed_url(clinic.logo) if clinic.logo else None
|
||||||
|
|
||||||
clinic_response_with_total = {
|
clinic_response_with_total = {
|
||||||
"clinics": clinic_response,
|
"clinics": clinic_response,
|
||||||
|
|
@ -74,13 +74,12 @@ class ClinicServices:
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_latest_clinic_id(self) -> int:
|
async def get_latest_clinic_id(self) -> int:
|
||||||
clinic = self.db.query(Clinics).order_by(Clinics.id.desc()).first()
|
clinic = self.db.query(Clinics).order_by(Clinics.id.desc()).first()
|
||||||
return clinic.id if clinic else 0
|
return clinic.id if clinic else 0
|
||||||
|
|
||||||
|
|
||||||
def get_clinic_by_id(self, clinic_id: int):
|
async def get_clinic_by_id(self, clinic_id: int):
|
||||||
try:
|
|
||||||
clinic = self.db.query(Clinics).options(joinedload(Clinics.creator)).filter(Clinics.id == clinic_id).first()
|
clinic = self.db.query(Clinics).options(joinedload(Clinics.creator)).filter(Clinics.id == clinic_id).first()
|
||||||
|
|
||||||
if clinic is None:
|
if clinic is None:
|
||||||
|
|
@ -88,9 +87,9 @@ class ClinicServices:
|
||||||
|
|
||||||
clinic_response = Clinic(**clinic.__dict__.copy())
|
clinic_response = Clinic(**clinic.__dict__.copy())
|
||||||
|
|
||||||
clinic_response.logo = get_signed_url(clinic_response.logo) if clinic_response.logo else None
|
clinic_response.logo = await get_signed_url(clinic_response.logo) if clinic_response.logo else None
|
||||||
clinic_response.abn_doc = get_signed_url(clinic_response.abn_doc) if clinic_response.abn_doc else None
|
clinic_response.abn_doc = await get_signed_url(clinic_response.abn_doc) if clinic_response.abn_doc else None
|
||||||
clinic_response.contract_doc = get_signed_url(clinic_response.contract_doc) if clinic_response.contract_doc else None
|
clinic_response.contract_doc = await get_signed_url(clinic_response.contract_doc) if clinic_response.contract_doc else None
|
||||||
|
|
||||||
clinicFiles = None
|
clinicFiles = None
|
||||||
if(clinic.status != ClinicStatus.ACTIVE):
|
if(clinic.status != ClinicStatus.ACTIVE):
|
||||||
|
|
@ -104,15 +103,13 @@ class ClinicServices:
|
||||||
"phone": clinic.creator.mobile,
|
"phone": clinic.creator.mobile,
|
||||||
"designation": clinic.creator.clinicRole
|
"designation": clinic.creator.clinicRole
|
||||||
},
|
},
|
||||||
"clinic_files": self.get_clinic_files(clinic_id),
|
"clinic_files": await self.get_clinic_files(clinic_id),
|
||||||
"fileStatus": {"reason":clinicFiles.rejection_reason if clinicFiles else None},
|
"fileStatus": {"reason":clinicFiles.rejection_reason if clinicFiles else None},
|
||||||
}
|
}
|
||||||
|
|
||||||
return clinic_resp
|
return clinic_resp
|
||||||
except Exception as e:
|
|
||||||
raise Exception(e)
|
|
||||||
|
|
||||||
def get_clinic_files(self, clinic_id: int):
|
async def get_clinic_files(self, clinic_id: int):
|
||||||
clinic_files = self.db.query(ClinicFileVerifications).filter(ClinicFileVerifications.clinic_id == clinic_id).first()
|
clinic_files = self.db.query(ClinicFileVerifications).filter(ClinicFileVerifications.clinic_id == clinic_id).first()
|
||||||
|
|
||||||
if clinic_files is None:
|
if clinic_files is None:
|
||||||
|
|
@ -122,7 +119,7 @@ class ClinicServices:
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def update_clinic(self, user, clinic_id: int, clinic_data: ClinicUpdate):
|
async def update_clinic(self, user, clinic_id: int, clinic_data: ClinicUpdate):
|
||||||
clinic = self.db.query(Clinics).filter(Clinics.id == clinic_id).first()
|
clinic = self.db.query(Clinics).filter(Clinics.id == clinic_id).first()
|
||||||
|
|
||||||
if clinic is None:
|
if clinic is None:
|
||||||
|
|
@ -149,7 +146,7 @@ class ClinicServices:
|
||||||
|
|
||||||
return clinic_response
|
return clinic_response
|
||||||
|
|
||||||
def delete_clinic(self, clinic_id: int):
|
async def delete_clinic(self, clinic_id: int):
|
||||||
clinic = self.db.query(Clinics).filter(Clinics.id == clinic_id).first()
|
clinic = self.db.query(Clinics).filter(Clinics.id == clinic_id).first()
|
||||||
|
|
||||||
if clinic is None:
|
if clinic is None:
|
||||||
|
|
@ -157,7 +154,7 @@ class ClinicServices:
|
||||||
|
|
||||||
clinic.soft_delete(self.db)
|
clinic.soft_delete(self.db)
|
||||||
|
|
||||||
def get_clinic_count(self):
|
async def get_clinic_count(self):
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
|
||||||
# Get total count
|
# Get total count
|
||||||
|
|
@ -199,7 +196,7 @@ class ClinicServices:
|
||||||
return counts
|
return counts
|
||||||
|
|
||||||
|
|
||||||
def update_clinic_status(self, user, clinic_id: int, status: ClinicStatus, documentStatus: Optional[dict] = None, rejection_reason: Optional[str] = None):
|
async def update_clinic_status(self, user, clinic_id: int, status: ClinicStatus, documentStatus: Optional[dict] = None, rejection_reason: Optional[str] = None):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to update clinic status")
|
raise UnauthorizedException("You are not authorized to update clinic status")
|
||||||
|
|
||||||
|
|
@ -258,11 +255,18 @@ class ClinicServices:
|
||||||
|
|
||||||
# handle inactive status
|
# handle inactive status
|
||||||
if clinic.status == ClinicStatus.INACTIVE:
|
if clinic.status == ClinicStatus.INACTIVE:
|
||||||
|
# get clinic creator
|
||||||
|
# clinic_creator = self.db.query(Users).options(joinedload(Users.created_clinics)).filter(Clinics.id == clinic.id).first()
|
||||||
|
|
||||||
|
# # block clinic creator
|
||||||
|
# clinic_creator.isBlocked = True
|
||||||
|
# self.db.add(clinic_creator)
|
||||||
|
# self.db.commit()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_clinic_offers(self, user, limit:int, offset:int, search:str = ""):
|
async def get_clinic_offers(self, user, limit:int, offset:int, search:str = ""):
|
||||||
|
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to get clinic offers")
|
raise UnauthorizedException("You are not authorized to get clinic offers")
|
||||||
|
|
@ -283,7 +287,7 @@ class ClinicServices:
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def create_clinic_offer(self, user, clinic_offer_data: ClinicOffersBase):
|
async def create_clinic_offer(self, user, clinic_offer_data: ClinicOffersBase):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to create clinic offer")
|
raise UnauthorizedException("You are not authorized to create clinic offer")
|
||||||
|
|
||||||
|
|
@ -299,7 +303,7 @@ class ClinicServices:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def update_clinic_offer(self, user, clinic_offer_id: int, clinic_offer_data: ClinicOffersBase):
|
async def update_clinic_offer(self, user, clinic_offer_id: int, clinic_offer_data: ClinicOffersBase):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to update clinic offer")
|
raise UnauthorizedException("You are not authorized to update clinic offer")
|
||||||
|
|
||||||
|
|
@ -316,7 +320,7 @@ class ClinicServices:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete_clinic_offer(self, user, clinic_offer_id: int):
|
async def delete_clinic_offer(self, user, clinic_offer_id: int):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
raise UnauthorizedException("You are not authorized to delete clinic offer")
|
raise UnauthorizedException("You are not authorized to delete clinic offer")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,15 @@ class DashboardService:
|
||||||
self.clinicDoctorsServices = ClinicDoctorsServices()
|
self.clinicDoctorsServices = ClinicDoctorsServices()
|
||||||
self.clinicServices = ClinicServices()
|
self.clinicServices = ClinicServices()
|
||||||
|
|
||||||
def get_dashboard_counts(self, isSuperAdmin: bool):
|
async def get_dashboard_counts(self, isSuperAdmin: bool):
|
||||||
if isSuperAdmin:
|
if isSuperAdmin:
|
||||||
clinicCounts = self.clinicServices.get_clinic_count()
|
clinicCounts = await self.clinicServices.get_clinic_count()
|
||||||
return clinicCounts
|
return clinicCounts
|
||||||
else:
|
else:
|
||||||
clinicDoctorsCount = self.clinicDoctorsServices.get_doctor_status_count()
|
clinicDoctorsCount = await self.clinicDoctorsServices.get_doctor_status_count()
|
||||||
return clinicDoctorsCount
|
return clinicDoctorsCount
|
||||||
|
|
||||||
def update_signup_pricing_master(
|
async def update_signup_pricing_master(
|
||||||
self, user, pricing_data: SignupPricingMasterBase
|
self, user, pricing_data: SignupPricingMasterBase
|
||||||
):
|
):
|
||||||
if user["userType"] != UserType.SUPER_ADMIN:
|
if user["userType"] != UserType.SUPER_ADMIN:
|
||||||
|
|
@ -62,7 +62,7 @@ class DashboardService:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def get_signup_pricing_master(self):
|
async def get_signup_pricing_master(self):
|
||||||
signup_pricing_master = self.db.query(SignupPricingMaster).first()
|
signup_pricing_master = self.db.query(SignupPricingMaster).first()
|
||||||
if signup_pricing_master is None:
|
if signup_pricing_master is None:
|
||||||
raise ResourceNotFoundException("Signup pricing master not found")
|
raise ResourceNotFoundException("Signup pricing master not found")
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class MasterAppointmentServices:
|
||||||
self.db: Session = next(get_db())
|
self.db: Session = next(get_db())
|
||||||
|
|
||||||
|
|
||||||
def get_master_appointment_types(self):
|
async def get_master_appointment_types(self):
|
||||||
appointment_types = self.db.query(MasterAppointmentTypes).all()
|
appointment_types = self.db.query(MasterAppointmentTypes).all()
|
||||||
total= self.db.query(MasterAppointmentTypes).count()
|
total= self.db.query(MasterAppointmentTypes).count()
|
||||||
response = CommonResponse(data=[MasterAppointmentTypeResponse(**appointment_type.__dict__.copy()) for appointment_type in appointment_types], total=total)
|
response = CommonResponse(data=[MasterAppointmentTypeResponse(**appointment_type.__dict__.copy()) for appointment_type in appointment_types], total=total)
|
||||||
|
|
@ -22,7 +22,7 @@ class MasterAppointmentServices:
|
||||||
existing_appointment_type = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.type == appointment_type.type.lower()).first()
|
existing_appointment_type = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.type == appointment_type.type.lower()).first()
|
||||||
return existing_appointment_type
|
return existing_appointment_type
|
||||||
|
|
||||||
def create_master_appointment_type(self, appointment_type: MasterAppointmentTypeBase):
|
async def create_master_appointment_type(self, appointment_type: MasterAppointmentTypeBase):
|
||||||
|
|
||||||
# get existing appointment type
|
# get existing appointment type
|
||||||
existing_appointment_type = self.is_appointment_type_exists(appointment_type)
|
existing_appointment_type = self.is_appointment_type_exists(appointment_type)
|
||||||
|
|
@ -37,7 +37,7 @@ class MasterAppointmentServices:
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete_master_appointment_type(self, appointment_type_id: int):
|
async def delete_master_appointment_type(self, appointment_type_id: int):
|
||||||
appointment_type = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.id == appointment_type_id).first()
|
appointment_type = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.id == appointment_type_id).first()
|
||||||
|
|
||||||
if appointment_type is None:
|
if appointment_type is None:
|
||||||
|
|
@ -47,7 +47,7 @@ class MasterAppointmentServices:
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def update_master_appointment_type(self, appointment_type_id: int, appointment_type: MasterAppointmentTypeBase):
|
async def update_master_appointment_type(self, appointment_type_id: int, appointment_type: MasterAppointmentTypeBase):
|
||||||
appointment_type_db = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.id == appointment_type_id).first()
|
appointment_type_db = self.db.query(MasterAppointmentTypes).filter(MasterAppointmentTypes.id == appointment_type_id).first()
|
||||||
|
|
||||||
if appointment_type_db is None:
|
if appointment_type_db is None:
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class S3Service:
|
||||||
def get_s3_service():
|
def get_s3_service():
|
||||||
return S3Service()
|
return S3Service()
|
||||||
|
|
||||||
def upload_file(
|
async def upload_file(
|
||||||
folder: S3FolderNameEnum,
|
folder: S3FolderNameEnum,
|
||||||
file_name: str,
|
file_name: str,
|
||||||
) -> Dict[str, str]:
|
) -> Dict[str, str]:
|
||||||
|
|
@ -93,7 +93,7 @@ def upload_file(
|
||||||
print(f"Error generating pre-signed URL: {e}")
|
print(f"Error generating pre-signed URL: {e}")
|
||||||
raise BusinessValidationException(str(e))
|
raise BusinessValidationException(str(e))
|
||||||
|
|
||||||
def get_signed_url(key: str) -> str:
|
async def get_signed_url(key: str) -> str:
|
||||||
"""
|
"""
|
||||||
Generate a pre-signed URL for retrieving a file from S3.
|
Generate a pre-signed URL for retrieving a file from S3.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class UserServices:
|
||||||
self.db: Session = next(get_db())
|
self.db: Session = next(get_db())
|
||||||
self.email_service = EmailService()
|
self.email_service = EmailService()
|
||||||
|
|
||||||
def create_user(self, user_data: UserCreate, background_tasks=None):
|
async def create_user(self, user_data: UserCreate, background_tasks=None):
|
||||||
# Start a transaction
|
# Start a transaction
|
||||||
try:
|
try:
|
||||||
user = user_data.user
|
user = user_data.user
|
||||||
|
|
@ -114,9 +114,6 @@ class UserServices:
|
||||||
# Add clinic files to database
|
# Add clinic files to database
|
||||||
self.db.add(clinic_files)
|
self.db.add(clinic_files)
|
||||||
|
|
||||||
# Now commit both user and clinic in a single transaction
|
|
||||||
self.db.commit()
|
|
||||||
|
|
||||||
# Send mail to admin in a non-blocking way using background tasks
|
# Send mail to admin in a non-blocking way using background tasks
|
||||||
if background_tasks:
|
if background_tasks:
|
||||||
background_tasks.add_task(self._send_emails_to_admins, clinic.email)
|
background_tasks.add_task(self._send_emails_to_admins, clinic.email)
|
||||||
|
|
@ -130,8 +127,10 @@ class UserServices:
|
||||||
|
|
||||||
# Use the centralized exception handler
|
# Use the centralized exception handler
|
||||||
DBExceptionHandler.handle_exception(e, context="creating user")
|
DBExceptionHandler.handle_exception(e, context="creating user")
|
||||||
|
finally:
|
||||||
|
self.db.commit()
|
||||||
|
|
||||||
def get_user(self, user_id) -> UserResponse:
|
async def get_user(self, user_id) -> UserResponse:
|
||||||
try:
|
try:
|
||||||
# Query the user by ID and explicitly load the created clinics relationship
|
# Query the user by ID and explicitly load the created clinics relationship
|
||||||
user = self.db.query(Users).options(joinedload(Users.created_clinics)).filter(Users.id == user_id).first()
|
user = self.db.query(Users).options(joinedload(Users.created_clinics)).filter(Users.id == user_id).first()
|
||||||
|
|
@ -165,7 +164,7 @@ class UserServices:
|
||||||
from twillio.exceptions.db_exceptions import DBExceptionHandler
|
from twillio.exceptions.db_exceptions import DBExceptionHandler
|
||||||
DBExceptionHandler.handle_exception(e, context="getting user")
|
DBExceptionHandler.handle_exception(e, context="getting user")
|
||||||
|
|
||||||
def get_users(self, limit:int, offset:int, search:str):
|
async def get_users(self, limit:int, offset:int, search:str):
|
||||||
query = self.db.query(Users)
|
query = self.db.query(Users)
|
||||||
if search:
|
if search:
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
|
|
@ -185,8 +184,7 @@ class UserServices:
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_user_by_email(self, email: str) -> UserResponse:
|
async def get_user_by_email(self, email: str) -> UserResponse:
|
||||||
try:
|
|
||||||
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
user = self.db.query(Users).filter(Users.email == email.lower()).first()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
|
|
@ -198,10 +196,8 @@ class UserServices:
|
||||||
user_response = UserResponse(**user_dict)
|
user_response = UserResponse(**user_dict)
|
||||||
|
|
||||||
return user_response
|
return user_response
|
||||||
except Exception as e:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
def update_user(self, admin_id:int|None, user_id: int, user_data: UserUpdate) -> UserResponse:
|
async def update_user(self, admin_id:int|None, user_id: int, user_data: UserUpdate) -> UserResponse:
|
||||||
# Check admin authorization if admin_id is provided
|
# Check admin authorization if admin_id is provided
|
||||||
if admin_id:
|
if admin_id:
|
||||||
admin = self.db.query(Users).filter(Users.id == admin_id).first()
|
admin = self.db.query(Users).filter(Users.id == admin_id).first()
|
||||||
|
|
@ -232,7 +228,7 @@ class UserServices:
|
||||||
# Return properly serialized response
|
# Return properly serialized response
|
||||||
return UserResponse.model_validate(user)
|
return UserResponse.model_validate(user)
|
||||||
|
|
||||||
def delete_user(self, user_id: int):
|
async def delete_user(self, user_id: int):
|
||||||
user = self.db.query(Users).filter(Users.id == user_id).first()
|
user = self.db.query(Users).filter(Users.id == user_id).first()
|
||||||
|
|
||||||
if not user:
|
if not user:
|
||||||
|
|
@ -244,13 +240,13 @@ class UserServices:
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_super_admins(self):
|
async def get_super_admins(self):
|
||||||
return self.db.query(Users).filter(Users.userType == UserType.SUPER_ADMIN).all()
|
return self.db.query(Users).filter(Users.userType == UserType.SUPER_ADMIN).all()
|
||||||
|
|
||||||
def _send_emails_to_admins(self, clinic_name):
|
async def _send_emails_to_admins(self, clinic_name):
|
||||||
"""Helper method to send emails to all super admins"""
|
"""Helper method to send emails to all super admins"""
|
||||||
try:
|
try:
|
||||||
admins = self.get_super_admins()
|
admins = await self.get_super_admins()
|
||||||
for admin in admins:
|
for admin in admins:
|
||||||
self.email_service.send_new_clinic_email(
|
self.email_service.send_new_clinic_email(
|
||||||
to_address=admin.email,
|
to_address=admin.email,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue