浏览代码

Added employee API

master
kj1352 3 年前
父节点
当前提交
01a563b981
共有 8 个文件被更改,包括 43 次插入12 次删除
  1. +6
    -6
      client/views.py
  2. +2
    -1
      employee/admin.py
  3. +1
    -1
      employee/models.py
  4. +8
    -0
      employee/serializers.py
  5. +6
    -0
      employee/urls.py
  6. +15
    -2
      employee/views.py
  7. +2
    -1
      project/admin.py
  8. +3
    -1
      workx_backend/urls.py

+ 6
- 6
client/views.py 查看文件

@@ -1,13 +1,13 @@
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.authentication import TokenAuthentication
from rest_framework.authentication import TokenAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from .models import TaxType, Country, State, City, Client from .models import TaxType, Country, State, City, Client
from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer




class TaxTypeList(APIView): class TaxTypeList(APIView):
authentication_classes = [TokenAuthentication]
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated] permission_classes = [IsAuthenticated]


def get(self, request): def get(self, request):
@@ -17,7 +17,7 @@ class TaxTypeList(APIView):




class CountryList(APIView): class CountryList(APIView):
authentication_classes = [TokenAuthentication]
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated] permission_classes = [IsAuthenticated]


def get(self, request): def get(self, request):
@@ -27,7 +27,7 @@ class CountryList(APIView):




class StateList(APIView): class StateList(APIView):
authentication_classes = [TokenAuthentication]
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated] permission_classes = [IsAuthenticated]


def get(self, request): def get(self, request):
@@ -37,7 +37,7 @@ class StateList(APIView):




class CityList(APIView): class CityList(APIView):
authentication_classes = [TokenAuthentication]
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated] permission_classes = [IsAuthenticated]


def get(self, request): def get(self, request):
@@ -47,7 +47,7 @@ class CityList(APIView):




class ClientList(APIView): class ClientList(APIView):
authentication_classes = [TokenAuthentication]
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated] permission_classes = [IsAuthenticated]


def get(self, request): def get(self, request):


+ 2
- 1
employee/admin.py 查看文件

@@ -1,3 +1,4 @@
from django.contrib import admin from django.contrib import admin
from .models import Employee


# Register your models here.
admin.site.register([Employee])

+ 1
- 1
employee/models.py 查看文件

@@ -14,4 +14,4 @@ class Employee(models.Model):
projects = models.ManyToManyField(Project) projects = models.ManyToManyField(Project)


def __str__(self): def __str__(self):
return self.user.name
return self.employee_id

+ 8
- 0
employee/serializers.py 查看文件

@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Employee


class EmployeeSerializer(serializers.ModelSerializer):
class Meta:
model = Employee
fields = ['id', 'user', 'employee_id', 'phone', 'salary', 'start_date', 'end_date', 'projects']

+ 6
- 0
employee/urls.py 查看文件

@@ -0,0 +1,6 @@
from django.urls import path
from . import views

urlpatterns = [
path('employees/', views.EmployeeList.as_view()),
]

+ 15
- 2
employee/views.py 查看文件

@@ -1,3 +1,16 @@
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.authentication import TokenAuthentication, SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from .models import Employee
from .serializers import EmployeeSerializer


# Create your views here.

class EmployeeList(APIView):
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [IsAuthenticated]

def get(self, request):
employees = Employee.objects.all()
serializer = EmployeeSerializer(employees, many=True)
return Response(serializer.data)

+ 2
- 1
project/admin.py 查看文件

@@ -1,3 +1,4 @@
from django.contrib import admin from django.contrib import admin
from .models import Project


# Register your models here.
admin.site.register([Project])

+ 3
- 1
workx_backend/urls.py 查看文件

@@ -4,6 +4,7 @@ from rest_framework import permissions
from drf_yasg.views import get_schema_view from drf_yasg.views import get_schema_view
from drf_yasg import openapi from drf_yasg import openapi
from client import urls as clientUrls from client import urls as clientUrls
from employee import urls as employeeUrls




schema_view = get_schema_view( schema_view = get_schema_view(
@@ -27,7 +28,8 @@ urlpatterns = [
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), 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('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('api/', include([ path('api/', include([
path('', include(clientUrls))
path('', include(clientUrls)),
path('', include(employeeUrls))
])) ]))
])), ])),
] ]