From 388c89cc40575a752ee34fa71575761f1e5934f9 Mon Sep 17 00:00:00 2001 From: IgorVolochay Date: Mon, 17 Feb 2025 13:24:19 +0300 Subject: [PATCH] Create base FastAPI routs --- app/main.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 5a11942..2fd3573 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,29 @@ +import uvicorn +import asyncio + +from schemas import * + +from fastapi import FastAPI, Depends from mongo_worker import MongoWorker + +app = FastAPI() + +@app.get("/check_user") +async def check_user(user_id: int, mongo: MongoWorker = Depends(MongoWorker)) -> BaseResponse: + result = mongo.check_user(user_id) + return BaseResponse(result=result) + +@app.get("/get_user") +async def get_user(user_id: int, mongo: MongoWorker = Depends(MongoWorker)) -> BaseResponse: + result = mongo.get_user(user_id) + return BaseResponse(result=result) + + +async def main(): + config = uvicorn.Config("main:app", port=5000, log_level="info") + server = uvicorn.Server(config) + await server.serve() + if __name__ == "__main__": - print("Hello World!") \ No newline at end of file + asyncio.run(main()) \ No newline at end of file