1
- from flask_restplus import Namespace , Resource , abort , inputs
1
+ from flask_restplus import Namespace , Resource , abort , inputs , fields
2
2
from .projects_model import project_dao
3
3
from time_tracker_api .errors import MissingResource
4
4
5
5
ns = Namespace ('projects' , description = 'API for projects (clients)' )
6
6
7
- @ns .route ('/' )
7
+ # Project Model
8
+ project = ns .model ('Project' , {
9
+ 'id' : fields .String (
10
+ readOnly = True ,
11
+ required = True ,
12
+ title = 'Identifier' ,
13
+ description = 'The unique id of the project'
14
+ ),
15
+ 'tenant_id' : fields .String (
16
+ required = True ,
17
+ title = 'Tenant' ,
18
+ max_length = 64 ,
19
+ description = 'The tenant this project belongs to'
20
+ ),
21
+ 'name' : fields .String (
22
+ required = True ,
23
+ title = 'Name' ,
24
+ max_length = 50 ,
25
+ description = 'Name of the project'
26
+ ),
27
+ 'description' : fields .String (
28
+ title = 'Description' ,
29
+ description = 'Description about the project'
30
+ ),
31
+ 'type' : fields .String (
32
+ required = True ,
33
+ title = 'Type' ,
34
+ max_length = 30 ,
35
+ description = 'If it is `Costumer`, `Training` or other type' ,
36
+ ),
37
+ })
38
+
39
+
40
+ @ns .route ('' )
8
41
class Projects (Resource ):
9
42
@ns .doc ('list_projects' )
43
+ @ns .marshal_list_with (project , code = 200 )
10
44
def get (self ):
11
45
"""List all projects"""
12
46
return project_dao .get_all (), 200
13
47
14
48
@ns .doc ('create_project' )
49
+ @ns .expect (project )
50
+ @ns .marshal_with (project , code = 201 )
15
51
def post (self ):
16
52
"""Create a project"""
17
53
return project_dao .create (ns .payload ), 201
18
54
55
+ # TODO : fix, this parser is for a field that is not being used.
19
56
project_update_parser = ns .parser ()
20
57
project_update_parser .add_argument ('active' ,
21
58
type = inputs .boolean ,
@@ -29,24 +66,14 @@ def post(self):
29
66
@ns .param ('uid' , 'The project identifier' )
30
67
class Project (Resource ):
31
68
@ns .doc ('get_project' )
69
+ @ns .marshal_with (project )
32
70
def get (self , uid ):
33
71
"""Retrieve a project"""
34
72
return project_dao .get (uid )
35
73
36
- @ns .doc ('delete_project' )
37
- @ns .response (204 , 'Project deleted' )
38
- def delete (self , uid ):
39
- """Deletes a project"""
40
- project_dao .delete (uid )
41
- return None , 204
42
-
43
- @ns .doc ('put_project' )
44
- def put (self , uid ):
45
- """Create or replace a project"""
46
- return project_dao .update (uid , ns .payload )
47
-
48
74
@ns .doc ('update_project_status' )
49
75
@ns .param ('uid' , 'The project identifier' )
76
+ @ns .expect (project )
50
77
@ns .response (204 , 'State of the project successfully updated' )
51
78
def post (self , uid ):
52
79
"""Updates a project using form data"""
@@ -57,3 +84,18 @@ def post(self, uid):
57
84
abort (code = 400 )
58
85
except MissingResource as e :
59
86
abort (message = str (e ), code = 404 )
87
+
88
+ @ns .doc ('put_project' )
89
+ @ns .expect (project )
90
+ @ns .marshal_with (project )
91
+ def put (self , uid ):
92
+ """Create or replace a project"""
93
+ return project_dao .update (uid , ns .payload )
94
+
95
+ @ns .doc ('delete_project' )
96
+ @ns .response (204 , 'Project deleted successfully' )
97
+ def delete (self , uid ):
98
+ """Deletes a project"""
99
+ project_dao .delete (uid )
100
+ return None , 204
101
+
0 commit comments