Exemplo n.º 1
0
    def events_by_interests_filter_builder(user_id):
        def intersection(list1, list2):
            return [element for element in list1 if element in list2]

        def interests_in_event(event):
            event_interests = [
                interest.label for user in event.users
                for interest in user.interests
            ]
            event_interests = list(set(event_interests))  # Removing duplicates

            return event_interests

        user_interests = [
            interest.label
            for interest in UserService.get_user_by_id(user_id).interests
        ]

        return lambda event: intersection(interests_in_event(event),
                                          user_interests) is not []
Exemplo n.º 2
0
def user_resource():

    if request.method == 'GET':
        user_id = flask_jwt.current_identity.id
        user = UserService.get_user_by_id(user_id=user_id)

        if not user:
            return 'User does not exist', status.HTTP_404_NOT_FOUND
        else:
            return jsonify(user), status.HTTP_200_OK

    if request.method == 'PUT':
        payload = request.get_json()
        user_id = flask_jwt.current_identity.id
        user = UserService.update_user(user_id, payload['age'], payload['bio'],
                                       payload['firstName'],
                                       payload['lastName'],
                                       payload['interests'])

        if not user:
            return 'User does not exist', status.HTTP_404_NOT_FOUND
        else:
            return jsonify(user), status.HTTP_200_OK
Exemplo n.º 3
0
 def identity(payload):
     return UserService.get_user_by_id(payload['identity'])