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
Next Next commit
Fixes #6 add project model
  • Loading branch information
Angeluz-07 committed Mar 11, 2020
commit fccc06910c40d79dc81394a7738c4fcad9a063f1
70 changes: 56 additions & 14 deletions time_tracker_api/projects/projects_api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
from flask_restplus import Namespace, Resource, abort, inputs
from flask_restplus import Namespace, Resource, abort, inputs, fields
from .projects_model import project_dao
from time_tracker_api.errors import MissingResource

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

@ns.route('/')
# 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',
max_length=50,
description='Name of the project'
),
'description': fields.String(
title='Description',
description='Description about the project'
),
'type': fields.String(
required=True,
title='Type',
max_length=30,
description='If it is `Costumer`, `Training` or other type',
),
})
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 ;)



@ns.route('')
class Projects(Resource):
@ns.doc('list_projects')
@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, code=201)
def post(self):
"""Create a project"""
return project_dao.create(ns.payload), 201

# TODO : fix, this parser is for a field that is not being used.
project_update_parser = ns.parser()
project_update_parser.add_argument('active',
type=inputs.boolean,
Expand All @@ -29,24 +66,14 @@ def post(self):
@ns.param('uid', 'The project identifier')
class Project(Resource):
@ns.doc('get_project')
@ns.marshal_with(project)
def get(self, uid):
"""Retrieve a project"""
return project_dao.get(uid)

@ns.doc('delete_project')
@ns.response(204, 'Project deleted')
def delete(self, uid):
"""Deletes a project"""
project_dao.delete(uid)
return None, 204

@ns.doc('put_project')
def put(self, uid):
"""Create or replace a project"""
return project_dao.update(uid, ns.payload)

@ns.doc('update_project_status')
@ns.param('uid', 'The project identifier')
@ns.expect(project)
@ns.response(204, 'State of the project successfully updated')
def post(self, uid):
"""Updates a project using form data"""
Expand All @@ -57,3 +84,18 @@ def post(self, uid):
abort(code=400)
except MissingResource as e:
abort(message=str(e), code=404)

@ns.doc('put_project')
@ns.expect(project)
@ns.marshal_with(project)
def put(self, uid):
"""Create or replace a project"""
return project_dao.update(uid, ns.payload)

@ns.doc('delete_project')
@ns.response(204, 'Project deleted successfully')
def delete(self, uid):
"""Deletes a project"""
project_dao.delete(uid)
return None, 204