|
1 | 1 | from faker import Faker |
2 | 2 | from flask_restplus import fields, Resource, Namespace |
3 | 3 |
|
| 4 | +from time_tracker_api import flask_app |
4 | 5 | from time_tracker_api.api import audit_fields |
| 6 | +from time_tracker_api.activities.activities_model import create_dao |
5 | 7 |
|
6 | 8 | faker = Faker() |
7 | 9 |
|
|
40 | 42 | activity_response_fields |
41 | 43 | ) |
42 | 44 |
|
| 45 | +activity_dao = create_dao(flask_app) |
| 46 | + |
43 | 47 |
|
44 | 48 | @ns.route('') |
45 | 49 | class Activities(Resource): |
46 | 50 | @ns.doc('list_activities') |
47 | 51 | @ns.marshal_list_with(activity, code=200) |
48 | 52 | def get(self): |
49 | | - return [] |
| 53 | + """List all activities""" |
| 54 | + return activity_dao.get_all(), 200 |
50 | 55 |
|
51 | 56 | @ns.doc('create_activity') |
| 57 | + @ns.response(400, 'Bad request') |
52 | 58 | @ns.expect(activity_input) |
53 | 59 | @ns.marshal_with(activity, code=201) |
54 | | - @ns.response(400, 'Invalid format of the attributes of the activity.') |
55 | 60 | def post(self): |
56 | | - return ns.payload, 201 |
| 61 | + """Create an activity""" |
| 62 | + return activity_dao.create(ns.payload), 201 |
57 | 63 |
|
58 | 64 |
|
59 | 65 | @ns.route('/<string:id>') |
60 | 66 | @ns.response(404, 'Activity not found') |
61 | | -@ns.param('id', 'The unique identifier of the activity') |
| 67 | +@ns.param('id', 'The activity identifier') |
62 | 68 | class Activity(Resource): |
63 | 69 | @ns.doc('get_activity') |
64 | | - @ns.marshal_with(activity) |
| 70 | + @ns.marshal_with(activity, code=200) |
65 | 71 | def get(self, id): |
66 | | - return {} |
67 | | - |
68 | | - @ns.doc('delete_activity') |
69 | | - @ns.response(204, 'The activity was deleted successfully (No content is returned)') |
70 | | - def delete(self, id): |
71 | | - return None, 204 |
| 72 | + """Get an activity""" |
| 73 | + return activity_dao.get(id) |
72 | 74 |
|
73 | | - @ns.doc('put_activity') |
74 | | - @ns.response(400, 'Invalid format of the attributes of the activity.') |
| 75 | + @ns.doc('update_activity') |
75 | 76 | @ns.expect(activity_input) |
76 | 77 | @ns.marshal_with(activity) |
77 | 78 | def put(self, id): |
78 | | - return ns.payload |
| 79 | + """Update an activity""" |
| 80 | + return activity_dao.update(id, ns.payload) |
| 81 | + |
| 82 | + @ns.doc('delete_activity') |
| 83 | + @ns.response(204, 'Activity deleted successfully') |
| 84 | + def delete(self, id): |
| 85 | + """Delete an activity""" |
| 86 | + activity_dao.delete(id) |
| 87 | + return None, 204 |
0 commit comments