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
Rename API models
  • Loading branch information
EliuX committed Mar 16, 2020
commit ad773897c0f1545b1990f060b63356fa8bcf6be8
20 changes: 10 additions & 10 deletions time_tracker_api/activities/activities_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ns = Namespace('activities', description='API for activities')

# Activity Model
activity = ns.model('Activity', {
activity_input = ns.model('ActivityInput', {
'name': fields.String(
required=True,
title='Name',
Expand All @@ -27,24 +27,24 @@
}
activity_response_fields.update(audit_fields)

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


@ns.route('')
class Activities(Resource):
@ns.doc('list_activities')
@ns.marshal_list_with(activity_response, code=200)
@ns.marshal_list_with(activity, code=200)
def get(self):
"""List all available activities"""
return []

@ns.doc('create_activity')
@ns.expect(activity)
@ns.marshal_with(activity_response, code=201)
@ns.expect(activity_input)
@ns.marshal_with(activity, code=201)
@ns.response(400, 'Invalid format of the attributes of the activity.')
def post(self):
"""Create a single activity"""
Expand All @@ -56,7 +56,7 @@ def post(self):
@ns.param('id', 'The unique identifier of the activity')
class Activity(Resource):
@ns.doc('get_activity')
@ns.marshal_with(activity_response)
@ns.marshal_with(activity)
def get(self, id):
"""Retrieve all the data of a single activity"""
return {}
Expand All @@ -69,8 +69,8 @@ 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_response)
@ns.expect(activity_input)
@ns.marshal_with(activity)
def put(self, id):
"""Updates an activity"""
return ns.payload
20 changes: 10 additions & 10 deletions time_tracker_api/projects/projects_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ns = Namespace('projects', description='API for projects (clients)')

# Project Model
project = ns.model('Project', {
project_input = ns.model('ProjectInput', {
'name': fields.String(
required=True,
title='Name',
Expand Down Expand Up @@ -35,24 +35,24 @@
}
project_response_fields.update(audit_fields)

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


@ns.route('')
class Projects(Resource):
@ns.doc('list_projects')
@ns.marshal_list_with(project_response, code=200)
@ns.marshal_list_with(project, code=200)
def get(self):
"""List all projects"""
return project_dao.get_all(), 200

@ns.doc('create_project')
@ns.expect(project)
@ns.marshal_with(project_response, code=201)
@ns.expect(project_input)
@ns.marshal_with(project, code=201)
def post(self):
"""Create a project"""
return project_dao.create(ns.payload), 201
Expand All @@ -71,7 +71,7 @@ def post(self):
@ns.param('uid', 'The project identifier')
class Project(Resource):
@ns.doc('get_project')
@ns.marshal_with(project_response)
@ns.marshal_with(project)
def get(self, uid):
"""Retrieve a project"""
return project_dao.get(uid)
Expand All @@ -90,8 +90,8 @@ def post(self, uid):
abort(message=str(e), code=404)

@ns.doc('put_project')
@ns.expect(project)
@ns.marshal_with(project_response)
@ns.expect(project_input)
@ns.marshal_with(project)
def put(self, uid):
"""Create or replace a project"""
return project_dao.update(uid, ns.payload)
Expand Down
20 changes: 10 additions & 10 deletions time_tracker_api/technologies/technologies_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ns = Namespace('technologies', description='API for technologies used')

# Technology Model
technology = ns.model('Technology', {
technology_input = ns.model('TechnologyInput', {
'name': fields.String(
required=True,
title='Name',
Expand All @@ -23,24 +23,24 @@
}
technology_response_fields.update(audit_fields)

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


@ns.route('')
class Technologies(Resource):
@ns.doc('list_technologies')
@ns.marshal_list_with(technology_response, code=200)
@ns.marshal_list_with(technology, code=200)
def get(self):
"""List all technologies"""
return [], 200

@ns.doc('create_technology')
@ns.expect(technology)
@ns.marshal_with(technology_response, code=201)
@ns.expect(technology_input)
@ns.marshal_with(technology, code=201)
def post(self):
"""Create a technology"""
return ns.payload, 201
Expand All @@ -51,14 +51,14 @@ def post(self):
@ns.param('uid', 'The technology identifier')
class Technology(Resource):
@ns.doc('get_technology')
@ns.marshal_with(technology_response)
@ns.marshal_with(technology)
def get(self, uid):
"""Retrieve a technology"""
return {}

@ns.doc('put_technology')
@ns.expect(technology)
@ns.marshal_with(technology_response)
@ns.expect(technology_input)
@ns.marshal_with(technology)
def put(self, uid):
"""Updates a technology"""
return ns.payload()
Expand Down
20 changes: 10 additions & 10 deletions time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ns = Namespace('time-entries', description='API for time entries')

# TimeEntry Model
time_entry = ns.model('TimeEntry', {
time_entry_input = ns.model('TimeEntryInput', {
'project_id': fields.String(
required=True,
title='Project',
Expand Down Expand Up @@ -55,9 +55,9 @@
}
time_entry_response_fields.update(audit_fields)

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

Expand All @@ -67,14 +67,14 @@
@ns.route('')
class TimeEntries(Resource):
@ns.doc('list_time_entries')
@ns.marshal_list_with(time_entry_response, code=200)
@ns.marshal_list_with(time_entry, code=200)
def get(self):
"""List all available time entries"""
return model.find_all()

@ns.doc('create_time_entry')
@ns.expect(time_entry)
@ns.marshal_with(time_entry_response, code=201)
@ns.expect(time_entry_input)
@ns.marshal_with(time_entry, code=201)
@ns.response(400, 'Invalid format of the attributes of the time entry')
def post(self):
"""Starts a time entry by creating it"""
Expand All @@ -86,7 +86,7 @@ def post(self):
@ns.param('id', 'The unique identifier of the time entry')
class TimeEntry(Resource):
@ns.doc('get_time_entry')
@ns.marshal_with(time_entry_response)
@ns.marshal_with(time_entry)
def get(self, id):
"""Retrieve all the data of a single time entry"""
return {}
Expand All @@ -99,8 +99,8 @@ def delete(self, id):

@ns.doc('put_time_entry')
@ns.response(400, 'Invalid format of the attributes of the time entry.')
@ns.expect(time_entry)
@ns.marshal_with(time_entry_response)
@ns.expect(time_entry_input)
@ns.marshal_with(time_entry)
def put(self, id):
"""Updates a time entry"""
return ns.payload
Expand Down