Skip to content

Commit 3f627ce

Browse files
committed
Apply code review suggestions
1 parent 25255c4 commit 3f627ce

File tree

2 files changed

+118
-52
lines changed

2 files changed

+118
-52
lines changed

time_tracker_api/activities/activities_api.py

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,72 @@
44

55
# Activity Model
66
activity = ns.model('Activity', {
7-
'id': fields.String(readOnly=True, required=True, title='Identifier',
8-
description='The unique id of the activity'),
9-
'name': fields.String(required=True, title='Name', max_length=50,
10-
description='Canonical name of the activity'),
11-
'description': fields.String(title='Description',
12-
description='Comments about the activity'),
13-
'tenant_id': fields.String(required=True, title='Tenant', max_length=64,
14-
description='The tenant this belongs to')
7+
'id': fields.String(
8+
readOnly=True,
9+
required=True,
10+
title='Identifier',
11+
description='The unique id of the activity',
12+
),
13+
'name': fields.String(
14+
required=True,
15+
title='Name',
16+
max_length=50,
17+
description='Canonical name of the activity',
18+
),
19+
'description': fields.String(
20+
title='Description',
21+
description='Comments about the activity',
22+
),
23+
24+
'created_at': fields.Date(
25+
title='Created',
26+
description='Date of creation'
27+
),
28+
'created_by': fields.String(
29+
required=False,
30+
title='Creator',
31+
max_length=64,
32+
description='Id of user who first added this technology',
33+
),
34+
'tenant_id': fields.String(
35+
required=True,
36+
title='Tenant',
37+
max_length=64,
38+
description='The tenant this belongs to',
39+
),
40+
})
41+
42+
activity_response = ns.inherit('ActivityResponse', activity, {
43+
'created_at': fields.Date(
44+
title='Created',
45+
description='Date of creation'
46+
),
47+
'created_by': fields.String(
48+
required=True,
49+
title='Creator',
50+
max_length=64,
51+
description='User that created it',
52+
),
53+
'tenant_id': fields.String(
54+
required=True,
55+
title='Tenant',
56+
max_length=64,
57+
description='The tenant this belongs to',
58+
),
1559
})
1660

1761

18-
@ns.route('/')
62+
@ns.route('')
1963
class Activities(Resource):
2064
@ns.doc('list_activities')
21-
@ns.marshal_list_with(activity, code=200)
65+
@ns.marshal_list_with(activity_response, code=200)
2266
def get(self):
2367
"""List all available activities"""
2468
return []
2569

2670
@ns.doc('create_activity')
2771
@ns.expect(activity)
28-
@ns.marshal_with(activity, code=201)
72+
@ns.marshal_with(activity_response, code=201)
2973
@ns.response(400, 'Invalid format of the attributes of the activity.')
3074
def post(self):
3175
"""Create a single activity"""
@@ -37,7 +81,7 @@ def post(self):
3781
@ns.param('id', 'The unique identifier of the activity')
3882
class Activity(Resource):
3983
@ns.doc('get_activity')
40-
@ns.marshal_with(activity)
84+
@ns.marshal_with(activity_response)
4185
def get(self, id):
4286
"""Retrieve all the data of a single activity"""
4387
return {}
@@ -51,7 +95,7 @@ def delete(self, id):
5195
@ns.doc('put_activity')
5296
@ns.response(400, 'Invalid format of the attributes of the activity.')
5397
@ns.expect(activity)
54-
@ns.marshal_with(activity)
98+
@ns.marshal_with(activity_response)
5599
def put(self, id):
56100
"""Updates an activity"""
57101
return ns.payload

time_tracker_api/time_entries/time_entry_api.py

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,71 @@
44

55
# TimeEntry Model
66
time_entry = ns.model('TimeEntry', {
7-
'id': fields.String(readOnly=True,
8-
required=True,
9-
title='Identifier',
10-
description='The unique id of the time entry'),
11-
'project_id': fields.String(required=True,
12-
title='Project',
13-
max_length=64,
14-
description='The id of the selected project'),
15-
'activity_id': fields.String(required=False,
16-
title='Activity',
17-
max_length=64,
18-
description='The id of the selected activity'),
19-
'technologies': fields.String(required=True,
20-
title='Technologies',
21-
max_length=64,
22-
description='Canonical names of the used technologies during this period'),
23-
'description': fields.String(title='Comments',
24-
description='Comments about the time entry'),
25-
'start_date': fields.DateTime(required=True,
26-
title='Start date',
27-
description='When the user started doing this activity'),
28-
'end_date': fields.DateTime(required=True,
29-
title='End date',
30-
description='When the user ended doing this activity'),
31-
32-
'user_id': fields.String(required=True,
33-
title='Tenant',
34-
max_length=64,
35-
description='The user who created this time entry'),
36-
'tenant_id': fields.String(required=True,
37-
title='Tenant',
38-
max_length=64,
39-
description='The tenant this time entry belongs to'),
7+
'id': fields.String(
8+
readOnly=True,
9+
required=True,
10+
title='Identifier',
11+
description='The unique id of the time entry',
12+
),
13+
'project_id': fields.String(
14+
required=True,
15+
title='Project',
16+
max_length=64,
17+
description='The id of the selected project',
18+
),
19+
'activity_id': fields.String(
20+
required=False,
21+
title='Activity',
22+
max_length=64,
23+
description='The id of the selected activity',
24+
),
25+
'technologies': fields.String(
26+
required=True,
27+
title='Technologies',
28+
max_length=64,
29+
description='Canonical names of the used technologies during this period',
30+
),
31+
'description': fields.String(
32+
title='Comments',
33+
description='Comments about the time entry'
34+
),
35+
'start_date': fields.DateTime(
36+
required=True,
37+
title='Start date',
38+
description='When the user started doing this activity',
39+
),
40+
'end_date': fields.DateTime(
41+
required=True,
42+
title='End date',
43+
description='When the user ended doing this activity',
44+
),
4045
})
4146

4247
time_entry_response = ns.inherit('TimeEntryResponse', time_entry, {
43-
'running': fields.Boolean(title='Is it running?',
44-
description='Whether this time entry is currently running '
45-
'or not'),
48+
'running': fields.Boolean(
49+
title='Is it running?',
50+
description='Whether this time entry is currently running or not'
51+
),
52+
'created_at': fields.Date(
53+
title='Created',
54+
description='Date of creation'
55+
),
56+
'created_by': fields.String(
57+
required=True,
58+
title='Creator',
59+
max_length=64,
60+
description='User that created it',
61+
),
62+
'tenant_id': fields.String(
63+
required=True,
64+
title='Tenant',
65+
max_length=64,
66+
description='The tenant this belongs to',
67+
),
4668
})
4769

4870

49-
@ns.route('/')
71+
@ns.route('')
5072
class TimeEntries(Resource):
5173
@ns.doc('list_time_entries')
5274
@ns.marshal_list_with(time_entry_response, code=200)
@@ -88,7 +110,7 @@ def put(self, id):
88110
return ns.payload
89111

90112

91-
@ns.route('/stop/<string:id>')
113+
@ns.route('<string:id>/stop')
92114
@ns.response(404, 'Running time entry not found')
93115
@ns.param('id', 'The unique identifier of a running time entry')
94116
class StopTimeEntry(Resource):
@@ -99,7 +121,7 @@ def post(self, id):
99121
return None, 204
100122

101123

102-
@ns.route('/continue/<string:id>')
124+
@ns.route('<string:id>/continue')
103125
@ns.response(404, 'Stopped time entry not found')
104126
@ns.param('id', 'The unique identifier of a stopped time entry')
105127
class ContinueTimeEntry(Resource):

0 commit comments

Comments
 (0)