Skip to content

Commit

Permalink
chore: removed unused deps and described endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
suchencjusz committed Sep 10, 2024
1 parent 2bbfb67 commit e644c36
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
9 changes: 4 additions & 5 deletions src/filman_server/routes/discord.py
Original file line number Diff line number Diff line change
@@ -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"])

Expand Down
42 changes: 29 additions & 13 deletions src/filman_server/routes/tasks.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,28 +29,37 @@ 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:
raise HTTPException(status_code=404, detail="Task not found")
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:
raise HTTPException(status_code=404, detail="Task not found")
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:
Expand Down
37 changes: 28 additions & 9 deletions src/filman_server/routes/users.py
Original file line number Diff line number Diff line change
@@ -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"])

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e644c36

Please sign in to comment.