Created
August 8, 2020 00:02
-
-
Save mtreacy002/265e4fa6ab81808b0f2f816bccfea2ac to your computer and use it in GitHub Desktop.
After refactoring POST PUT to just PUT /user/additional_info
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("update_user_additional_info") | |
@users_ns.response( | |
HTTPStatus.OK, f"{messages.ADDITIONAL_INFO_SUCCESSFULLY_UPDATED}" | |
) | |
@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}\n" | |
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): | |
""" | |
Creates or updates user additional information | |
A user with valid access token can use this endpoint to create or 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 retrieves 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, HTTPStatus.BAD_REQUEST | |
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