From e644c36b88b0e5490dbe27e8bd5b949c5698d1dd Mon Sep 17 00:00:00 2001 From: kuba Date: Wed, 11 Sep 2024 00:28:29 +0200 Subject: [PATCH] chore: removed unused deps and described endpoints --- src/filman_server/routes/discord.py | 9 ++-- src/filman_server/routes/tasks.py | 42 +++++++++++++------ src/filman_server/routes/users.py | 37 ++++++++++++---- .../tests_routes/test_discord_integration.py | 2 +- .../tests_routes/test_users_integration.py | 2 +- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/src/filman_server/routes/discord.py b/src/filman_server/routes/discord.py index 866ea7e..85734b4 100644 --- a/src/filman_server/routes/discord.py +++ b/src/filman_server/routes/discord.py @@ -1,12 +1,11 @@ -from typing import Any, Dict, List, Optional +from typing import List -from fastapi import APIRouter, Depends, FastAPI, HTTPException -from fastapi.responses import JSONResponse +from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session -from filman_server.database import crud, models, schemas -from filman_server.database.db import SessionLocal, engine, get_db +from filman_server.database import crud, schemas +from filman_server.database.db import get_db discord_router = APIRouter(prefix="/discord", tags=["discord"]) diff --git a/src/filman_server/routes/tasks.py b/src/filman_server/routes/tasks.py index 8f21d10..fda6503 100644 --- a/src/filman_server/routes/tasks.py +++ b/src/filman_server/routes/tasks.py @@ -1,18 +1,25 @@ +# for what purpose rabbitmq exists +# if you can build your task broker and learn something :~~~~D + from datetime import datetime -from typing import Any, Dict, List, Optional +from typing import List from fastapi import APIRouter, Depends, HTTPException, Query from fastapi.responses import JSONResponse -from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session -from filman_server.database import crud, models, schemas -from filman_server.database.db import SessionLocal, engine, get_db +from filman_server.database import crud, schemas +from filman_server.database.db import get_db tasks_router = APIRouter(prefix="/tasks", tags=["tasks"]) -@tasks_router.post("/create", response_model=schemas.Task) +@tasks_router.post( + "/create", + response_model=schemas.Task, + summary="Create a task", + description="Create a task to do", +) def create_task(task: schemas.TaskCreate, db: Session = Depends(get_db)): task.task_created = datetime.now() task.task_started = None @@ -22,7 +29,11 @@ def create_task(task: schemas.TaskCreate, db: Session = Depends(get_db)): return db_task -@tasks_router.head("/get/task/to_do") +@tasks_router.head( + "/get/task/to_do", + summary="Check if is any task to do", + description="Check if is any task to do for given task types (only check)", +) def get_task_to_do_head(task_types: List[schemas.TaskTypes] = Query(...), db: Session = Depends(get_db)): db_task = crud.get_task_to_do(db, task_types, head=True) if db_task is None: @@ -30,7 +41,12 @@ def get_task_to_do_head(task_types: List[schemas.TaskTypes] = Query(...), db: Se return JSONResponse(content={"task_id": db_task.task_id}) -@tasks_router.get("/get/task/to_do", response_model=schemas.Task) +@tasks_router.get( + "/get/task/to_do", + response_model=schemas.Task, + summary="Get task to do", + description="Get task to do for given task types", +) def get_task_to_do(task_types: List[schemas.TaskTypes] = Query(...), db: Session = Depends(get_db)): db_task = crud.get_task_to_do(db, task_types, head=False) if db_task is None: @@ -38,12 +54,12 @@ def get_task_to_do(task_types: List[schemas.TaskTypes] = Query(...), db: Session return db_task -# -# -# - - -@tasks_router.get("/update/task/status/{task_id}/{task_status}", response_model=schemas.Task) +@tasks_router.get( + "/update/task/status/{task_id}/{task_status}", + response_model=schemas.Task, + summary="Update task status", + description="Update task status to given status", +) def update_task_status(task_id: int, task_status: schemas.TaskStatus, db: Session = Depends(get_db)): db_task = crud.update_task_status(db, task_id, task_status) if db_task is None: diff --git a/src/filman_server/routes/users.py b/src/filman_server/routes/users.py index 0b678c0..b79762f 100644 --- a/src/filman_server/routes/users.py +++ b/src/filman_server/routes/users.py @@ -1,12 +1,11 @@ -from typing import List, Optional +from typing import List -from fastapi import APIRouter, Depends, FastAPI, HTTPException -from fastapi.responses import JSONResponse +from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.exc import IntegrityError from sqlalchemy.orm import Session -from filman_server.database import crud, models, schemas -from filman_server.database.db import SessionLocal, engine, get_db +from filman_server.database import crud, schemas +from filman_server.database.db import get_db users_router = APIRouter(prefix="/users", tags=["users"]) @@ -51,7 +50,12 @@ async def get_user( # -@users_router.get("/get_all_guilds", response_model=List[schemas.DiscordDestinations]) +@users_router.get( + "/get_all_guilds", + response_model=List[schemas.DiscordDestinations], + summary="Get all user guilds", + description="Get all guilds user is in", +) async def get_guilds( user_id: int | None = None, discord_id: int | None = None, @@ -68,7 +72,12 @@ async def get_guilds( return discord_destinations -@users_router.get("/add_to_guild", response_model=schemas.DiscordDestinations) +@users_router.get( + "/add_to_guild", + response_model=schemas.DiscordDestinations, + summary="Add user to discord guild", + description="Add user to discord guild (guild must be in db first)", +) async def add_to_guild( discord_id: int, discord_guild_id: int, @@ -95,7 +104,12 @@ async def add_to_guild( return discord_destination -@users_router.delete("/remove_from_guild", response_model=schemas.DiscordDestinations) +@users_router.delete( + "/remove_from_guild", + response_model=schemas.DiscordDestinations, + summary="Remove user from discord guild", + description="Remove user from discord (the message destination for notifications)", +) async def remove_from_guild( user_id: int | None = None, discord_user_id: int | None = None, @@ -123,7 +137,12 @@ async def remove_from_guild( return discord_destination -@users_router.delete("/remove_from_all_guilds", response_model=List[schemas.DiscordDestinations]) +@users_router.delete( + "/remove_from_all_guilds", + response_model=List[schemas.DiscordDestinations], + summary="Remove user from all guilds", + description="Remove user from all guilds (the message destinations for notifications)", +) async def remove_from_all_guilds( user_id: int | None = None, discord_user_id: int | None = None, diff --git a/tests/integration/tests_filman_server/tests_routes/test_discord_integration.py b/tests/integration/tests_filman_server/tests_routes/test_discord_integration.py index 188f5bd..3f24018 100644 --- a/tests/integration/tests_filman_server/tests_routes/test_discord_integration.py +++ b/tests/integration/tests_filman_server/tests_routes/test_discord_integration.py @@ -5,7 +5,7 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from filman_server.database import models, schemas +from filman_server.database import models from filman_server.database.db import Base, get_db from filman_server.main import app diff --git a/tests/integration/tests_filman_server/tests_routes/test_users_integration.py b/tests/integration/tests_filman_server/tests_routes/test_users_integration.py index 167fd7b..f279b2f 100644 --- a/tests/integration/tests_filman_server/tests_routes/test_users_integration.py +++ b/tests/integration/tests_filman_server/tests_routes/test_users_integration.py @@ -5,7 +5,7 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from filman_server.database import models, schemas +from filman_server.database import models from filman_server.database.db import Base, get_db from filman_server.main import app