2222 is_username_email_already_exists_in_db ,
2323 convert_db_model_to_resp ,
2424)
25- from src .usermanagement_service .users .response_handlers .create_user_success_response import (
26- generate_success_response ,
27- )
25+ from src .usermanagement_service .users .response_handlers .create_user_success_response import generate_success_response
2826
2927
3028def register_user ():
3129 try :
3230 user_management_logger .info (
33- f"REQUEST ==> Received Endpoint for the request: : { request .endpoint } "
31+ f"REQUEST ==> Received Endpoint: { request .endpoint } "
3432 )
3533 user_management_logger .info (
3634 f"REQUEST ==> Received url for the request :: { request .url } "
@@ -40,21 +38,28 @@ def register_user():
4038 user_management_logger .info (
4139 f"Received Headers from the request :: { rec_req_headers } "
4240 )
43- """
41+ """
4442 1. Find the missing headers, any schema related issue related to headers in the request
45- 2. If any missing headers or schema related issue , send the error response back to client.
43+ 2. If any missing headers or schema related issue, send the error response back to client.
4644 3. Custom error response contains the information about headers related to missing/schema issue, with status code as 400,BAD_REQUEST
4745 """
48- reg_header_result = usermanager .generate_req_missing_params (rec_req_headers , req_headers_schema )
46+ reg_header_result = usermanager .generate_req_missing_params (
47+ rec_req_headers , req_headers_schema
48+ )
4949 if len (reg_header_result ) > 0 :
50- return send_invalid_request_error_to_client (app_logger_name = user_management_logger ,message_data = "Request Headers Missing" ,err_details = reg_header_result ,)
50+ return send_invalid_request_error_to_client (
51+ app_logger_name = user_management_logger ,
52+ message_data = "Request Headers Missing" ,
53+ err_details = reg_header_result ,
54+ )
5155
5256 rec_req_data = request .get_json ()
53- """
57+ """
5458 1. Find the missing params, any schema related issue related to params in the request body
55- 2. If any missing params or schema related issue , send the error response back to client.
59+ 2. If any missing params or schema related issue, send the error response back to client.
5660 3. Custom error response contains the information about params related to missing/schema issue, with status code as 400,BAD_REQUEST
5761 """
62+ """
5863 body_result = usermanager.generate_req_missing_params(
5964 rec_req_data, reg_user_req_schema
6065 )
@@ -72,21 +77,32 @@ def register_user():
7277 emailaddress = rec_req_data["email"]
7378 password = rec_req_data["password"]
7479 dateofbirth = rec_req_data["dateOfBirth"]
75- user_management_logger .info ("Processing the request data... :: [STARTED]" )
76- session_to_validate_existing_user = app_manager_db_obj .get_session_from_session_maker ()
80+ user_management_logger.info("Processing request data... [STARTED]")
81+ session_to_validate_existing_user = (
82+ app_manager_db_obj.get_session_from_session_maker()
83+ )
7784 if session_to_validate_existing_user is None:
78- """
79- No need to close the connection/session if the timeout occurs during the session/connection creation.
80- If the queue is full, it will try to wait initiate/fetch connection from the overflows connections.
81- """
82- return send_internal_server_error_to_client (app_logger_name = user_management_logger , message_data = "Create Session Failed" ,)
85+ return send_internal_server_error_to_client(
86+ app_logger_name=user_management_logger,
87+ message_data="Create Session Failed",
88+ )
8389 # Doing the pre-validation checks before procession the request.
84- if is_username_email_already_exists_in_db (session_instance = session_to_validate_existing_user , uname = username , email = emailaddress ,) is None :
90+ if is_username_email_already_exists_in_db(
91+ session_instance=session_to_validate_existing_user,
92+ uname=username,
93+ email=emailaddress,
94+ ) is None:
8595 app_manager_db_obj.close_session(session_instance=session_to_validate_existing_user)
86- return send_internal_server_error_to_client (app_logger_name = user_management_logger , message_data = "Db error" )
96+ return send_internal_server_error_to_client(
97+ app_logger_name=user_management_logger,
98+ message_data="Db error"
99+ )
87100 if not is_username_email_already_exists_in_db:
88101 app_manager_db_obj.close_session(session_instance=session_to_validate_existing_user)
89- return send_invalid_request_error_to_client (app_logger_name = user_management_logger , message_data = "Existing User" ,)
102+ return send_invalid_request_error_to_client(
103+ app_logger_name=user_management_logger,
104+ message_data="Existing User",
105+ )
90106 # Register user-logic begins here
91107 try:
92108 user_obj = User(
@@ -110,9 +126,6 @@ def register_user():
110126 app_logger_name=user_management_logger,
111127 message_data="User Instance creation Failed",
112128 )
113- """
114- Using the session begin the transaction, and add the user into the database using ORM.
115- """
116129 session_to_create_new_user = app_manager_db_obj.get_session_from_session_maker()
117130 if session_to_create_new_user is None:
118131 return send_internal_server_error_to_client(app_logger_name=user_management_logger, message_data="Create Session Failed",)
@@ -121,10 +134,6 @@ def register_user():
121134 if user_db_record_to_insert is None:
122135 app_manager_db_obj.close_session(session_instance=session_to_create_new_user)
123136 return send_internal_server_error_to_client(app_logger_name=user_management_logger, message_data="User DB - Instance mapping Failed",)
124- """
125- Add the user model to the database and commit the changes
126- Any exception occur, logs the exception and sends back the error response to the client as internal_server_error
127- """
128137 try:
129138 user_management_logger.info(
130139 f"Data adding into DataBase session {user_db_record_to_insert}:: [STARTED]"
@@ -147,11 +156,6 @@ def register_user():
147156 )
148157 return send_internal_server_error_to_client(app_logger_name=user_management_logger, message_data="Database Error",)
149158 else:
150- """
151- 1. Converting the database model of user to defined user and serialize to json
152- 2. Using the serialize , Generating the success custom response , headers
153- 3. Sending the response back to client
154- """
155159 user_instance = convert_db_model_to_resp(model_instance=user_db_record_to_insert)
156160 if not user_instance:
157161 app_manager_db_obj.close_session(session_instance=session_to_create_new_user)
0 commit comments