-
Notifications
You must be signed in to change notification settings - Fork 0
Create api definition activies#4 #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| from flask import Flask | ||
| from flask_restplus import Api | ||
|
|
||
|
|
||
| def create_app(): | ||
| flask_app = Flask(__name__) | ||
| app = Api(app=flask_app) | ||
|
|
||
| from time_tracker_api.projects.projects_endpoints import ns as projects_ns | ||
| app.add_namespace(projects_ns) | ||
| init_app(flask_app) | ||
|
|
||
| return flask_app | ||
|
|
||
|
|
||
| def init_app(app: Flask): | ||
| from .api import api | ||
| api.init_app(app) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from flask_restplus import fields, Resource, Namespace | ||
|
|
||
| ns = Namespace('activities', description='API for activities') | ||
|
|
||
| # Activity Model | ||
| activity = ns.model('Activity', { | ||
| 'id': fields.String(readOnly=True, required=True, title='Identifier', | ||
| description='The unique id of the activity'), | ||
| 'name': fields.String(required=True, title='Name', max_length=50, | ||
| description='Canonical name of the activity'), | ||
| 'description': fields.String(title='Description', | ||
| description='Comments about the activity'), | ||
| 'tenant_id': fields.String(required=True, title='Tenant', max_length=64, | ||
| description='The tenant this belongs to') | ||
| }) | ||
|
|
||
|
|
||
| @ns.route('/') | ||
| class Activities(Resource): | ||
| @ns.doc('list_activities') | ||
| @ns.marshal_list_with(activity, code=200) | ||
| def get(self): | ||
| """List all available activities""" | ||
| return [] | ||
|
|
||
| @ns.doc('create_activity') | ||
| @ns.expect(activity) | ||
| @ns.marshal_with(activity, code=201) | ||
| @ns.response(400, 'Invalid format of the attributes of the activity.') | ||
| def post(self): | ||
| """Create a single activity""" | ||
| return ns.payload, 201 | ||
|
|
||
|
|
||
| @ns.route('/<string:id>') | ||
| @ns.response(404, 'Activity not found') | ||
| @ns.param('id', 'The unique identifier of the activity') | ||
| class Activity(Resource): | ||
| @ns.doc('get_activity') | ||
| @ns.marshal_with(activity) | ||
| def get(self, id): | ||
| """Retrieve all the data of a single activity""" | ||
| return {} | ||
|
|
||
| @ns.doc('delete_activity') | ||
| @ns.response(204, 'The activity was deleted successfully (No content is returned)') | ||
| def delete(self, id): | ||
| """Deletes a activity""" | ||
| return None, 204 | ||
|
|
||
| @ns.doc('put_activity') | ||
| @ns.response(400, 'Invalid format of the attributes of the activity.') | ||
| @ns.expect(activity) | ||
| @ns.marshal_with(activity) | ||
| def put(self, id): | ||
| """Updates an activity""" | ||
| return ns.payload |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| from flask_restplus import Api | ||
|
|
||
| api = Api(version='1.0.1', title="TimeTracker API", | ||
| description="API for the TimeTracker project") | ||
|
|
||
| # APIs | ||
| from time_tracker_api.projects import projects_api | ||
| api.add_namespace(projects_api.ns) | ||
|
|
||
| from time_tracker_api.activities import activities_api | ||
| api.add_namespace(activities_api.ns) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Shouldn't we put all the imports at the top?
On the other hand, the import
from time_tracker_api.projects import projects_apifrom what I understand, you import the fileprojects_apiand use it to reference functions inside of it. But It took me some minutes to figure it out. I think it would more easy to grasp something likefrom time_tracker_api.projects.projects_api import ns as projects_ns. But feel free to argument your approach.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.
The thing is that when I see the variable projects_ns it looks like an alias but it is not clear where it comes from, also it makes that import line bigger. When I see projects_api.ns, I understand that it comes from projects_api and that the variable it references is
ns, there is no possible abstract interpretation.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.
I did the import in the same part where I added that namespace because it seemed a good idea to have them together in case I wanted to remove or comment the inclusion of a particular namespace.