-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_app.py
90 lines (61 loc) · 1.81 KB
/
sample_app.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
"""A sample FireFrame API."""
from fireframe.core.api import FireFrameAPI
from fireframe.core.views import BaseListAPIView
from fireframe.core.viewsets import crud_viewset
from fireframe.core.models import Model
from fireframe.core.serializers import ModelSerializer
class User(Model):
"""
User model.
Inherits from FireFrame's Model.
"""
class Meta:
collection_name = "users_sample_collection"
name: str
email: str
age: int
class UserSerializer(ModelSerializer):
"""
User serializer.
Inherits from FireFrame's ModelSerializer.
"""
class Meta:
model = User
fields = ["name", "email", "age"]
class Item(Model):
"""
Item model.
Inherits from FireFrame's Model.
"""
class Meta:
collection_name = "items_sample_collection"
name: str
price: float
is_offer: bool
stock: int
class ItemSerializer(ModelSerializer):
"""
Item serializer.
Inherits from FireFrame's ModelSerializer.
"""
class Meta:
model = Item
fields = ["name", "price", "is_offer", "stock"]
class ItemListView(BaseListAPIView):
"""
Item list view.
Inherits from FireFrame's BaseListAPIView.
"""
serializer_class = ItemSerializer
class UserListView(BaseListAPIView):
"""
User list view.
Inherits from FireFrame's BaseListAPIView.
"""
serializer_class = UserSerializer
app = FireFrameAPI(title="Sample FireFrame App", version="0.0.0")
# include routes from viewsets and views
app.include_router(crud_viewset(UserSerializer), tags=["Users"], prefix="/users")
app.include_router(UserListView(), tags=["Users"], prefix="/users")
app.include_router(crud_viewset(ItemSerializer), tags=["Items"], prefix="/items")
app.include_router(ItemListView(), tags=["Items"], prefix="/items")