Example #1
0
    def delete(self, request, pk=None, *args, **kwargs):
        try:
            post = self.get_and_check(pk)
            if post.user_id != request.user.id:
                raise exceptions.PermissionDenied()

            PostService.delete_comment(post)
            return Response(status=status.HTTP_204_NO_CONTENT)

        except Exception as exception:
            raise ServiceException(exception)
Example #2
0
 def get_post_of_friend(self, request):
     try:
         data = PostService.get_post_of_friend(request.user.id)
         # post_user = PostService.get_post_of_user(request.user.id)
         # data.append(post_user)
         return Response(data)
     except Exception as exception:
         raise exception
Example #3
0
    def get_and_check(self, pk):
        post = PostService.get_post(pk)
        if not post:
            raise exceptions.NotFound()

        return post
Example #4
0
 def get_list_post_of_user(self, request):
     try:
         user_id = request.data['user_id']
         return Response(PostService.get_post_of_user(user_id))
     except Exception as exception:
         raise exception
Example #5
0
 def list(self, request):
     try:
         return Response(PostService.get_post_of_user(request.user.id))
     except Exception as exception:
         raise exception
Example #6
0
 def update(self, instance, validated_data):
     return PostService.save(validated_data, instance)
Example #7
0
 def create(self, validated_data):
     return PostService.save(validated_data)