Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Apply code review suggestions
  • Loading branch information
EliuX committed Mar 11, 2020
commit 2923b9c7c0ba455509e7ca234303b758f866d5ed
54 changes: 41 additions & 13 deletions time_tracker_api/activities/activities_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,56 @@

# 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')
'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',
),
})

activity_response = ns.inherit('ActivityResponse', activity, {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
),
'created_at': fields.Date(
readOnly=True,
title='Created',
description='Date of creation'
),
'created_by': fields.String(
readOnly=True,
title='Creator',
max_length=64,
description='User that created it',
),
'tenant_id': fields.String(
readOnly=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"""
Expand All @@ -37,7 +65,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 {}
Expand All @@ -51,7 +79,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
104 changes: 64 additions & 40 deletions time_tracker_api/time_entries/time_entry_api.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,76 @@
from flask_restplus import fields, Resource, Namespace

ns = Namespace('time_entries', description='API for time entries')
ns = Namespace('time-entries', description='API for time entries')

# 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'),
'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'),
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
),
'running': fields.Boolean(
readOnly=True,
title='Is it running?',
description='Whether this time entry is currently running or not'
),
'created_at': fields.Date(
readOnly=True,
title='Created',
description='Date of creation'
),
'created_by': fields.String(
readOnly=True,
title='Creator',
max_length=64,
description='User that created it',
),
'tenant_id': fields.String(
readOnly=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)
Expand Down Expand Up @@ -88,7 +112,7 @@ def put(self, id):
return ns.payload


@ns.route('/stop/<string:id>')
@ns.route('<string:id>/stop')
@ns.response(404, 'Running time entry not found')
@ns.param('id', 'The unique identifier of a running time entry')
class StopTimeEntry(Resource):
Expand All @@ -99,7 +123,7 @@ def post(self, id):
return None, 204


@ns.route('/continue/<string:id>')
@ns.route('<string:id>/continue')
@ns.response(404, 'Stopped time entry not found')
@ns.param('id', 'The unique identifier of a stopped time entry')
class ContinueTimeEntry(Resource):
Expand Down