Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions time_tracker_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
from time_tracker_api.activities import activities_api
api.add_namespace(activities_api.ns)

from time_tracker_api.technologies import technologies_api
api.add_namespace(technologies_api.ns)

from time_tracker_api.time_entries import time_entry_api
api.add_namespace(time_entry_api.ns)
87 changes: 87 additions & 0 deletions time_tracker_api/technologies/technologies_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from flask_restplus import Namespace, Resource, fields

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

# Technology Model
technology = ns.model('Technology', {
'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(
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',
),
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_response, code=200)
def get(self):
"""List all technologies"""
return [], 200

@ns.doc('create_technology')
@ns.expect(technology)
@ns.marshal_with(technology_response, code=201)
def post(self):
"""Create a technology"""
return ns.payload, 201


@ns.route('/<string:uid>')
@ns.response(404, 'Technology not found')
@ns.param('uid', 'The technology identifier')
class Technology(Resource):
@ns.doc('get_technology')
@ns.marshal_with(technology_response)
def get(self, uid):
"""Retrieve a technology"""
return {}

@ns.doc('update_technology_status')
@ns.param('uid', 'The technology identifier')
@ns.expect(technology)
@ns.response(204, 'State of the technology successfully updated')
def post(self, uid):
"""Updates a technology using form data"""
return ns.payload()

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

@ns.doc('delete_technology')
@ns.response(204, 'Technology deleted successfully')
def delete(self, uid):
"""Deletes a technology"""
return None, 204