health-apps-backend/apis/endpoints/auth.py

48 lines
1.3 KiB
Python

from fastapi import APIRouter, BackgroundTasks
from services.authService import AuthService
from schemas.CreateSchemas import UserCreate
from schemas.ApiResponse import ApiResponse
from schemas.BaseSchemas import AuthBase, AuthOTP
from services.clinicServices import ClinicServices
from http import HTTPStatus
router = APIRouter()
@router.post("/login")
def login(data: AuthBase):
token = AuthService().login(data)
return ApiResponse(
data=token,
message="Login successful"
)
@router.post("/register")
def register(user_data: UserCreate, background_tasks: BackgroundTasks):
token = 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()
return ApiResponse(
data=clinic_id,
message="Latest clinic ID retrieved successfully"
)
@router.post("/send-otp")
def send_otp(email: str):
AuthService().send_otp(email)
return HTTPStatus.OK
@router.post("/verify-otp")
def verify_otp(data: AuthOTP):
AuthService().verify_otp(data)
return ApiResponse(
data="OK",
message="OTP verified successfully"
)