Esempio n. 1
0
class UserResourceList(MethodResource):
    user_service = UserService()

    @marshal_with(UserModelSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserModelSchema().fields)
    })
    @doc(description='return all users')
    def get(self, **kwargs):
        _ = get_token_info()
        page = kwargs.pop('page')
        limit = kwargs.pop('limit')

        return self.user_service.get_multiple(
            page=page, limit=limit, kwarg_filters=kwargs), status.HTTP_200_OK

    @use_kwargs({
        **UserModelSchema().fields, 'password':
        fields.String(required=True)
    })
    @marshal_with(UserModelSchema, code=status.HTTP_201_CREATED)
    @doc(description='Create a new user')
    def post(self, **kwargs):
        password = kwargs.pop('password')
        salt = 'LoboLObOlOBo'
        kwargs['hashed_password'] = md5(
            f"{password}{salt}".encode()).hexdigest()
        new_user = self.user_service.create(**kwargs)
        return new_user, status.HTTP_201_CREATED
Esempio n. 2
0
class ConversationList(MethodResource):
    conversation_service = ConversationService()
    @use_kwargs({**unrequire(ConversationModelSchema().fields)})
    @marshal_with(ConversationModelSchema, code=status.HTTP_201_CREATED)
    @doc(description='generate a conversation from two users')
    def post(self, **kwargs):
        _ = get_token_info()
        self.conversation_service.create(**kwargs)
        return []
Esempio n. 3
0
class UsersNearbyResourceList(MethodResource):
    user_service = UserService()

    @marshal_with(UserModelSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserModelSchema().fields)
    })
    @doc(description='return all nearby guides')
    def get(self, **kwargs):
        _ = get_token_info()
        uid = kwargs.pop('uid')
        page = kwargs.pop('page')
        limit = kwargs.pop('limit')

        return self.user_service.get_multiple_nearby(
            uid=uid, ), status.HTTP_200_OK
Esempio n. 4
0
class UserServiceResourceList(MethodResource):
    service_service = ServiceService()

    @marshal_with(UserServiceSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserModelSchema().fields)
    })
    @doc(description='return all reviews associate with a user')
    def get(self, user_id, **kwargs):
        _ = get_token_info()
        service_ids = UserServiceRelationModel.query.filter(
            UserServiceRelationModel.user_id == user_id).all()
        result = []
        for service in service_ids:
            model = self.service_service.get_by_id(service.service_id)
            model.is_expert = service.is_expert
            result.append(model)
        return result, status.HTTP_200_OK
Esempio n. 5
0
class UserReviewResourceList(MethodResource):
    user_event_service = UserEventService()
    review_service = ReviewService()

    @marshal_with(UserReviewSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserModelSchema().fields)
    })
    @doc(description='return all reviews associate with a user')
    def get(self, user_id, **kwargs):
        _ = get_token_info()
        review_ids = ReviewModel.query.filter(
            ReviewModel.user_id == user_id).all()
        result = []
        for review in review_ids:
            model = self.review_service.get_by_id(review.id)
            result.append(model)
        return result, status.HTTP_200_OK
Esempio n. 6
0
class UserEventResourceList(MethodResource):
    user_event_service = UserEventService()
    event_service = EventService()

    @marshal_with(UserEventSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserModelSchema().fields)
    })
    @doc(description='return all events associate with a user')
    def get(self, user_id, **kwargs):
        _ = get_token_info()
        event_ids = UserEventRelationModel.query.filter(
            or_(UserEventRelationModel.user_id_one == user_id,
                UserEventRelationModel.user_id_two == user_id)).all()
        result = []
        for event in event_ids:
            model = self.event_service.get_by_id(event.event_id)
            result.append(model)
        return result, status.HTTP_200_OK
Esempio n. 7
0
class EventResourceDetail(MethodResource):
    event_service = EventService()

    @marshal_with(EventModelSchema, code=status.HTTP_200_OK)
    @doc(description='return event with id')
    def get(self, event_id, **kwargs):
        _ = get_token_info()
        result = self.event_service.get_by_id(event_id)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK

    @marshal_with(None, code=status.HTTP_204_NO_CONTENT)
    @doc(description='delete a event')
    def delete(self, event_id, **kwargs):
        _ = get_token_info()
        result = self.event_service.delete_by_id(event_id)
        if result == False:
            abort(status.HTTP_404_NOT_FOUND)
        return make_response('', status.HTTP_204_NO_CONTENT)

    @use_kwargs(EventModelSchema().fields)
    @marshal_with(EventModelSchema, code=status.HTTP_200_OK)
    @doc(description='update a existing event')
    def put(self, event_id, **kwargs):
        _ = get_token_info()
        result = self.event_service.update_by_id(event_id, kwargs)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK

    @use_kwargs(unrequire(EventModelSchema().fields))
    @doc(description='partially update a event')
    @marshal_with(EventModelSchema, code=status.HTTP_200_OK)
    def patch(self, event_id, **kwargs):
        _ = get_token_info()
        result = self.event_service.update_by_id(event_id, kwargs)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK
Esempio n. 8
0
class ServiceResourceDetail(MethodResource):
    service_service = ServiceService()

    @marshal_with(ServiceModelSchema, code=status.HTTP_200_OK)
    @doc(description='return service with id')
    def get(self, service_id, **kwargs):
        _ = get_token_info()
        result = self.service_service.get_by_id(service_id)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK

    @marshal_with(None, code=status.HTTP_204_NO_CONTENT)
    @doc(description='delete a service')
    def delete(self, service_id, **kwargs):
        _ = get_token_info()
        result = self.service_service.delete_by_id(service_id)
        if result == False:
            abort(status.HTTP_404_NOT_FOUND)
        return make_response('', status.HTTP_204_NO_CONTENT)

    @use_kwargs(ServiceModelSchema().fields)
    @marshal_with(ServiceModelSchema, code=status.HTTP_200_OK)
    @doc(description='update a existing service')
    def put(self, service_id, **kwargs):
        _ = get_token_info()
        result = self.service_service.update_by_id(service_id, kwargs)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK

    @use_kwargs(unrequire(ServiceModelSchema().fields))
    @doc(description='partially update a recurring frequency')
    @marshal_with(ServiceModelSchema, code=status.HTTP_200_OK)
    def patch(self, service_id, **kwargs):
        _ = get_token_info()
        result = self.service_service.update_by_id(service_id, kwargs)
        if result == None:
            abort(status.HTTP_404_NOT_FOUND)
        return result, status.HTTP_200_OK
Esempio n. 9
0
class UserEventResourceList(MethodResource):
    event_service = UserEventService()

    @marshal_with(UserEventRelationModelSchema(many=True),
                  code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(UserEventRelationModelSchema().fields)
    })
    @doc(description='return all user_events')
    def get(self, **kwargs):
        _ = get_token_info()
        page = kwargs.pop('page')
        limit = kwargs.pop('limit')

        return self.event_service.get_multiple(
            page=page, limit=limit, kwarg_filters=kwargs), status.HTTP_200_OK

    @use_kwargs({
        **UserEventRelationModelSchema().fields, 'user_id_one':
        fields.Integer(required=True),
        'user_id_two':
        fields.Integer(required=True)
    })
    @marshal_with(UserEventRelationModelSchema, code=status.HTTP_201_CREATED)
    @doc(description='Create a new event')
    def post(self, **kwargs):
        _ = get_token_info()
        user_id_one = kwargs.pop('user_id_one')
        user_id_two = kwargs.pop('user_id_two')
        created = self.event_service.create(**kwargs)
        user_event_service = UserEventService()
        user_event_service.create(
            **{
                'user_id_one': user_id_one,
                'user_id_two': user_id_two,
                'event_id': created.id
            })
        return created, status.HTTP_201_CREATED
Esempio n. 10
0
class ServiceResourceList(MethodResource):
    service_service = ServiceService()

    @marshal_with(ServiceModelSchema(many=True), code=status.HTTP_200_OK)
    @use_kwargs({
        **RequestParams.pagination_params(),
        **unrequire(ServiceModelSchema().fields)
    })
    @doc(description='return all services')
    def get(self, **kwargs):
        _ = get_token_info()
        page = kwargs.pop('page')
        limit = kwargs.pop('limit')

        return self.service_service.get_multiple(
            page=page, limit=limit, kwarg_filters=kwargs), status.HTTP_200_OK

    @use_kwargs(ServiceModelSchema().fields)
    @marshal_with(ServiceModelSchema, code=status.HTTP_201_CREATED)
    @doc(description='Create a new service')
    def post(self, **kwargs):
        _ = get_token_info()
        new_service = self.service_service.create(**kwargs)
        return new_service, status.HTTP_201_CREATED