Add flask-smorest dependencies and test route#11
Conversation
This commit squashes a number of smaller commits and adds the following: flask-smorest as a dependency A "user" model, schema, blueprint and routes for testing purposes API documentation (auto-generated by Swagger)
|
Oh, shoot, I should have opened this as a draft request. Feel free to check it out but I don't really want to merge until I've replaced the user test stuff with some real code. |
If this is a WIP and you want to convert it to a draft, you can still do so. There's an option for that in the right sidebar, just below the Reviewers section. |
Renamed "annotations-field" to "field" Updated models Introduced schemas for Field, Tool, Task Wrote and registered /task blueprint
|
Ok, I've now established a working route at /api/tasks and some mock data. It does require a small amount of setup:
|
|
Ok, I'm done with updates on this branch (aside from requested revisions, of course!) It's gone well beyond its original remit, but we now have a working endpoint at |
HWaruguru
left a comment
There was a problem hiding this comment.
Looks good. only thing is that you need to expose the database port in docker-compose so that it can be easy to view the tables in a tool like Tableplus
Can you open a pull request for that? I don't use any tools like that and am not sure how to configure them. If it's just a matter of exposing a port it should be an easy fix, I guess. (But nothing seems to happen easily between me and Docker.) |
api/resources/db.py
Outdated
| @@ -0,0 +1,2 @@ | |||
| from flask_sqlalchemy import SQLAlchemy | |||
There was a problem hiding this comment.
For what reason(s) did you move the initialization of the db to its own file from /api/__init__py?
There was a problem hiding this comment.
IIRC once I started importing it into various locations I started running into error messages; I may have gotten myself stuck in some sort of circular import loop. I'll test it out and see if I can pin down the problem.
There was a problem hiding this comment.
Ah, I see. I was just caught up in the idea that I had to do all of my imports first. I can solve the problem by initializing the db and then importing the blueprints, etc. Will push a fix.
data/__init__.py
Outdated
| from api.models import Tool, Field, Task | ||
| from api.resources.db import db | ||
|
|
||
| def insertData(): |
There was a problem hiding this comment.
This could be moved to manage.py so the db could be seeded from the command line (or a script). That way, we could also remove the call to insertData from inside our index route in app.py
nit: Python variables are conventionally named using snake_case. I know you know this, but JS has a way of polluting the mind xd
data/fieldData.py
Outdated
| @@ -0,0 +1,11 @@ | |||
| fieldData = [ | |||
There was a problem hiding this comment.
Having all mock data inside a single file would reduce complexity a bit
|
There's a lot going on in this PR, which is mainly my fault for not getting to it earlier. Let's do a little bit of cleanup step by step. We can start with the db stuff. We already have the I've also left some comments inline. |
I'd been slacking on properly implementing migrations. I've addressed the other points and will get to this one next. |
The User class was for testing purposes only.
|
So as of af7f574 I'm up to the following commands for initializing and inserting data into the db: From the flask container, Is there a way to automate these processes? I tried various ways of inserting these commands into the Dockerfile and docker-compose, but without success. |
Yes – this is what the
|
| flask run --host=0.0.0.0 --port=5000 | ||
| #flask db upgrade | ||
| flask run --host=0.0.0.0 --port=5000 No newline at end of file | ||
| #python manage.py insert_data No newline at end of file |
There was a problem hiding this comment.
I recalled the cv-model-serve code you'd shown me before and copied a lot of that. I was able to get things running using /start but the other commands here in the start file had no effect. (They're just commented out here because they weren't doing anything and I wanted to commit a "working" version.)
(I was intending to highlight multiple lines of code here but obviously that didn't work out. I'm referring to the contents of compose/flask/start)
* Add /api/contribution endpoint * Add route for getting leaderboard data
This commit squashes a number of smaller commits and adds the following:
flask-smorest as a dependency
A "user" model, schema, blueprint and routes for testing purposes
API documentation (auto-generated by Swagger)
To test: follow the instructions in the README to get everything running and start the db
API docs available at
localhost:5000/api/documentationTo test the current route, using Postman (or equivalent), make a POST request to
localhost:5000/userswith the bodyThen a GET request to the same endpoint should return the list of users.