-
Notifications
You must be signed in to change notification settings - Fork 0
Implement activities model #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
804120c
d5c11c5
587855b
63bcdd4
b683c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| from faker import Faker | ||
| from flask_restplus import fields, Resource, Namespace | ||
| from flask_restplus._http import HTTPStatus | ||
|
|
||
| from time_tracker_api import flask_app | ||
| from time_tracker_api.api import audit_fields | ||
| from time_tracker_api.activities.activities_model import create_dao | ||
|
|
||
|
|
@@ -42,49 +42,49 @@ | |
| activity_response_fields | ||
| ) | ||
|
|
||
| activity_dao = create_dao(flask_app) | ||
| activity_dao = create_dao() | ||
|
|
||
|
|
||
| @ns.route('') | ||
| class Activities(Resource): | ||
| @ns.doc('list_activities') | ||
| @ns.marshal_list_with(activity, code=200) | ||
| @ns.marshal_list_with(activity, code=HTTPStatus.OK) | ||
| def get(self): | ||
| """List all activities""" | ||
| return activity_dao.get_all(), 200 | ||
| return activity_dao.get_all(), HTTPStatus.OK | ||
|
|
||
| @ns.doc('create_activity') | ||
| @ns.response(400, 'Bad request') | ||
| @ns.response(HTTPStatus.BAD_REQUEST, 'Bad request') | ||
|
||
| @ns.expect(activity_input) | ||
| @ns.marshal_with(activity, code=201) | ||
| @ns.marshal_with(activity, code=HTTPStatus.CREATED) | ||
| def post(self): | ||
| """Create an activity""" | ||
| return activity_dao.create(ns.payload), 201 | ||
| return activity_dao.create(ns.payload), HTTPStatus.CREATED | ||
|
|
||
|
|
||
| @ns.route('/<string:id>') | ||
| @ns.response(404, 'Activity not found') | ||
| @ns.response(HTTPStatus.NOT_FOUND, 'Activity not found') | ||
| @ns.param('id', 'The activity identifier') | ||
| class Activity(Resource): | ||
EliuX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @ns.doc('get_activity') | ||
| @ns.response(422, 'The id has an invalid format') | ||
| @ns.marshal_with(activity, code=200) | ||
| @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') | ||
|
||
| @ns.marshal_with(activity, code=HTTPStatus.OK) | ||
| def get(self, id): | ||
| """Get an activity""" | ||
| return activity_dao.get(id) | ||
| return activity_dao.get(id), HTTPStatus.OK | ||
|
||
|
|
||
| @ns.doc('update_activity') | ||
| @ns.response(422, 'The data has an invalid format.') | ||
| @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The data has an invalid format.') | ||
|
||
| @ns.expect(activity_input) | ||
| @ns.marshal_with(activity) | ||
| def put(self, id): | ||
| """Update an activity""" | ||
| return activity_dao.update(id, ns.payload) | ||
|
|
||
| @ns.doc('delete_activity') | ||
| @ns.response(422, 'The id has an invalid format') | ||
| @ns.response(204, 'Activity deleted successfully') | ||
| @ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format') | ||
|
||
| @ns.response(HTTPStatus.NO_CONTENT, 'Activity deleted successfully') | ||
| def delete(self, id): | ||
| """Delete an activity""" | ||
| activity_dao.delete(id) | ||
| return None, 204 | ||
| return None, HTTPStatus.NO_CONTENT | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by default it is
OK. So this is redundant.