Skip to content

Commit

Permalink
feat: anons update read by endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Shavkatjon-O committed Sep 10, 2024
1 parent e77dd1f commit 795f80a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 0 deletions.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions apps/anons/api/AnonsReadUpdate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .views import *
11 changes: 11 additions & 0 deletions apps/anons/api/AnonsReadUpdate/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from rest_framework import serializers
from apps.anons.models import Anons


class AnonsReadUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = Anons
fields = ("id",)


__all__ = ("AnonsReadUpdateSerializer",)
20 changes: 20 additions & 0 deletions apps/anons/api/AnonsReadUpdate/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from rest_framework.generics import UpdateAPIView
from rest_framework.permissions import IsAuthenticated

from apps.anons.models import Anons
from apps.anons.api.AnonsReadUpdate.serializers import AnonsReadUpdateSerializer


class AnonsReadUpdate(UpdateAPIView):
serializer_class = AnonsReadUpdateSerializer
permission_classes = (IsAuthenticated,)

def perform_update(self, serializer):
anons = Anons.objects.get(pk=self.kwargs["pk"])

if not anons.read_by.filter(id=self.request.user.id).exists():
anons.read_by.add(self.request.user)
anons.save()


__all__ = ("AnonsReadUpdate",)
1 change: 1 addition & 0 deletions apps/anons/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .AnonsList import *
from .AnonsReadUpdate import *
from .AnonsDetail import *
2 changes: 2 additions & 0 deletions apps/anons/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.urls import path

from apps.anons.api.AnonsList.views import AnonsListView
from apps.anons.api.AnonsReadUpdate.views import AnonsReadUpdate
from apps.anons.api.AnonsDetail.views import AnonsDetailView

urlpatterns = [
path("", AnonsListView.as_view(), name="anons-list"),
path("<int:pk>/read/", AnonsReadUpdate.as_view(), name="anons-read"),
path("<int:pk>/", AnonsDetailView.as_view(), name="anons-detail"),
]

0 comments on commit 795f80a

Please sign in to comment.