From 3f627ce3b5981f33f5cc566885b59a500316da64 Mon Sep 17 00:00:00 2001 From: EliuX Date: Wed, 11 Mar 2020 09:30:56 -0500 Subject: [PATCH] Apply code review suggestions --- time_tracker_api/activities/activities_api.py | 70 +++++++++--- .../time_entries/time_entry_api.py | 100 +++++++++++------- 2 files changed, 118 insertions(+), 52 deletions(-) diff --git a/time_tracker_api/activities/activities_api.py b/time_tracker_api/activities/activities_api.py index b9578842..71f55c5e 100644 --- a/time_tracker_api/activities/activities_api.py +++ b/time_tracker_api/activities/activities_api.py @@ -4,28 +4,72 @@ # Activity Model activity = ns.model('Activity', { - 'id': fields.String(readOnly=True, required=True, title='Identifier', - description='The unique id of the activity'), - 'name': fields.String(required=True, title='Name', max_length=50, - description='Canonical name of the activity'), - 'description': fields.String(title='Description', - description='Comments about the activity'), - 'tenant_id': fields.String(required=True, title='Tenant', max_length=64, - description='The tenant this belongs to') + 'id': fields.String( + readOnly=True, + required=True, + title='Identifier', + description='The unique id of the activity', + ), + 'name': fields.String( + required=True, + title='Name', + max_length=50, + description='Canonical name of the activity', + ), + 'description': fields.String( + title='Description', + description='Comments about the activity', + ), + + 'created_at': fields.Date( + title='Created', + description='Date of creation' + ), + 'created_by': fields.String( + required=False, + title='Creator', + max_length=64, + description='Id of user who first added this technology', + ), + 'tenant_id': fields.String( + required=True, + title='Tenant', + max_length=64, + description='The tenant this belongs to', + ), +}) + +activity_response = ns.inherit('ActivityResponse', activity, { + 'created_at': fields.Date( + title='Created', + description='Date of creation' + ), + 'created_by': fields.String( + required=True, + title='Creator', + max_length=64, + description='User that created it', + ), + 'tenant_id': fields.String( + required=True, + title='Tenant', + max_length=64, + description='The tenant this belongs to', + ), }) -@ns.route('/') +@ns.route('') class Activities(Resource): @ns.doc('list_activities') - @ns.marshal_list_with(activity, code=200) + @ns.marshal_list_with(activity_response, code=200) def get(self): """List all available activities""" return [] @ns.doc('create_activity') @ns.expect(activity) - @ns.marshal_with(activity, code=201) + @ns.marshal_with(activity_response, code=201) @ns.response(400, 'Invalid format of the attributes of the activity.') def post(self): """Create a single activity""" @@ -37,7 +81,7 @@ def post(self): @ns.param('id', 'The unique identifier of the activity') class Activity(Resource): @ns.doc('get_activity') - @ns.marshal_with(activity) + @ns.marshal_with(activity_response) def get(self, id): """Retrieve all the data of a single activity""" return {} @@ -51,7 +95,7 @@ def delete(self, id): @ns.doc('put_activity') @ns.response(400, 'Invalid format of the attributes of the activity.') @ns.expect(activity) - @ns.marshal_with(activity) + @ns.marshal_with(activity_response) def put(self, id): """Updates an activity""" return ns.payload diff --git a/time_tracker_api/time_entries/time_entry_api.py b/time_tracker_api/time_entries/time_entry_api.py index fe8d3872..94af84b9 100644 --- a/time_tracker_api/time_entries/time_entry_api.py +++ b/time_tracker_api/time_entries/time_entry_api.py @@ -4,49 +4,71 @@ # TimeEntry Model time_entry = ns.model('TimeEntry', { - 'id': fields.String(readOnly=True, - required=True, - title='Identifier', - description='The unique id of the time entry'), - 'project_id': fields.String(required=True, - title='Project', - max_length=64, - description='The id of the selected project'), - 'activity_id': fields.String(required=False, - title='Activity', - max_length=64, - description='The id of the selected activity'), - 'technologies': fields.String(required=True, - title='Technologies', - max_length=64, - description='Canonical names of the used technologies during this period'), - 'description': fields.String(title='Comments', - description='Comments about the time entry'), - 'start_date': fields.DateTime(required=True, - title='Start date', - description='When the user started doing this activity'), - 'end_date': fields.DateTime(required=True, - title='End date', - description='When the user ended doing this activity'), - - 'user_id': fields.String(required=True, - title='Tenant', - max_length=64, - description='The user who created this time entry'), - 'tenant_id': fields.String(required=True, - title='Tenant', - max_length=64, - description='The tenant this time entry belongs to'), + 'id': fields.String( + readOnly=True, + required=True, + title='Identifier', + description='The unique id of the time entry', + ), + 'project_id': fields.String( + required=True, + title='Project', + max_length=64, + description='The id of the selected project', + ), + 'activity_id': fields.String( + required=False, + title='Activity', + max_length=64, + description='The id of the selected activity', + ), + 'technologies': fields.String( + required=True, + title='Technologies', + max_length=64, + description='Canonical names of the used technologies during this period', + ), + 'description': fields.String( + title='Comments', + description='Comments about the time entry' + ), + 'start_date': fields.DateTime( + required=True, + title='Start date', + description='When the user started doing this activity', + ), + 'end_date': fields.DateTime( + required=True, + title='End date', + description='When the user ended doing this activity', + ), }) time_entry_response = ns.inherit('TimeEntryResponse', time_entry, { - 'running': fields.Boolean(title='Is it running?', - description='Whether this time entry is currently running ' - 'or not'), + 'running': fields.Boolean( + title='Is it running?', + description='Whether this time entry is currently running or not' + ), + 'created_at': fields.Date( + title='Created', + description='Date of creation' + ), + 'created_by': fields.String( + required=True, + title='Creator', + max_length=64, + description='User that created it', + ), + 'tenant_id': fields.String( + required=True, + title='Tenant', + max_length=64, + description='The tenant this belongs to', + ), }) -@ns.route('/') +@ns.route('') class TimeEntries(Resource): @ns.doc('list_time_entries') @ns.marshal_list_with(time_entry_response, code=200) @@ -88,7 +110,7 @@ def put(self, id): return ns.payload -@ns.route('/stop/') +@ns.route('/stop') @ns.response(404, 'Running time entry not found') @ns.param('id', 'The unique identifier of a running time entry') class StopTimeEntry(Resource): @@ -99,7 +121,7 @@ def post(self, id): return None, 204 -@ns.route('/continue/') +@ns.route('/continue') @ns.response(404, 'Stopped time entry not found') @ns.param('id', 'The unique identifier of a stopped time entry') class ContinueTimeEntry(Resource):