<reponame>KoliosterNikolayIliev/vozila_backend<gh_stars>0
from rest_framework import generics, permissions

from vozila_backend.common.Like_Dislike_Follow_functionality import like_dislike_follow_toggle
from vozila_backend.common.permisions import IsOwnerOrReadOnly
from vozila_backend.common.serialisers import ProjectPostSerializer, LikePSerializer, CommentPSerializer
from vozila_specials.models import ProjectPost, LikeP, CommentP


class GetListProjectPostsView(generics.ListCreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = ProjectPost.objects.all()
    serializer_class = ProjectPostSerializer

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)


class DetailsEditDeleteProjectPostView(generics.RetrieveUpdateDestroyAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = ProjectPost.objects.all()
    serializer_class = ProjectPostSerializer


class CreateLikeDislikePView(generics.CreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    queryset = LikeP.objects.all()
    serializer_class = LikePSerializer

    def perform_create(self, serializer):
        pass

    def create(self, request, *args, **kwargs):
        super().create(request, *args, **kwargs)
        return like_dislike_follow_toggle(request, *args, **kwargs)


class CreateAndListCommentsPView(generics.ListCreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    queryset = CommentP.objects.all()
    serializer_class = CommentPSerializer

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)


class DetailsEditDeleteCommentPView(generics.RetrieveUpdateDestroyAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = CommentP.objects.all()
    serializer_class = CommentPSerializer

from rest_framework import generics, permissions

from vozila_backend.common.Like_Dislike_Follow_functionality import like_dislike_follow_toggle
from vozila_backend.common.permisions import IsOwnerOrReadOnly
from vozila_backend.common.serialisers import ProjectPostSerializer, LikePSerializer, CommentPSerializer
from vozila_specials.models import ProjectPost, LikeP, CommentP


class GetListProjectPostsView(generics.ListCreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = ProjectPost.objects.all()
    serializer_class = ProjectPostSerializer

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)


class DetailsEditDeleteProjectPostView(generics.RetrieveUpdateDestroyAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = ProjectPost.objects.all()
    serializer_class = ProjectPostSerializer


class CreateLikeDislikePView(generics.CreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    queryset = LikeP.objects.all()
    serializer_class = LikePSerializer

    def perform_create(self, serializer):
        pass

    def create(self, request, *args, **kwargs):
        super().create(request, *args, **kwargs)
        return like_dislike_follow_toggle(request, *args, **kwargs)


class CreateAndListCommentsPView(generics.ListCreateAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    queryset = CommentP.objects.all()
    serializer_class = CommentPSerializer

    def perform_create(self, serializer):
        serializer.save(user=self.request.user)


class DetailsEditDeleteCommentPView(generics.RetrieveUpdateDestroyAPIView):
    permission_classes = [permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
    queryset = CommentP.objects.all()
    serializer_class = CommentPSerializer