Last active
August 3, 2020 03:05
-
-
Save mtreacy002/d1598c7846838f3cd71ea31e67e87bf5 to your computer and use it in GitHub Desktop.
POST and PUT users additional information before refactoring.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@classmethod | |
@users_ns.doc("create_user_additional_info") | |
@users_ns.response( | |
HTTPStatus.CREATED, f"{messages.ADDITIONAL_INFO_SUCCESSFULLY_CREATED}" | |
) | |
@users_ns.response( | |
HTTPStatus.BAD_REQUEST, | |
f"{messages.USER_ID_IS_NOT_VALID}\n" | |
f"{messages.IS_ORGANIZATION_REP_FIELD_IS_MISSING}\n" | |
f"{messages.TIMEZONE_FIELD_IS_MISSING}" | |
f"{messages.UNEXPECTED_INPUT}" | |
) | |
@users_ns.response( | |
HTTPStatus.FORBIDDEN, f"{messages.USER_ID_IS_NOT_RETRIEVED}" | |
) | |
@users_ns.response( | |
HTTPStatus.INTERNAL_SERVER_ERROR, f"{messages.INTERNAL_SERVER_ERROR}" | |
) | |
@users_ns.expect(auth_header_parser, user_extension_request_body_model, validate=True) | |
def post(cls): | |
""" | |
Creates user additional information | |
A user with valid access token can use this endpoint to add additional | |
information to their own data. The endpoint takes any of the given | |
parameters (is_organization_rep (true or false value), timezone (with | |
value as per Timezone Enum Value) and additional_info (dictionary of | |
phone, mobile and personal_website)). The response contains a success | |
or error message. This request only accessible once user retrieve | |
their user_id by sending GET /user/personal_details. | |
""" | |
token = request.headers.environ["HTTP_AUTHORIZATION"] | |
is_wrong_token = validate_token(token) | |
if not is_wrong_token: | |
data = request.json | |
if not data: | |
return messages.NO_DATA_FOR_UPDATING_PROFILE_WAS_SENT | |
is_field_valid = expected_fields_validator(data, user_extension_request_body_model) | |
if not is_field_valid.get("is_field_valid"): | |
return is_field_valid.get("message"), HTTPStatus.BAD_REQUEST | |
is_not_valid = validate_update_additional_info_request(data) | |
if is_not_valid: | |
return is_not_valid, HTTPStatus.BAD_REQUEST | |
return UserExtensionDAO.create_user_additional_info(data) | |
return is_wrong_token | |
@classmethod | |
@users_ns.doc("update_user_additional_info") | |
@users_ns.response( | |
HTTPStatus.CREATED, f"{messages.ADDITIONAL_INFO_SUCCESSFULLY_CREATED}" | |
) | |
@users_ns.response( | |
HTTPStatus.BAD_REQUEST, | |
f"{messages.USER_ID_IS_NOT_VALID}\n" | |
f"{messages.IS_ORGANIZATION_REP_FIELD_IS_MISSING}\n" | |
f"{messages.TIMEZONE_FIELD_IS_MISSING}" | |
f"{messages.UNEXPECTED_INPUT}" | |
) | |
@users_ns.response( | |
HTTPStatus.FORBIDDEN, f"{messages.USER_ID_IS_NOT_RETRIEVED}" | |
) | |
@users_ns.response( | |
HTTPStatus.INTERNAL_SERVER_ERROR, f"{messages.INTERNAL_SERVER_ERROR}" | |
) | |
@users_ns.expect(auth_header_parser, user_extension_request_body_model, validate=True) | |
def put(cls): | |
""" | |
Updates user additional information | |
A user with valid access token can use this endpoint to update additional | |
information to their own data. The endpoint takes any of the given | |
parameters (is_organization_rep (true or false value), timezone (with | |
value as per Timezone Enum Value) and additional_info (dictionary of phone, | |
mobile and personal_website)). The response contains a success or error | |
message. This request only accessible once user retrieve their user_id | |
by sending GET /user/personal_details. | |
""" | |
token = request.headers.environ["HTTP_AUTHORIZATION"] | |
is_wrong_token = validate_token(token) | |
if not is_wrong_token: | |
data = request.json | |
if not data: | |
return messages.NO_DATA_FOR_UPDATING_PROFILE_WAS_SENT | |
is_field_valid = expected_fields_validator(data, user_extension_request_body_model) | |
if not is_field_valid.get("is_field_valid"): | |
return is_field_valid.get("message"), HTTPStatus.BAD_REQUEST | |
is_not_valid = validate_update_additional_info_request(data) | |
if is_not_valid: | |
return is_not_valid, HTTPStatus.BAD_REQUEST | |
return UserExtensionDAO.update_user_additional_info(data); | |
return is_wrong_token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment