diff --git a/src/api.py b/src/api.py index ef0a7a0..bd911dd 100644 --- a/src/api.py +++ b/src/api.py @@ -11,54 +11,14 @@ from datamodels import DataModel from constants import DATA_VERSION from modules.profiles.data import ProfileData +from routes import dbvar, datamodelsv, profiledatav, register_routes -from routes.stamps import routes as stamp_routes -from routes.documents import routes as doc_routes -from routes.users import routes as user_routes -from routes.specimens import routes as spec_routes -from routes.transactions import routes as txn_routes -from routes.events import routes as event_routes -from routes.lib import dbvar, datamodelsv, profiledatav sys.path.insert(0, os.path.join(os.getcwd())) sys.path.insert(0, os.path.join(os.getcwd(), "src")) logger = logging.getLogger(__name__) -# TODO: Move the route table to the __init__ of routes -# Maybe we can join route tables together? -# Or we just expose an add_routes or register method - -""" -- `/stamps` with `POST`, `PUT`, `GET` -- `/stamps/{stamp_id}` with `GET`, `PATCH`, `DELETE` - -- `/documents` with `POST, GET` -- `/documents/{document_id}` with `GET`, `PATCH`, `DELETE` -- `/documents/{document_id}/stamps` which is passed to `/stamps` with `document_id` set. - -- `/events` with `POST`, `GET` -- `/events/{event_id}` with `GET`, `PATCH`, `DELETE` -- `/events/{event_id}/document` which is passed to `/documents/{document_id}` -- `/events/{event_id}/user` which is passed to `/users/{user_id}` - -- `/users` with `POST`, `GET`, `PATCH`, `DELETE` -- `/users/{user_id}` with `GET`, `PATCH`, `DELETE` -- `/users/{user_id}/events` which is passed to `/events` -- `/users/{user_id}/specimen` which is passed to `/specimens/{specimen_id}` -- `/users/{user_id}/specimens` which is passed to `/specimens` -- `/users/{user_id}/wallet` with `GET` -- `/users/{user_id}/transactions` which is passed to `/transactions` - -- `/specimens` with `GET` and `POST` -- `/specimens/{specimen_id}` with `PATCH` and `DELETE` -- `/specimens/{specimen_id}/owner` which is passed to `/users/{user_id}` - -- `/transactions` with `POST`, `GET` -- `/transactions/{transaction_id}` with `GET`, `PATCH`, `DELETE` -- `/transactions/{transaction_id}/user` which is passed to `/users/{user_id}` -""" - async def attach_db(app: web.Application): db = Database(conf.data['args']) async with db.open(): @@ -84,19 +44,14 @@ async def attach_db(app: web.Application): async def test(request: web.Request) -> web.Response: - return web.Response(text="Hello World") + return web.Response(text="Welcome to the Dreamspace API. Please donate an important childhood memory to continue.") def app_factory(): auth = key_auth_factory(conf.API['TOKEN']) app = web.Application(middlewares=[auth]) app.cleanup_ctx.append(attach_db) app.router.add_get('/', test) - app.router.add_routes(stamp_routes) - app.router.add_routes(doc_routes) - app.router.add_routes(user_routes) - app.router.add_routes(spec_routes) - app.router.add_routes(event_routes) - app.router.add_routes(txn_routes) + register_routes(app.router) return app diff --git a/src/routes/__init__.py b/src/routes/__init__.py new file mode 100644 index 0000000..71bce2c --- /dev/null +++ b/src/routes/__init__.py @@ -0,0 +1,16 @@ +from .stamps import routes as stamp_routes +from .documents import routes as doc_routes +from .users import routes as user_routes +from .specimens import routes as spec_routes +from .transactions import routes as txn_routes +from .events import routes as event_routes +from .lib import dbvar, datamodelsv, profiledatav + + +def register_routes(router): + router.add_routes(stamp_routes) + router.add_routes(doc_routes) + router.add_routes(user_routes) + router.add_routes(spec_routes) + router.add_routes(event_routes) + router.add_routes(txn_routes)