|
1 | 1 | from faker import Faker
|
2 | 2 | from flask_restplus import Namespace, Resource, fields
|
| 3 | +from flask_restplus._http import HTTPStatus |
3 | 4 |
|
4 |
| -from time_tracker_api import flask_app |
5 | 5 | from time_tracker_api.api import audit_fields
|
6 | 6 | from time_tracker_api.projects.projects_model import PROJECT_TYPE, create_dao
|
7 | 7 |
|
|
57 | 57 | project_response_fields
|
58 | 58 | )
|
59 | 59 |
|
60 |
| -project_dao = create_dao(flask_app) |
| 60 | +project_dao = create_dao() |
61 | 61 |
|
62 | 62 |
|
63 | 63 | @ns.route('')
|
64 | 64 | class Projects(Resource):
|
65 | 65 | @ns.doc('list_projects')
|
66 |
| - @ns.marshal_list_with(project, code=200) |
| 66 | + @ns.marshal_list_with(project) |
67 | 67 | def get(self):
|
68 | 68 | """List all projects"""
|
69 |
| - return project_dao.get_all(), 200 |
| 69 | + return project_dao.get_all() |
70 | 70 |
|
71 | 71 | @ns.doc('create_project')
|
72 |
| - @ns.response(409, 'This project already exists') |
73 |
| - @ns.response(400, 'Bad request') |
| 72 | + @ns.response(HTTPStatus.CONFLICT, 'This project already exists') |
| 73 | + @ns.response(HTTPStatus.BAD_REQUEST, 'Invalid format or structure ' |
| 74 | + 'of the attributes of the project') |
74 | 75 | @ns.expect(project_input)
|
75 |
| - @ns.marshal_with(project, code=201) |
| 76 | + @ns.marshal_with(project, code=HTTPStatus.CREATED) |
76 | 77 | def post(self):
|
77 | 78 | """Create a project"""
|
78 |
| - return project_dao.create(ns.payload), 201 |
| 79 | + return project_dao.create(ns.payload) |
79 | 80 |
|
80 | 81 |
|
81 | 82 | @ns.route('/<string:id>')
|
82 |
| -@ns.response(404, 'Project not found') |
| 83 | +@ns.response(HTTPStatus.NOT_FOUND, 'This project does not exist') |
| 84 | +@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The data has an invalid format') |
83 | 85 | @ns.param('id', 'The project identifier')
|
84 | 86 | class Project(Resource):
|
85 | 87 | @ns.doc('get_project')
|
86 |
| - @ns.response(422, 'The id has an invalid format') |
| 88 | + @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') |
87 | 89 | @ns.marshal_with(project)
|
88 | 90 | def get(self, id):
|
89 | 91 | """Get a project"""
|
90 | 92 | return project_dao.get(id)
|
91 | 93 |
|
92 | 94 | @ns.doc('update_project')
|
93 |
| - @ns.response(422, 'The data has an invalid format.') |
94 |
| - @ns.response(409, 'This project already exists') |
| 95 | + @ns.response(HTTPStatus.CONFLICT, 'A project already exists with this new data') |
95 | 96 | @ns.expect(project_input)
|
96 | 97 | @ns.marshal_with(project)
|
97 | 98 | def put(self, id):
|
98 | 99 | """Update a project"""
|
99 | 100 | return project_dao.update(id, ns.payload)
|
100 | 101 |
|
101 | 102 | @ns.doc('delete_project')
|
102 |
| - @ns.response(204, 'Project deleted successfully') |
103 |
| - @ns.response(422, 'The id has an invalid format') |
| 103 | + @ns.response(HTTPStatus.NO_CONTENT, 'Project successfully deleted') |
104 | 104 | def delete(self, id):
|
105 | 105 | """Delete a project"""
|
106 | 106 | project_dao.delete(id)
|
107 |
| - return None, 204 |
| 107 | + return None, HTTPStatus.NO_CONTENT |
0 commit comments