Skip to content

Commit f5bbf77

Browse files
committed
Merge branch 'feature/create-technologies-spec#7' of https://github.com/ioet/time-tracker-api into feature/create-technologies-spec#7
2 parents 4dbe6fb + 0f72441 commit f5bbf77

File tree

3 files changed

+178
-13
lines changed

3 files changed

+178
-13
lines changed

time_tracker_api/activities/activities_api.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,56 @@
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 identifier',
25+
),
26+
'created_at': fields.Date(
27+
readOnly=True,
28+
title='Created',
29+
description='Date of creation'
30+
),
31+
'created_by': fields.String(
32+
readOnly=True,
33+
title='Creator',
34+
max_length=64,
35+
description='User that created it',
36+
),
37+
'tenant_id': fields.String(
38+
readOnly=True,
39+
title='Tenant',
40+
max_length=64,
41+
description='The tenant this belongs to',
42+
),
1543
})
1644

1745

18-
@ns.route('/')
46+
@ns.route('')
1947
class Activities(Resource):
2048
@ns.doc('list_activities')
21-
@ns.marshal_list_with(activity, code=200)
49+
@ns.marshal_list_with(activity_response, code=200)
2250
def get(self):
2351
"""List all available activities"""
2452
return []
2553

2654
@ns.doc('create_activity')
2755
@ns.expect(activity)
28-
@ns.marshal_with(activity, code=201)
56+
@ns.marshal_with(activity_response, code=201)
2957
@ns.response(400, 'Invalid format of the attributes of the activity.')
3058
def post(self):
3159
"""Create a single activity"""
@@ -37,7 +65,7 @@ def post(self):
3765
@ns.param('id', 'The unique identifier of the activity')
3866
class Activity(Resource):
3967
@ns.doc('get_activity')
40-
@ns.marshal_with(activity)
68+
@ns.marshal_with(activity_response)
4169
def get(self, id):
4270
"""Retrieve all the data of a single activity"""
4371
return {}
@@ -51,7 +79,7 @@ def delete(self, id):
5179
@ns.doc('put_activity')
5280
@ns.response(400, 'Invalid format of the attributes of the activity.')
5381
@ns.expect(activity)
54-
@ns.marshal_with(activity)
82+
@ns.marshal_with(activity_response)
5583
def put(self, id):
5684
"""Updates an activity"""
5785
return ns.payload

time_tracker_api/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313

1414
from time_tracker_api.technologies import technologies_api
1515
api.add_namespace(technologies_api.ns)
16+
17+
from time_tracker_api.time_entries import time_entry_api
18+
api.add_namespace(time_entry_api.ns)
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from flask_restplus import fields, Resource, Namespace
2+
3+
ns = Namespace('time-entries', description='API for time entries')
4+
5+
# TimeEntry Model
6+
time_entry = ns.model('TimeEntry', {
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+
),
39+
})
40+
41+
time_entry_response = ns.inherit('TimeEntryResponse', time_entry, {
42+
'id': fields.String(
43+
readOnly=True,
44+
required=True,
45+
title='Identifier',
46+
description='The unique identifier',
47+
),
48+
'running': fields.Boolean(
49+
readOnly=True,
50+
title='Is it running?',
51+
description='Whether this time entry is currently running or not'
52+
),
53+
'created_at': fields.Date(
54+
readOnly=True,
55+
title='Created',
56+
description='Date of creation'
57+
),
58+
'created_by': fields.String(
59+
readOnly=True,
60+
title='Creator',
61+
max_length=64,
62+
description='User that created it',
63+
),
64+
'tenant_id': fields.String(
65+
readOnly=True,
66+
title='Tenant',
67+
max_length=64,
68+
description='The tenant this belongs to',
69+
),
70+
})
71+
72+
73+
@ns.route('')
74+
class TimeEntries(Resource):
75+
@ns.doc('list_time_entries')
76+
@ns.marshal_list_with(time_entry_response, code=200)
77+
def get(self):
78+
"""List all available time entries"""
79+
return []
80+
81+
@ns.doc('create_time_entry')
82+
@ns.expect(time_entry)
83+
@ns.marshal_with(time_entry_response, code=201)
84+
@ns.response(400, 'Invalid format of the attributes of the time entry')
85+
def post(self):
86+
"""Starts a time entry by creating it"""
87+
return ns.payload, 201
88+
89+
90+
@ns.route('/<string:id>')
91+
@ns.response(404, 'Time entry not found')
92+
@ns.param('id', 'The unique identifier of the time entry')
93+
class TimeEntry(Resource):
94+
@ns.doc('get_time_entry')
95+
@ns.marshal_with(time_entry_response)
96+
def get(self, id):
97+
"""Retrieve all the data of a single time entry"""
98+
return {}
99+
100+
@ns.doc('delete_time_entry')
101+
@ns.response(204, 'The time entry was deleted successfully (No content is returned)')
102+
def delete(self, id):
103+
"""Deletes a time entry"""
104+
return None, 204
105+
106+
@ns.doc('put_time_entry')
107+
@ns.response(400, 'Invalid format of the attributes of the time entry.')
108+
@ns.expect(time_entry)
109+
@ns.marshal_with(time_entry_response)
110+
def put(self, id):
111+
"""Updates a time entry"""
112+
return ns.payload
113+
114+
115+
@ns.route('<string:id>/stop')
116+
@ns.response(404, 'Running time entry not found')
117+
@ns.param('id', 'The unique identifier of a running time entry')
118+
class StopTimeEntry(Resource):
119+
@ns.doc('stop_time_entry')
120+
@ns.response(204, 'The time entry was stopped successfully (No content is returned)')
121+
def post(self, id):
122+
"""Stops a running time entry"""
123+
return None, 204
124+
125+
126+
@ns.route('<string:id>/continue')
127+
@ns.response(404, 'Stopped time entry not found')
128+
@ns.param('id', 'The unique identifier of a stopped time entry')
129+
class ContinueTimeEntry(Resource):
130+
@ns.doc('continue_time_entry')
131+
@ns.response(204, 'The time entry was continued successfully (No content is returned)')
132+
def post(self, id):
133+
"""Restart an stopped time entry"""
134+
return None, 204

0 commit comments

Comments
 (0)