Skip to content

Commit 274566e

Browse files
committed
Apply code review suggestions
1 parent 25255c4 commit 274566e

File tree

2 files changed

+102
-53
lines changed

2 files changed

+102
-53
lines changed

time_tracker_api/activities/activities_api.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,55 @@
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+
'name': fields.String(
8+
required=True,
9+
title='Name',
10+
max_length=50,
11+
description='Canonical name of the activity',
12+
),
13+
'description': fields.String(
14+
title='Description',
15+
description='Comments about the activity',
16+
),
17+
})
18+
19+
activity_response = ns.inherit('ActivityResponse', activity, {
20+
'id': fields.String(
21+
readOnly=True,
22+
required=True,
23+
title='Identifier',
24+
description='The unique id of the activity',
25+
),
26+
'created_at': fields.Date(
27+
title='Created',
28+
description='Date of creation'
29+
),
30+
'created_by': fields.String(
31+
required=True,
32+
title='Creator',
33+
max_length=64,
34+
description='User that created it',
35+
),
36+
'tenant_id': fields.String(
37+
required=True,
38+
title='Tenant',
39+
max_length=64,
40+
description='The tenant this belongs to',
41+
),
1542
})
1643

1744

18-
@ns.route('/')
45+
@ns.route('')
1946
class Activities(Resource):
2047
@ns.doc('list_activities')
21-
@ns.marshal_list_with(activity, code=200)
48+
@ns.marshal_list_with(activity_response, code=200)
2249
def get(self):
2350
"""List all available activities"""
2451
return []
2552

2653
@ns.doc('create_activity')
2754
@ns.expect(activity)
28-
@ns.marshal_with(activity, code=201)
55+
@ns.marshal_with(activity_response, code=201)
2956
@ns.response(400, 'Invalid format of the attributes of the activity.')
3057
def post(self):
3158
"""Create a single activity"""
@@ -37,7 +64,7 @@ def post(self):
3764
@ns.param('id', 'The unique identifier of the activity')
3865
class Activity(Resource):
3966
@ns.doc('get_activity')
40-
@ns.marshal_with(activity)
67+
@ns.marshal_with(activity_response)
4168
def get(self, id):
4269
"""Retrieve all the data of a single activity"""
4370
return {}
@@ -51,7 +78,7 @@ def delete(self, id):
5178
@ns.doc('put_activity')
5279
@ns.response(400, 'Invalid format of the attributes of the activity.')
5380
@ns.expect(activity)
54-
@ns.marshal_with(activity)
81+
@ns.marshal_with(activity_response)
5582
def put(self, id):
5683
"""Updates an activity"""
5784
return ns.payload

time_tracker_api/time_entries/time_entry_api.py

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,74 @@
11
from flask_restplus import fields, Resource, Namespace
22

3-
ns = Namespace('time_entries', description='API for time entries')
3+
ns = Namespace('time-entries', description='API for time entries')
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+
'project_id': fields.String(
8+
required=True,
9+
title='Project',
10+
max_length=64,
11+
description='The id of the selected project',
12+
),
13+
'activity_id': fields.String(
14+
required=False,
15+
title='Activity',
16+
max_length=64,
17+
description='The id of the selected activity',
18+
),
19+
'technologies': fields.String(
20+
required=True,
21+
title='Technologies',
22+
max_length=64,
23+
description='Canonical names of the used technologies during this period',
24+
),
25+
'description': fields.String(
26+
title='Comments',
27+
description='Comments about the time entry'
28+
),
29+
'start_date': fields.DateTime(
30+
required=True,
31+
title='Start date',
32+
description='When the user started doing this activity',
33+
),
34+
'end_date': fields.DateTime(
35+
required=True,
36+
title='End date',
37+
description='When the user ended doing this activity',
38+
),
4039
})
4140

4241
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'),
42+
'id': fields.String(
43+
readOnly=True,
44+
required=True,
45+
title='Identifier',
46+
description='The unique id of the time entry',
47+
),
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)