This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
from ..serializers import RegisterSerializer | |
from rest_framework.decorators import api_view | |
from django.views.decorators.csrf import csrf_exempt | |
from rest_framework import status | |
@csrf_exempt | |
@api_view(['POST']) | |
def createAccount(request): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
from ..models import Notice | |
from rest_framework import permissions | |
from rest_framework.decorators import api_view | |
from rest_framework.decorators import permission_classes | |
from rest_framework.permissions import IsAuthenticated | |
@api_view(['GET']) | |
@permission_classes([permissions.IsAuthenticated]) | |
def listAllNotices(request): | |
output = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from .views import user | |
from .views import notices | |
from rest_framework_simplejwt import views as jwt_views | |
urlpatterns = [ | |
path('register', user.createAccount, name='createAccount'), | |
path('login/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'), | |
path('token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'), | |
path('listAllNotices', notices.listAllNotices, name='listAllNotices'), | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import include, re_path | |
from django.contrib import admin | |
urlpatterns = [ | |
re_path('notices/', include('notices.urls')), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .models import Notice | |
from .serializers import NoticeSerializer | |
from rest_framework import viewsets | |
from .pagination import CustomPagination | |
from rest_framework.exceptions import ValidationError | |
class NoticeModelViewSet(viewsets.ModelViewSet): | |
queryset = Notice.objects.all() | |
serializer_class = NoticeSerializer | |
pagination_class = CustomPagination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import pagination | |
class CustomPagination(pagination.PageNumberPagination): | |
page_size = 2 | |
page_size_query_param = 'page_size' | |
max_page_size = 50 | |
page_query_param = 'p' | |
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 3 columns, instead of 2. in line 4.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VERB,URL, DESCRIPTION | |
GET,http://127.0.0.1:8000//api/v1/notices/,List all Notices | |
GET,http://127.0.0.1:8000/api/v1/notices/?kw=Hello,List all Notices containing Hello as Title | |
GET,http://127.0.0.1:8000/api/v1/notices/?p=2&order=-id,List second page order by id descending | |
GET,http://127.0.0.1:8000/api/v1/notices/ | |
?p=2&kw=Hello&order=-id,List second page containing title Hello order by id descending | |
GET,http://127.0.0.1:8000//api/v1/notices/1, Get Single notice whose id is 1 | |
POST,http://127.0.0.1:8000//api/v1/notices/, Create new notice using title and description as params | |
PUT,http://127.0.0.1:8000//api/v1/notices/5/, Update ALL PARAMS existig notice with id =5 | |
PATCH,http://127.0.0.1:8000//api/v1/notices/5/, Partial update (Selected fields) existig notice with id =5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import routers | |
from notices import views as noticeAppViews | |
router = routers.DefaultRouter() | |
router.register(r'notices', noticeAppViews.NoticeModelViewSet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import include, path | |
from .api import router | |
urlpatterns = [ | |
path('api/v1/', include(router.urls)), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asgiref==3.7.2 | |
Django==4.2.3 | |
django-environ==0.10.0 | |
djangorestframework==3.14.0 | |
pytz==2023.3 | |
sqlparse==0.4.4 |