Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Fixes #18 - create common structure and use it across models
  • Loading branch information
Angeluz-07 committed Mar 12, 2020
commit 4893f2e2cd739969bf88b2ca33a0bff22fb6c7d6
31 changes: 11 additions & 20 deletions time_tracker_api/activities/activities_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_restplus import fields, Resource, Namespace
from time_tracker_api.api import audit_fields

ns = Namespace('activities', description='API for activities')

Expand All @@ -16,31 +17,21 @@
),
})

activity_response = ns.inherit('ActivityResponse', activity, {
activity_response_fields = {
'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',
),
})
)
}
activity_response_fields.update(audit_fields)

activity_response = ns.inherit(
'ActivityResponse',
activity,
activity_response_fields
)


@ns.route('')
Expand Down
24 changes: 22 additions & 2 deletions time_tracker_api/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@

from flask_restplus import Api
from flask_restplus import Api, fields

api = Api(version='1.0.1', title="TimeTracker API",
description="API for the TimeTracker project")

# Common models structure
audit_fields = {
'created_at': fields.Date(
readOnly=True,
title='Created',
description='Date of creation'
),
'tenant_id': fields.String(
readOnly=True,
title='Tenant',
max_length=64,
description='The tenant this belongs to',
),
'created_by': fields.String(
readOnly=True,
title='Creator',
max_length=64,
description='User that created it',
),
}

# APIs
from time_tracker_api.projects import projects_api
api.add_namespace(projects_api.ns)
Expand Down
26 changes: 11 additions & 15 deletions time_tracker_api/projects/projects_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_restplus import Namespace, Resource, abort, inputs, fields
from .projects_model import project_dao
from time_tracker_api.errors import MissingResource
from time_tracker_api.api import audit_fields

ns = Namespace('projects', description='API for projects (clients)')

Expand All @@ -24,26 +25,21 @@
),
})


project_response = ns.inherit('ProjectResponse', project, {
project_response_fields = {
'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'
),
'tenant_id': fields.String(
readOnly=True,
title='Tenant',
max_length=64,
description='The tenant this belongs to',
),
})
)
}
project_response_fields.update(audit_fields)

project_response = ns.inherit(
'ProjectResponse',
project,
project_response_fields
)


@ns.route('')
Expand Down
29 changes: 10 additions & 19 deletions time_tracker_api/technologies/technologies_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_restplus import Namespace, Resource, fields
from time_tracker_api.api import audit_fields

ns = Namespace('technologies', description='API for technologies used')

Expand All @@ -12,31 +13,21 @@
),
})

technology_response = ns.inherit('TechnologyResponse', technology, {
technology_response_fields = {
'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',
),
})
}
technology_response_fields.update(audit_fields)

technology_response = ns.inherit(
'TechnologyResponse',
technology,
technology_response_fields
)


@ns.route('')
Expand Down
29 changes: 10 additions & 19 deletions time_tracker_api/time_entries/time_entry_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask_restplus import fields, Resource, Namespace
from time_tracker_api.api import audit_fields

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

Expand Down Expand Up @@ -38,7 +39,7 @@
),
})

time_entry_response = ns.inherit('TimeEntryResponse', time_entry, {
time_entry_response_fields = {
'id': fields.String(
readOnly=True,
required=True,
Expand All @@ -50,24 +51,14 @@
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',
),
})
}
time_entry_response_fields.update(audit_fields)

time_entry_response = ns.inherit(
'TimeEntryResponse',
time_entry,
time_entry_response_fields,
)


@ns.route('')
Expand Down