Переглянути джерело

Client APIs created

master
kj1352 3 роки тому
джерело
коміт
d90b277328
7 змінених файлів з 60 додано та 32 видалено
  1. +2
    -1
      client/admin.py
  2. +1
    -1
      client/models.py
  3. +10
    -0
      client/urls.py
  4. +39
    -1
      client/views.py
  5. +1
    -1
      employee/models.py
  6. +7
    -7
      workx_backend/urls.py
  7. +0
    -21
      workx_backend/views.py

+ 2
- 1
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])

+ 1
- 1
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


+ 10
- 0
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())
]

+ 39
- 1
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)

+ 1
- 1
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)


+ 7
- 7
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))
]))
])),
]

+ 0
- 21
workx_backend/views.py Переглянути файл

@@ -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')