From d90b27732896b9df7739c0a9903aa66e012f4429 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Fri, 15 Jul 2022 19:49:10 +0530 Subject: [PATCH] Client APIs created --- client/admin.py | 3 ++- client/models.py | 2 +- client/urls.py | 10 ++++++++++ client/views.py | 40 +++++++++++++++++++++++++++++++++++++++- employee/models.py | 2 +- workx_backend/urls.py | 14 +++++++------- workx_backend/views.py | 21 --------------------- 7 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 client/urls.py delete mode 100644 workx_backend/views.py diff --git a/client/admin.py b/client/admin.py index 8c38f3f..ca0dcf1 100644 --- a/client/admin.py +++ b/client/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin +from .models import TaxType, Country, State, City, Client -# Register your models here. +admin.site.register([TaxType, Country, State, City, Client]) diff --git a/client/models.py b/client/models.py index 3bfe293..4069e54 100644 --- a/client/models.py +++ b/client/models.py @@ -3,7 +3,7 @@ from django.db import models class TaxType(models.Model): name = models.CharField(max_length=15) - percentage = models.DecimalField(max_digits=3, decimal_places=2) + percentage = models.DecimalField(max_digits=5, decimal_places=2) def __str__(self): return self.name diff --git a/client/urls.py b/client/urls.py new file mode 100644 index 0000000..61e17d0 --- /dev/null +++ b/client/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('tax-types/', views.TaxTypeList.as_view()), + path('countries/', views.CountryList.as_view()), + path('states/', views.StateList.as_view()), + path('cities/', views.CityList.as_view()), + path('clients/', views.ClientList.as_view()) +] diff --git a/client/views.py b/client/views.py index 2800278..f4b83eb 100644 --- a/client/views.py +++ b/client/views.py @@ -1,2 +1,40 @@ -from django.shortcuts import render +from rest_framework.response import Response +from rest_framework.views import APIView +from .models import TaxType, Country, State, City, Client +from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer + + +class TaxTypeList(APIView): + def get(self, request): + tax_types = TaxType.objects.all() + serializer = TaxTypeSerializer(tax_types, many=True) + return Response(serializer.data) + + +class CountryList(APIView): + def get(self, request): + countries = Country.objects.all() + serializer = CountrySerializer(countries, many=True) + return Response(serializer.data) + + +class StateList(APIView): + def get(self, request): + states = State.objects.all() + serializer = StateSerializer(states, many=True) + return Response(serializer.data) + + +class CityList(APIView): + def get(self, request): + cities = City.objects.all() + serializer = CitySerializer(cities, many=True) + return Response(serializer.data) + + +class ClientList(APIView): + def get(self, request): + clients = Client.objects.all() + serializer = ClientSerializer(clients, many=True) + return Response(serializer.data) diff --git a/employee/models.py b/employee/models.py index 31ee860..fd0fb66 100644 --- a/employee/models.py +++ b/employee/models.py @@ -8,7 +8,7 @@ class Employee(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) employee_id = models.CharField(max_length=15) phone = PhoneNumberField() - salary = models.DecimalField(max_digits=10, decimal_places=2) + salary = models.DecimalField(max_digits=15, decimal_places=2) start_date = models.DateField() end_date = models.DateField(null=True, blank=True) projects = models.ManyToManyField(Project) diff --git a/workx_backend/urls.py b/workx_backend/urls.py index 1681259..fd89be1 100644 --- a/workx_backend/urls.py +++ b/workx_backend/urls.py @@ -1,10 +1,10 @@ from django.contrib import admin from django.urls import path, include -from rest_framework import routers -from workx_backend.views import UserViewSet, test_mail from rest_framework import permissions from drf_yasg.views import get_schema_view from drf_yasg import openapi +from client import urls as clientUrls + schema_view = get_schema_view( openapi.Info( @@ -19,15 +19,15 @@ schema_view = get_schema_view( permission_classes=[permissions.AllowAny], ) -router = routers.DefaultRouter() -router.register(r'users', UserViewSet) urlpatterns = [ path('workx/', include([ + path('admin/', admin.site.urls), + path('', include('drfpasswordless.urls')), path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), - path('admin/', admin.site.urls), - path('api/', include(router.urls)), - path('', include('drfpasswordless.urls')) + path('api/', include([ + path('', include(clientUrls)) + ])) ])), ] diff --git a/workx_backend/views.py b/workx_backend/views.py deleted file mode 100644 index 100d26a..0000000 --- a/workx_backend/views.py +++ /dev/null @@ -1,21 +0,0 @@ -from django.contrib.auth.models import User -from django.core.mail import send_mail -from django.http import HttpResponse -from rest_framework import viewsets -from workx_backend.serializers import UserSerializer - - -class UserViewSet(viewsets.ModelViewSet): - queryset = User.objects.all() - serializer_class = UserSerializer - - -def test_mail(request, *args, **kwargs): - send_mail('This is the title of the email', - 'This is the message you want to send', - 'nikhilkj24@gmail.com', - [ - 'nikhilkj.webtrigon@gmail.com', # add more emails to this list of you want to - ] - ) - return HttpResponse('Done')