File size: 12,343 Bytes
ef1ad9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
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)