ans123's picture
Initial upload from Colab
ef1ad9e verified
from app.schema.change_password import PasswordSchema
from app.schema.examples.error_response import *
from app.schema.examples.user import *
from app.schema.onBoarding_profile_schema import (
OnboardingProfileCreate,
OnboardingProfileUpdate,
)
from app.schema.personal_info import PersonalInfoSchema
from app.schema.response_schema import ResponseSchema
from app.schema.user_schema import CheckFirstTimeUserSchema
from app.services.user_service import UserService
from app.utils.auth0 import get_current_user
from app.utils.database import get_db
from app.utils.jwt import VerifyToken
from app.utils.utility import create_swagger_redirect_response, create_swagger_response
from fastapi import APIRouter, Depends, Query, Security
from sqlalchemy.orm import Session
router = APIRouter()
auth = VerifyToken()
@router.get(
"/redirect-verification/",
response_model=ResponseSchema,
summary="Redirect Loan Officer Verification",
description="Redirect the user to the loan officer verification process using the provided parameters.",
responses=create_swagger_redirect_response(
description="Temporary Redirect to the loan officer verification page.",
example_url="https://example.com/dashboard?session_token=abc123token",
),
)
async def redirect_verification(redirectUrl: str, sessionToken: str, state: str):
"""
Redirect user for loan officer verification.
- **redirectUrl**: The URL to redirect to.
- **sessionToken**: The session token of the user.
- **state**: The state parameter for verification.
"""
return await UserService.redirect_user_verification(redirectUrl, sessionToken)
@router.get(
"/get_loan_officer_details",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get Loan Officer Details",
description="Fetch details of the logged-in loan officer.",
responses=create_swagger_response(get_loan_offcier_response, [unauthorized_response, user_not_found]),
)
async def get_loan_officer_details(
user=Security(auth.verify, scopes=[]),
db: Session = Depends(get_db),
):
"""
Get details of the logged-in loan officer.
- **user**: The authenticated user.
- **db**: The database session.
"""
return await UserService.get_loan_officer_details(db, user)
@router.get(
"/{user_id}",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get User Details",
description="Fetch details for the specified user.",
responses=create_swagger_response(get_user_details_response, [unauthorized_response, user_not_found]),
)
async def get_user_details(user_id: int, db: Session = Depends(get_db)):
"""
Get details for the specified user.
- **user_id**: The ID of the user.
- **db**: The database session.
"""
return await UserService.get_user_detail(user_id, db)
@router.get(
"/users/",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get All Users",
description="Fetch a list of all users with pagination options.",
responses=create_swagger_response(get_all_users_response, [unauthorized_response]),
)
async def get_all_users(limit: int, offset: int, db: Session = Depends(get_db)):
"""
Get a list of all users with pagination options.
- **limit**: The maximum number of users to return.
- **offset**: The starting point within the collection of users.
- **db**: The database session.
"""
return await UserService.get_all_users(limit, offset, db)
@router.get(
"/loan_officers/",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get Loan Officers",
description="Fetch a list of all loan officers.",
responses=create_swagger_response(get_loan_offcier_response, [unauthorized_response]),
)
async def get_loan_officers(db: Session = Depends(get_db)):
"""
Get a list of all loan officers.
- **db**: The database session.
"""
return await UserService.get_loan_officers(db)
@router.post(
"/is_first_time_user",
response_model=ResponseSchema,
summary="Is First Time User",
description="Check if the user is logging in for the first time.",
responses=create_swagger_response(is_first_time_user_response),
)
async def is_first_time_user(user: CheckFirstTimeUserSchema, db: Session = Depends(get_db)):
"""
Check if the user is logging in for the first time.
- **user**: Schema containing user data.
- **db**: The database session.
"""
return await UserService.is_first_time_user(user, db)
@router.get(
"/user_profiles/{user_id}",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get User Profiles",
description="Fetch profiles of the specified user.",
responses=create_swagger_response(get_user_profiles_response, [unauthorized_response]),
)
async def get_user_profiles(user_id: int, db: Session = Depends(get_db)):
"""
Fetch profiles of the specified user.
- **user_id**: The ID of the user.
- **db**: The database session.
"""
return await UserService.get_user_profiles(user_id, db)
@router.post(
"/onboarding_profile",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Create Onboarding Profile",
description="Create a new onboarding profile for the authenticated user.",
responses=create_swagger_response(create_onboarding_profile_response, [unauthorized_response]),
)
async def create_onboarding_profile(
onboarding_profile_details: OnboardingProfileCreate,
db: Session = Depends(get_db),
user=Security(auth.verify, scopes=[]),
):
"""
Create a new onboarding profile for the authenticated user.
- **onboarding_profile_details**: Schema containing onboarding profile details.
- **db**: The database session.
- **user**: The authenticated user.
"""
return await UserService.create_onboarding_profiles(db, onboarding_profile_details, user)
@router.put(
"/onboarding_profile",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Update Onboarding Profile",
description="Update the onboarding profile of the authenticated user.",
responses=create_swagger_response(
update_onboarding_profile_response, [unauthorized_response, onboarding_data_not_found]
),
)
async def update_onboarding_profile(
update_fields: OnboardingProfileUpdate,
user=Security(auth.verify, scopes=[]),
db: Session = Depends(get_db),
):
"""
Update the onboarding profile of the authenticated user.
- **update_fields**: Schema containing fields to update.
- **user**: The authenticated user.
- **db**: The database session.
"""
return await UserService.update_onboarding_profiles(db, update_fields, user)
@router.get(
"/onboarding_profile/",
dependencies=[Depends(auth.verify)],
response_model=ResponseSchema,
summary="Get Onboarding Profile",
description="Fetch the onboarding profile of the authenticated user.",
responses=create_swagger_response(
get_onboarding_profile_response, [unauthorized_response, onboarding_data_not_found]
),
)
async def get_onboarding_profile(user=Security(auth.verify, scopes=[]), db: Session = Depends(get_db)):
"""
Fetch the onboarding profile of the authenticated user.
- **user**: The authenticated user.
- **db**: The database session.
"""
return await UserService.get_onboarding_profiles(db, user)
@router.delete(
"/application/{user_id}",
response_model=ResponseSchema,
summary="Delete Application",
description="Delete application for the specified user.",
responses=create_swagger_response(delete_application_response),
)
async def delete_application(user_id: int, db: Session = Depends(get_db)):
"""
Delete application for the specified user.
- **user_id**: The ID of the user.
- **db**: The database session.
"""
return await UserService.delete_applications(db, user_id)
@router.get(
"/is_loan_officer/{user_id}",
response_model=ResponseSchema,
summary="Check Loan Officer Status",
description="Check if the specified user is a loan officer.",
)
async def is_loan_officer(user_id: int, db: Session = Depends(get_db)):
"""
Check if the specified user is a loan officer.
- **user_id**: The ID of the user.
- **db**: The database session.
"""
return await UserService.is_loan_officer(db, user_id)
@router.post(
"/change_password",
response_model=ResponseSchema,
summary="Change Password",
description="Change the password for the authenticated user.",
responses=create_swagger_response(change_password_response, [user_not_found]),
)
async def change_password(pass_object: PasswordSchema, db: Session = Depends(get_db)):
"""
Change the password for the authenticated user.
- **pass_object**: Schema containing the new password.
- **db**: The database session.
"""
return await UserService.change_password(pass_object, db)
@router.get(
"/is_user_verified/{user_id}/{code}",
response_model=ResponseSchema,
summary="Verify User",
description="Verify if the user with the specified ID and code is verified.",
responses=create_swagger_redirect_response(
description="Temporary Redirect to Password setup page.",
example_url="https://example.com/password?user_id=1&code=123456&[email protected]",
),
)
async def is_user_verified(user_id: int, code: int, db: Session = Depends(get_db)):
"""
Verify if the user with the specified ID and code is verified.
- **user_id**: The ID of the user.
- **code**: The verification code.
- **db**: The database session.
"""
return await UserService.is_user_verified(db, user_id, code)
@router.get(
"/reset_user_password/{user_id}/{code}",
response_model=ResponseSchema,
summary="Reset User Password",
description="Reset the password for the user with the specified ID and code.",
responses=create_swagger_redirect_response(
description="Temporary Redirect to Password setup page.",
example_url="https://example.com/password?user_id=1&code=123456&[email protected]",
),
)
async def reset_user_password(user_id: int, code: int, db: Session = Depends(get_db)):
"""
Reset the password for the user with the specified ID and code.
- **user_id**: The ID of the user.
- **code**: The reset code.
- **db**: The database session.
"""
return await UserService.reset_user_password_via_reset_link(db, user_id, code)
@router.post(
"/personal-info",
dependencies=[Depends(get_current_user)],
response_model=ResponseSchema,
summary="Update Personal Info",
description="Update personal information for the authenticated user.",
)
async def post_personal_info(
user: PersonalInfoSchema, db: Session = Depends(get_db), current_user: dict = Depends(get_current_user)
):
"""
Update personal information for the authenticated user.
- **user**: Schema containing personal information.
- **db**: The database session.
- **current_user**: The authenticated user's data.
"""
return await UserService.update_personal_info(user, db, current_user)
@router.post(
"/resend-mail",
dependencies=[Depends(get_current_user)],
response_model=ResponseSchema,
summary="Resend Verification Mail",
description="Resend the verification mail to the authenticated user.",
responses=create_swagger_response(resend_verification_mail_response),
)
async def resend_mail(db: Session = Depends(get_db), current_user: dict = Depends(get_current_user)):
"""
Resend the verification mail to the authenticated user.
- **db**: The database session.
- **current_user**: The authenticated user's data.
"""
return await UserService.resend_mail(db, current_user)