|
1 | 1 | from faker import Faker
|
2 | 2 | from flask_restplus import fields, Resource, Namespace
|
| 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.activities.activities_model import create_dao
|
7 | 7 |
|
|
42 | 42 | activity_response_fields
|
43 | 43 | )
|
44 | 44 |
|
45 |
| -activity_dao = create_dao(flask_app) |
| 45 | +activity_dao = create_dao() |
46 | 46 |
|
47 | 47 |
|
48 | 48 | @ns.route('')
|
49 | 49 | class Activities(Resource):
|
50 | 50 | @ns.doc('list_activities')
|
51 |
| - @ns.marshal_list_with(activity, code=200) |
| 51 | + @ns.marshal_list_with(activity, code=HTTPStatus.OK) |
52 | 52 | def get(self):
|
53 | 53 | """List all activities"""
|
54 |
| - return activity_dao.get_all(), 200 |
| 54 | + return activity_dao.get_all(), HTTPStatus.OK |
55 | 55 |
|
56 | 56 | @ns.doc('create_activity')
|
57 |
| - @ns.response(400, 'Bad request') |
| 57 | + @ns.response(HTTPStatus.BAD_REQUEST, 'Bad request') |
58 | 58 | @ns.expect(activity_input)
|
59 |
| - @ns.marshal_with(activity, code=201) |
| 59 | + @ns.marshal_with(activity, code=HTTPStatus.CREATED) |
60 | 60 | def post(self):
|
61 | 61 | """Create an activity"""
|
62 |
| - return activity_dao.create(ns.payload), 201 |
| 62 | + return activity_dao.create(ns.payload), HTTPStatus.CREATED |
63 | 63 |
|
64 | 64 |
|
65 | 65 | @ns.route('/<string:id>')
|
66 |
| -@ns.response(404, 'Activity not found') |
| 66 | +@ns.response(HTTPStatus.NOT_FOUND, 'Activity not found') |
67 | 67 | @ns.param('id', 'The activity identifier')
|
68 | 68 | class Activity(Resource):
|
69 | 69 | @ns.doc('get_activity')
|
70 |
| - @ns.response(422, 'The id has an invalid format') |
71 |
| - @ns.marshal_with(activity, code=200) |
| 70 | + @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') |
| 71 | + @ns.marshal_with(activity, code=HTTPStatus.OK) |
72 | 72 | def get(self, id):
|
73 | 73 | """Get an activity"""
|
74 |
| - return activity_dao.get(id) |
| 74 | + return activity_dao.get(id), HTTPStatus.OK |
75 | 75 |
|
76 | 76 | @ns.doc('update_activity')
|
77 |
| - @ns.response(422, 'The data has an invalid format.') |
| 77 | + @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The data has an invalid format.') |
78 | 78 | @ns.expect(activity_input)
|
79 | 79 | @ns.marshal_with(activity)
|
80 | 80 | def put(self, id):
|
81 | 81 | """Update an activity"""
|
82 | 82 | return activity_dao.update(id, ns.payload)
|
83 | 83 |
|
84 | 84 | @ns.doc('delete_activity')
|
85 |
| - @ns.response(422, 'The id has an invalid format') |
86 |
| - @ns.response(204, 'Activity deleted successfully') |
| 85 | + @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') |
| 86 | + @ns.response(HTTPStatus.NO_CONTENT, 'Activity deleted successfully') |
87 | 87 | def delete(self, id):
|
88 | 88 | """Delete an activity"""
|
89 | 89 | activity_dao.delete(id)
|
90 |
| - return None, 204 |
| 90 | + return None, HTTPStatus.NO_CONTENT |
0 commit comments