class UserProfileResource(Resource): def __init__(self): self.controller = UserProfileController() @token_required(roles=['Administrator']) @swag_from('/resources/users/description/users_profile_get.yml') @marshal_with(get_profile_fields()) def get(self, public_id: str, profile_id: int, current_user: User) -> Profile: return self.controller.get_by_id(profile_id, current_user, public_id=public_id) @token_required(roles=['Administrator']) @swag_from('/resources/users/description/users_profile_put.yml') @marshal_with(get_profile_fields()) def put(self, public_id: str, profile_id: int, current_user: User) -> Profile: return self.controller.edit(profile_id, current_user, public_id=public_id) @token_required(roles=['Administrator']) @swag_from('/resources/users/description/users_profile_delete.yml') def delete(self, public_id: str, profile_id: int, current_user: User): self.controller.delete(profile_id, current_user, public_id=public_id) return get_delete_response()
def post(self, current_user: User) -> Profile: profile = self.controller.create(current_user) serialized_profile = serialize(profile, get_profile_fields()) json_profile = json.dumps(serialized_profile) response = get_post_response( obj=profile, body=json_profile, content_type='application/json', api='/{rsc}/current/profiles'.format(rsc=API_PREFIX)) return response
class CurrentUserProfileResource(Resource): def __init__(self): self.controller = CurrentUserProfileController() @token_required() @swag_from('/resources/users/description/current_user_profile_get.yml') @marshal_with(get_profile_fields()) def get(self, profile_id, current_user: User) -> Profile: return self.controller.get_by_id(profile_id, current_user) @token_required() @swag_from('/resources/users/description/current_user_profile_put.yml') @marshal_with(get_profile_fields()) def put(self, profile_id, current_user: User) -> Profile: return self.controller.edit(resource_id=profile_id, current_user=current_user) @token_required() @swag_from('/resources/users/description/current_user_profile_delete.yml') def delete(self, profile_id, current_user: User): self.controller.delete(resource_id=profile_id, current_user=current_user) return get_delete_response()
class UserProfileListResource(Resource): def __init__(self): self.controller = UserProfileController() @token_required(roles=['Administrator']) @swag_from('/resources/users/description/users_profile_list_get.yml') @marshal_with(get_profile_fields()) def get(self, public_id, current_user: User) -> List[Profile]: return self.controller.get_list(current_user, public_id=public_id) @token_required(roles=['Administrator']) @swag_from('/resources/users/description/users_profile_list_post.yml') def post(self, public_id, current_user: User) -> Profile: profile = self.controller.create(current_user, public_id=public_id) public_id = profile.user.public_id serialized_profile = serialize(profile, get_profile_fields()) json_profile = json.dumps(serialized_profile) response = get_post_response(obj=profile, body=json_profile, content_type='application/json', api='/{rsc}/{public_id}/profiles'.format( rsc=API_PREFIX, public_id=public_id)) return response