Browse Source

add model usage example in bottle_api example

Bastien Sevajol 3 years ago
parent
commit
0925c550db
2 changed files with 30 additions and 6 deletions
  1. 9 6
      example/fake_api/bottle_api.py
  2. 21 0
      example/fake_api/model.py

+ 9 - 6
example/fake_api/bottle_api.py View File

@@ -5,6 +5,8 @@ from http import HTTPStatus
5 5
 import bottle
6 6
 import time
7 7
 from datetime import datetime
8
+
9
+from example.fake_api.model import User
8 10
 from hapic import Hapic
9 11
 from example.fake_api.schema import *
10 12
 from hapic.data import HapicData
@@ -31,15 +33,16 @@ class BottleController(object):
31 33
         """
32 34
         Obtain users list.
33 35
         """
36
+        some_user = User(
37
+            id=4,
38
+            username='some_user',
39
+            display_name='Damien Accorsi',
40
+            company='Algoo',
41
+        )
34 42
         return {
35 43
             'item_nb': 1,
36 44
             'items': [
37
-                {
38
-                    'id': 4,
39
-                    'username': 'some_user',
40
-                    'display_name': 'Damien Accorsi',
41
-                    'company': 'Algoo',
42
-                },
45
+                some_user,
43 46
             ],
44 47
             'pagination': {
45 48
                 'first_id': 0,

+ 21 - 0
example/fake_api/model.py View File

@@ -0,0 +1,21 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+
4
+class User(object):
5
+    def __init__(
6
+        self,
7
+        id: int,
8
+        username: str,
9
+        display_name: str,
10
+        company: str,
11
+        email_address: str='',
12
+        first_name: str='',
13
+        last_name: str='',
14
+    ) -> None:
15
+        self.id = id
16
+        self.username = username
17
+        self.email_address = email_address
18
+        self.first_name = first_name
19
+        self.last_name = last_name
20
+        self.display_name = display_name
21
+        self.company = company