Explorar el Código

Added employee API

master
kj1352 hace 3 años
padre
commit
01a563b981
Se han modificado 8 ficheros con 43 adiciones y 12 borrados
  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 Ver fichero

@@ -1,13 +1,13 @@
from rest_framework.response import Response
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 .models import TaxType, Country, State, City, Client
from .serializers import TaxTypeSerializer, CountrySerializer, StateSerializer, CitySerializer, ClientSerializer


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

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


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

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


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

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


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

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


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

def get(self, request):


+ 2
- 1
employee/admin.py Ver fichero

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

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

+ 1
- 1
employee/models.py Ver fichero

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

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

+ 8
- 0
employee/serializers.py Ver fichero

@@ -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 Ver fichero

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

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

+ 15
- 2
employee/views.py Ver fichero

@@ -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 Ver fichero

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

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

+ 3
- 1
workx_backend/urls.py Ver fichero

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


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('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('api/', include([
path('', include(clientUrls))
path('', include(clientUrls)),
path('', include(employeeUrls))
]))
])),
]