/
views.py
118 lines (95 loc) · 3.33 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2013 Jack David Baucum
#
# This file is part of Orthosie.
#
# Orthosie is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Orthosie is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Orthosie. If not, see <http://www.gnu.org/licenses/>.
from inventory.models import Item, Vendor
from register.models import Shift, Transaction, LineItem
from rest_framework import generics
from rest_framework.decorators import api_view
from rest_framework.reverse import reverse
from rest_framework.response import Response
from orthosie.serializers import ItemSerializer, VendorSerializer, ShiftSerializer, TransactionSerializer, LineItemSerializer
@api_view(['GET'])
def api_root(request, format=None):
"""
The entry endpoint of our API.
"""
return Response({
'item': reverse('item-list', request=request),
'vendor': reverse('vendor-list', request=request),
'shift': reverse('shift-list', request=request),
'transaction': reverse('transaction-list', request=request),
'lineitem': reverse('lineitem-list', request=request),
})
class ItemList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of items.
"""
model = Item
serializer_class = ItemSerializer
class ItemDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single item.
"""
model = Item
serializer_class = ItemSerializer
class VendorList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of vendors.
"""
model = Vendor
serializer_class = VendorSerializer
class VendorDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single vendor.
"""
model = Vendor
serializer_class = VendorSerializer
class ShiftList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of shift.
"""
model = Shift
serializer_class = ShiftSerializer
class ShiftDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single vendor.
"""
model = Shift
serializer_class = ShiftSerializer
class TransactionList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of transaction.
"""
model = Transaction
serializer_class = TransactionSerializer
class TransactionDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single transaction.
"""
model = Transaction
serializer_class = TransactionSerializer
class LineItemList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of line items.
"""
model = LineItem
serializer_class = LineItemSerializer
class LineItemDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single line items.
"""
model = LineItem
serializer_class = LineItemSerializer