Skip to content
Merged
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
Fixes #6 add project_response model
  • Loading branch information
Angeluz-07 committed Mar 11, 2020
commit 3f6bad6c994a62cd3690686330ed528441794dc4
42 changes: 25 additions & 17 deletions time_tracker_api/projects/projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@

# Project Model
project = ns.model('Project', {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique id of the project'
),
'tenant_id': fields.String(
required=True,
title='Tenant',
max_length=64,
description='The tenant this project belongs to'
),
'name': fields.String(
required=True,
title='Name',
Expand All @@ -37,17 +25,38 @@
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would give you the same recommendations as in #12 (review). Add the audit fields (tenant_id, created_at and created_by) and create a project_response to show those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's move id to the response model ;)



project_response = ns.inherit('ProjectResponse', project, {
'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',
),
})


@ns.route('')
class Projects(Resource):
@ns.doc('list_projects')
@ns.marshal_list_with(project, code=200)
@ns.marshal_list_with(project_response, 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, code=201)
@ns.marshal_with(project_response, code=201)
def post(self):
"""Create a project"""
return project_dao.create(ns.payload), 201
Expand All @@ -66,7 +75,7 @@ def post(self):
@ns.param('uid', 'The project identifier')
class Project(Resource):
@ns.doc('get_project')
@ns.marshal_with(project)
@ns.marshal_with(project_response)
def get(self, uid):
"""Retrieve a project"""
return project_dao.get(uid)
Expand All @@ -87,7 +96,7 @@ def post(self, uid):

@ns.doc('put_project')
@ns.expect(project)
@ns.marshal_with(project)
@ns.marshal_with(project_response)
def put(self, uid):
"""Create or replace a project"""
return project_dao.update(uid, ns.payload)
Expand All @@ -98,4 +107,3 @@ def delete(self, uid):
"""Deletes a project"""
project_dao.delete(uid)
return None, 204