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
Next Next commit
Fixes #7 create technology response for server generated fields
  • Loading branch information
Angeluz-07 committed Mar 11, 2020
commit a2a441176d9a6731faf14b8383f533e56440ba45
41 changes: 22 additions & 19 deletions time_tracker_api/technologies/technologies_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,51 @@

# Technology Model
technology = ns.model('Technology', {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique id of the technology'
),
'tenant_id': fields.String(
required=True,
title='Tenant',
max_length=64,
description='The tenant this technology belongs to'
),
'name': fields.String(
required=True,
title='Name',
max_length=50,
description='Name of the technology'
),
})

technology_response = ns.inherit('TechnologyResponse', technology, {
'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(
required=True,
readOnly=True,
title='Creator',
max_length=64,
description='Id of user who first added this technology',
description='User that created it',
),
'tenant_id': fields.String(
readOnly=True,
title='Tenant',
max_length=64,
description='The tenant this belongs to',
),
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 these kinds of fields that are generated after creation, i.e. created_at, created_by, tenant_id, etc., to a model called technology_response, this way you will not require them when the technology is being created but this has to be autogenerated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Those would be those ReadOnly fields

})


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

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

@ns.doc('put_technology')
@ns.expect(technology)
@ns.marshal_with(technology)
@ns.marshal_with(technology_response)
def put(self, uid):
"""Create or replace a technology"""
return ns.payload()
Expand Down