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)
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
def get_and_check(self, pk): post = PostService.get_post(pk) if not post: raise exceptions.NotFound() return post
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
def list(self, request): try: return Response(PostService.get_post_of_user(request.user.id)) except Exception as exception: raise exception
def update(self, instance, validated_data): return PostService.save(validated_data, instance)
def create(self, validated_data): return PostService.save(validated_data)