mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
Added OpenAPI decorators for equipment and instances
This commit is contained in:
parent
d6efa30759
commit
a92d698ec9
3 changed files with 1378 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from .models import Equipment, EquipmentInstance
|
from .models import Equipment, EquipmentInstance
|
||||||
|
from drf_spectacular.utils import extend_schema_field
|
||||||
|
from drf_spectacular.types import OpenApiTypes
|
||||||
|
from accounts.models import CustomUser
|
||||||
|
|
||||||
# -- Equipment Serializers
|
# -- Equipment Serializers
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ class EquipmentSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
def get_history_user(self, obj):
|
def get_history_user(self, obj):
|
||||||
return obj.history_user.username if obj.history_user else None
|
return obj.history_user.username if obj.history_user else None
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_last_updated_by(self, obj):
|
def get_last_updated_by(self, obj):
|
||||||
return obj.history.first().history_user if obj.history.first().history_user else None
|
return obj.history.first().history_user if obj.history.first().history_user else None
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@ class EquipmentLogsSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
read_only_fields = ('history_id', 'id', 'name', 'description',
|
read_only_fields = ('history_id', 'id', 'name', 'description',
|
||||||
'history_date', 'history_user')
|
'history_date', 'history_user')
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_history_user(self, obj):
|
def get_history_user(self, obj):
|
||||||
return obj.history_user.username if obj.history_user else None
|
return obj.history_user.username if obj.history_user else None
|
||||||
|
|
||||||
|
@ -68,6 +72,7 @@ class EquipmentLogSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
read_only_fields = ('id', 'last_updated',
|
read_only_fields = ('id', 'last_updated',
|
||||||
'date_added', 'last_updated_by', 'history')
|
'date_added', 'last_updated_by', 'history')
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_last_updated_by(self, obj):
|
def get_last_updated_by(self, obj):
|
||||||
return obj.history.first().history_user if obj.history.first().history_user else None
|
return obj.history.first().history_user if obj.history.first().history_user else None
|
||||||
|
|
||||||
|
@ -106,9 +111,11 @@ class EquipmentInstanceSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
read_only_fields = ('id', 'last_updated',
|
read_only_fields = ('id', 'last_updated',
|
||||||
'last_updated_by', 'date_added')
|
'last_updated_by', 'date_added')
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_history_user(self, obj):
|
def get_history_user(self, obj):
|
||||||
return obj.history_user.username if obj.history_user else None
|
return obj.history_user.username if obj.history_user else None
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_last_updated_by(self, obj):
|
def get_last_updated_by(self, obj):
|
||||||
return obj.history.first().history_user if obj.history.first().history_user else None
|
return obj.history.first().history_user if obj.history.first().history_user else None
|
||||||
|
|
||||||
|
@ -127,6 +134,7 @@ class EquipmentInstanceLogsSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
read_only_fields = ('history_id', 'id', 'equipment', 'status', 'remarks',
|
read_only_fields = ('history_id', 'id', 'equipment', 'status', 'remarks',
|
||||||
'history_date', 'history_user')
|
'history_date', 'history_user')
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_history_user(self, obj):
|
def get_history_user(self, obj):
|
||||||
return obj.history_user.username if obj.history_user else None
|
return obj.history_user.username if obj.history_user else None
|
||||||
|
|
||||||
|
@ -156,5 +164,6 @@ class EquipmentInstanceLogSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
read_only_fields = ('id', 'last_updated',
|
read_only_fields = ('id', 'last_updated',
|
||||||
'date_added', 'last_updated_by', 'history')
|
'date_added', 'last_updated_by', 'history')
|
||||||
|
|
||||||
|
@extend_schema_field(OpenApiTypes.STR)
|
||||||
def get_last_updated_by(self, obj):
|
def get_last_updated_by(self, obj):
|
||||||
return obj.history.first().history_user if obj.history.first().history_user else None
|
return obj.history.first().history_user if obj.history.first().history_user else None
|
||||||
|
|
|
@ -997,7 +997,7 @@ components:
|
||||||
equipment:
|
equipment:
|
||||||
type: integer
|
type: integer
|
||||||
status:
|
status:
|
||||||
type: string
|
$ref: '#/components/schemas/StatusEnum'
|
||||||
remarks:
|
remarks:
|
||||||
type: string
|
type: string
|
||||||
last_updated:
|
last_updated:
|
||||||
|
@ -1062,6 +1062,11 @@ components:
|
||||||
history_id:
|
history_id:
|
||||||
type: integer
|
type: integer
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
readOnly: true
|
||||||
|
equipment:
|
||||||
|
type: integer
|
||||||
status:
|
status:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/StatusEnum'
|
- $ref: '#/components/schemas/StatusEnum'
|
||||||
|
@ -1077,9 +1082,11 @@ components:
|
||||||
type: string
|
type: string
|
||||||
readOnly: true
|
readOnly: true
|
||||||
required:
|
required:
|
||||||
|
- equipment
|
||||||
- history_date
|
- history_date
|
||||||
- history_id
|
- history_id
|
||||||
- history_user
|
- history_user
|
||||||
|
- id
|
||||||
- remarks
|
- remarks
|
||||||
- status
|
- status
|
||||||
EquipmentLog:
|
EquipmentLog:
|
||||||
|
@ -1206,7 +1213,7 @@ components:
|
||||||
equipment:
|
equipment:
|
||||||
type: integer
|
type: integer
|
||||||
status:
|
status:
|
||||||
type: string
|
$ref: '#/components/schemas/StatusEnum'
|
||||||
remarks:
|
remarks:
|
||||||
type: string
|
type: string
|
||||||
last_updated:
|
last_updated:
|
||||||
|
|
1359
equipment_tracker/schema.yml1
Normal file
1359
equipment_tracker/schema.yml1
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue