Skip to content

Commit 3f6bad6

Browse files
committed
Fixes #6 add project_response model
1 parent fccc069 commit 3f6bad6

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

time_tracker_api/projects/projects_api.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66

77
# Project Model
88
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-
),
219
'name': fields.String(
2210
required=True,
2311
title='Name',
@@ -37,17 +25,38 @@
3725
})
3826

3927

28+
project_response = ns.inherit('ProjectResponse', project, {
29+
'id': fields.String(
30+
readOnly=True,
31+
required=True,
32+
title='Identifier',
33+
description='The unique identifier',
34+
),
35+
'created_at': fields.Date(
36+
readOnly=True,
37+
title='Created',
38+
description='Date of creation'
39+
),
40+
'tenant_id': fields.String(
41+
readOnly=True,
42+
title='Tenant',
43+
max_length=64,
44+
description='The tenant this belongs to',
45+
),
46+
})
47+
48+
4049
@ns.route('')
4150
class Projects(Resource):
4251
@ns.doc('list_projects')
43-
@ns.marshal_list_with(project, code=200)
52+
@ns.marshal_list_with(project_response, code=200)
4453
def get(self):
4554
"""List all projects"""
4655
return project_dao.get_all(), 200
4756

4857
@ns.doc('create_project')
4958
@ns.expect(project)
50-
@ns.marshal_with(project, code=201)
59+
@ns.marshal_with(project_response, code=201)
5160
def post(self):
5261
"""Create a project"""
5362
return project_dao.create(ns.payload), 201
@@ -66,7 +75,7 @@ def post(self):
6675
@ns.param('uid', 'The project identifier')
6776
class Project(Resource):
6877
@ns.doc('get_project')
69-
@ns.marshal_with(project)
78+
@ns.marshal_with(project_response)
7079
def get(self, uid):
7180
"""Retrieve a project"""
7281
return project_dao.get(uid)
@@ -87,7 +96,7 @@ def post(self, uid):
8796

8897
@ns.doc('put_project')
8998
@ns.expect(project)
90-
@ns.marshal_with(project)
99+
@ns.marshal_with(project_response)
91100
def put(self, uid):
92101
"""Create or replace a project"""
93102
return project_dao.update(uid, ns.payload)
@@ -98,4 +107,3 @@ def delete(self, uid):
98107
"""Deletes a project"""
99108
project_dao.delete(uid)
100109
return None, 204
101-

0 commit comments

Comments
 (0)