Skip to content

Commit

Permalink
created crud apis for attendance, events, post and cmments
Browse files Browse the repository at this point in the history
  • Loading branch information
walosha committed Jan 17, 2023
1 parent e65438c commit 7b76884
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 8 deletions.
8 changes: 6 additions & 2 deletions attendance/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from rest_framework.routers import DefaultRouter
from django.urls import path, include
from .views import AttendanceListCreateAPIView, AttendanceRetrieveAPIView
from .views import AttendanceListCreateAPIView, AttendanceRetrieveAPIView, AttendanceUpdateAPIView, AttendanceDestroyAPIView

urlpatterns = [
path('<int:pk>/', AttendanceRetrieveAPIView.as_view(),
path('<uuid:pk>/', AttendanceRetrieveAPIView.as_view(),
name="attendance_detail"),
path('<uuid:pk>/', AttendanceUpdateAPIView.as_view(),
name="attendance_update"),
path('<uuid:pk>/', AttendanceDestroyAPIView.as_view(),
name="attendance_delete"),
path('', AttendanceListCreateAPIView.as_view(), name="attendance_list")
]
10 changes: 10 additions & 0 deletions attendance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ class AttendanceListCreateAPIView(generics.ListCreateAPIView):
class AttendanceRetrieveAPIView(generics.RetrieveAPIView):
queryset = Attendance.objects.all()
serializer_class = AttendanceSerializer


class AttendanceUpdateAPIView(generics.UpdateAPIView):
queryset = Attendance.objects.all()
serializer_class = AttendanceSerializer


class AttendanceDestroyAPIView(generics.DestroyAPIView):
queryset = Attendance.objects.all()
serializer_class = AttendanceSerializer
20 changes: 20 additions & 0 deletions blog/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# django #selenium #webscraping
from rest_framework import serializers
from django.contrib.auth.models import User, Group
from .models import Post, Comment


class PostSerializer(serializers.ModelSerializer):
class Meta:
model = Post
# fields = ('id', 'title', 'description', 'completed')
# Shortcut for getting all fields
fields = '__all__'


class CommentSerializer(serializers.ModelSerializer):
class Meta:
model = Comment
# fields = ('id', 'title', 'description', 'completed')
# Shortcut for getting all fields
fields = '__all__'
17 changes: 17 additions & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.urls import path, include
from .views import PostListCreateAPIView, PostRetrieveAPIView, PostDestroyAPIView, PostUpdateAPIView, CommentListCreateAPIView, CommentRetrieveAPIView, CommentDestroyAPIView, CommentUpdateAPIView

urlpatterns = [
path('posts/<uuid:pk>/', PostRetrieveAPIView.as_view(),
name="Post_detail"),
path('posts/', PostListCreateAPIView.as_view(), name="post_list"),
path('posts/<uuid:pk>/', PostUpdateAPIView.as_view(), name="post_update"),
path('posts/<uuid:pk>/', PostDestroyAPIView.as_view(),
name="post_delete"),
path('coments/<uuid:pk>/', CommentRetrieveAPIView.as_view(),
name="comment_detail"),
path('coments/', CommentListCreateAPIView.as_view(), name="comment_list"),
path('coments/<uuid:pk>/', CommentUpdateAPIView.as_view(), name="comment_update"),
path('coments/<uuid:pk>/', CommentDestroyAPIView.as_view(),
name="event_delete"),
]
47 changes: 45 additions & 2 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from django.shortcuts import render
from .models import Post, Comment
from .serializers import PostSerializer, CommentSerializer
from rest_framework import generics

# Create your views here.

# Post serializer

class PostListCreateAPIView(generics.ListCreateAPIView):
queryset = Post.objects.all()
serializer_class = PostSerializer


class PostRetrieveAPIView(generics.RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostSerializer


class PostUpdateAPIView(generics.UpdateAPIView):
queryset = Post.objects.all()
serializer_class = PostSerializer


class PostDestroyAPIView(generics.DestroyAPIView):
queryset = Post.objects.all()
serializer_class = PostSerializer


# Commment serializer
class CommentListCreateAPIView(generics.ListCreateAPIView):
queryset = Comment.objects.all()
serializer_class = CommentSerializer


class CommentRetrieveAPIView(generics.RetrieveAPIView):
queryset = Comment.objects.all()
serializer_class = CommentSerializer


class CommentUpdateAPIView(generics.UpdateAPIView):
queryset = Comment.objects.all()
serializer_class = CommentSerializer


class CommentDestroyAPIView(generics.DestroyAPIView):
queryset = Comment.objects.all()
serializer_class = CommentSerializer
2 changes: 1 addition & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
}

SPECTACULAR_SETTINGS = {
'SCHEMA_PATH_PREFIX': r'/api/v1',
'SCHEMA_PATH_PREFIX': r'/api',
'DEFAULT_GENERATOR_CLASS': 'drf_spectacular.generators.SchemaGenerator',
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
'COMPONENT_SPLIT_PATCH': True,
Expand Down
1 change: 1 addition & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
path('api/auth/', include('account.urls')),
path('api/attendances/', include('attendance.urls')),
path('api/events/', include('event.urls')),
path('api/', include('blog.urls')),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
# Optional UI:
path('api/doc/',
Expand Down
9 changes: 6 additions & 3 deletions event/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.urls import path, include
from .views import EventListCreateAPIView, EventRetrieveAPIView
from .views import EventListCreateAPIView, EventRetrieveAPIView, EventDestroyAPIView, EventUpdateAPIView

urlpatterns = [
path('<int:pk>/', EventRetrieveAPIView.as_view(),
path('<uuid:pk>/', EventRetrieveAPIView.as_view(),
name="event_detail"),
path('', EventListCreateAPIView.as_view(), name="event_list")
path('', EventListCreateAPIView.as_view(), name="event_list"),
path('<uuid:pk>/', EventUpdateAPIView.as_view(), name="event_update"),
path('<uuid:pk>/', EventDestroyAPIView.as_view(),
name="event_delete"),
]
10 changes: 10 additions & 0 deletions event/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ class EventListCreateAPIView (generics.ListCreateAPIView):
class EventRetrieveAPIView (generics.RetrieveAPIView):
queryset = Event.objects.all()
serializer_class = EventSerializer


class EventDestroyAPIView (generics.DestroyAPIView):
queryset = Event.objects.all()
serializer_class = EventSerializer


class EventUpdateAPIView (generics.UpdateAPIView):
queryset = Event.objects.all()
serializer_class = EventSerializer
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
- Email marketing
- Live streeming
- schedule meetings
- Video and audio for sermons

0 comments on commit 7b76884

Please sign in to comment.