Ejemplo n.º 1
0
    def create(self, request, *args, **kwargs):
        """
        Create a new star for a point.

        Path parameters:
            - point_pk: id of the point the star is for.

        Errors:
            - a star by the user already exists (409)

        Returns:
            - created star object.
        """

        try:
            star = Star.objects.get(point=self.kwargs['point_pk'],
                                    creator=request.user.id)
            if star:
                return Response(
                    {
                        'detail':
                        'A star for this point by this user already exists.'
                    },
                    status=409)
        except Star.DoesNotExist:
            pass

        response = super().create(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=201)
Ejemplo n.º 2
0
    def create(self, request, *args, **kwargs):
        """
        Create a new point.

        Errors:
            - a point with the same name by the user already exists (409)

        Returns:
            - created point object.
        """

        try:
            point = Point.objects.get(name=request.data.get('name'),
                                      creator=request.user.id)
            if point:
                return Response(
                    {
                        'detail':
                        'A point with this name by this user already exists.'
                    },
                    status=409)
        except Point.DoesNotExist:
            pass

        response = super().create(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=201)
Ejemplo n.º 3
0
    def create(self, request, *args, **kwargs):
        """
        Create a new tag for a point.

        Path parameters:
            - point_pk: id of the point the tag is for.

        Errors:
            - the creator of the tag is not the creator of the point (403)

        Returns:
            - created tag object.
        """

        point = get_object_or_404(
            Point.objects.filter(id=self.kwargs['point_pk']))
        if point.creator.id != request.user.id:
            return Response(
                {
                    'detail':
                    'Only the creator of the point can create tags for it.'
                },
                status=403)

        response = super().create(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=201)
Ejemplo n.º 4
0
    def update(self, request, *args, **kwargs):
        """
        Update a single user's details.

        Returns:
            - updated user object.
        """

        response = super().update(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=200)
Ejemplo n.º 5
0
    def update(self, request, *args, **kwargs):
        """
        Update a single tags's details for a point.

        Returns:
            - updated tag object.
        """

        response = super().update(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request)
Ejemplo n.º 6
0
    def create(self, request, *args, **kwargs):
        """
        Create a new comment for a point.

        Path parameters:
            - point_pk: id of the point the comment is for.

        Returns:
            - created comment object.
        """

        response = super().create(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=201)
Ejemplo n.º 7
0
    def retrieve(self, request, pk=None):
        """
        Get a single user.

        Path parameters:
            - pk: id of the user.

        Returns:
            - single user object.
        """

        queryset = User.objects.filter()
        user = get_object_or_404(queryset, pk=pk)
        serializer = UserSerializer(user,
                                    context={
                                        'request': request,
                                        'action': 'retrieve'
                                    })
        return LinkedInstanceResponse(serializer.data, request)
Ejemplo n.º 8
0
    def retrieve(self, request, pk=None):
        """
        Get a single point.

        Path parameters:
            - pk: id of the point to retrieve.

        Returns:
            - single point object.
        """

        queryset = Point.objects.filter(pk=pk)
        point = get_object_or_404(queryset, pk=pk)
        serializer = PointSerializer(point,
                                     context={
                                         'request': request,
                                         'action': 'retrieve'
                                     })
        return LinkedInstanceResponse(serializer.data, request)
Ejemplo n.º 9
0
    def retrieve(self, request, pk=None, user_pk=None):
        """
        Get a single star of a specified user.

        Path parameters:
            - user_pk: id of the user whose star is retrieved.
            - pk: id of the star to retrieve.

        Returns:
            - single star object of the specified user.
        """
        queryset = Star.objects.filter(pk=pk, creator=user_pk)
        star = get_object_or_404(queryset, pk=pk)
        serializer = StarSerializer(star,
                                    context={
                                        'request': request,
                                        'action': 'retrieve'
                                    })
        return LinkedInstanceResponse(serializer.data, request)
Ejemplo n.º 10
0
    def retrieve(self, request, pk=None, point_pk=None):
        """
        Get a single star for a point.

        Path parameters:
            - point_pk: id of the point the star is for.
            - pk: id of the star to retrieve.

        Returns:
            - single star object.
        """

        queryset = Star.objects.filter(pk=pk, point=point_pk)
        star = get_object_or_404(queryset, pk=pk)
        serializer = StarSerializer(star,
                                    context={
                                        'request': request,
                                        'action': 'retrieve'
                                    })
        return LinkedInstanceResponse(serializer.data, request)
Ejemplo n.º 11
0
    def create(self, request, *args, **kwargs):
        """
        Create a new user.

        Errors:
            - a user with the same username already exists (409)

        Returns:
            - created user object.
        """

        try:
            user = User.objects.get(username=request.data.get('username'))
            if user:
                return Response(
                    {'detail': 'A user with this username already exists.'},
                    status=409)
        except User.DoesNotExist:
            pass

        response = super().create(request, *args, **kwargs)
        return LinkedInstanceResponse(response.data, request, status=201)