Skip to content

Commit 25255c4

Browse files
author
EliuX
committed
Fixes #5 Create API definition for time entries
1 parent e1224d2 commit 25255c4

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

time_tracker_api/api.py

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

1111
from time_tracker_api.activities import activities_api
1212
api.add_namespace(activities_api.ns)
13+
14+
from time_tracker_api.time_entries import time_entry_api
15+
api.add_namespace(time_entry_api.ns)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
'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'),
40+
})
41+
42+
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'),
46+
})
47+
48+
49+
@ns.route('/')
50+
class TimeEntries(Resource):
51+
@ns.doc('list_time_entries')
52+
@ns.marshal_list_with(time_entry_response, code=200)
53+
def get(self):
54+
"""List all available time entries"""
55+
return []
56+
57+
@ns.doc('create_time_entry')
58+
@ns.expect(time_entry)
59+
@ns.marshal_with(time_entry_response, code=201)
60+
@ns.response(400, 'Invalid format of the attributes of the time entry')
61+
def post(self):
62+
"""Starts a time entry by creating it"""
63+
return ns.payload, 201
64+
65+
66+
@ns.route('/<string:id>')
67+
@ns.response(404, 'Time entry not found')
68+
@ns.param('id', 'The unique identifier of the time entry')
69+
class TimeEntry(Resource):
70+
@ns.doc('get_time_entry')
71+
@ns.marshal_with(time_entry_response)
72+
def get(self, id):
73+
"""Retrieve all the data of a single time entry"""
74+
return {}
75+
76+
@ns.doc('delete_time_entry')
77+
@ns.response(204, 'The time entry was deleted successfully (No content is returned)')
78+
def delete(self, id):
79+
"""Deletes a time entry"""
80+
return None, 204
81+
82+
@ns.doc('put_time_entry')
83+
@ns.response(400, 'Invalid format of the attributes of the time entry.')
84+
@ns.expect(time_entry)
85+
@ns.marshal_with(time_entry_response)
86+
def put(self, id):
87+
"""Updates a time entry"""
88+
return ns.payload
89+
90+
91+
@ns.route('/stop/<string:id>')
92+
@ns.response(404, 'Running time entry not found')
93+
@ns.param('id', 'The unique identifier of a running time entry')
94+
class StopTimeEntry(Resource):
95+
@ns.doc('stop_time_entry')
96+
@ns.response(204, 'The time entry was stopped successfully (No content is returned)')
97+
def post(self, id):
98+
"""Stops a running time entry"""
99+
return None, 204
100+
101+
102+
@ns.route('/continue/<string:id>')
103+
@ns.response(404, 'Stopped time entry not found')
104+
@ns.param('id', 'The unique identifier of a stopped time entry')
105+
class ContinueTimeEntry(Resource):
106+
@ns.doc('continue_time_entry')
107+
@ns.response(204, 'The time entry was continued successfully (No content is returned)')
108+
def post(self, id):
109+
"""Restart an stopped time entry"""
110+
return None, 204

0 commit comments

Comments
 (0)