Compare commits

..

No commits in common. "a97eee842eef757e73ba31298fa792c45029bcb8" and "d9ad903798c22e8440d0005ba411e5511e63d2f8" have entirely different histories.

3 changed files with 12 additions and 57 deletions

View File

@ -17,7 +17,7 @@ matplotlib.use("agg")
import matplotlib.pyplot as plt
analysis_router = APIRouter(prefix="/analysis", tags=["analysis"])
analysis_router = APIRouter(prefix="/analysis")
C = Chemistry
@ -264,7 +264,7 @@ def mvp(
analysis_router.add_api_route(
"/graph_json/{team_id}", endpoint=graph_json, methods=["GET"]
)
# analysis_router.add_api_route("/image", endpoint=render_sociogram, methods=["POST"])
analysis_router.add_api_route("/image", endpoint=render_sociogram, methods=["POST"])
analysis_router.add_api_route("/mvp/{team_id}", endpoint=mvp, methods=["GET"])
if __name__ == "__main__":

View File

@ -22,9 +22,7 @@ C = Chemistry
R = MVPRanking
P = Player
app = FastAPI(
title="cutt", swagger_ui_parameters={"syntaxHighlight": {"theme": "monokai"}}
)
app = FastAPI(title="cutt")
api_router = APIRouter(prefix="/api")
origins = [
"https://cutt.0124816.xyz",
@ -55,7 +53,6 @@ def list_teams():
team_router = APIRouter(
prefix="/team",
dependencies=[Security(get_current_active_user, scopes=["admin"])],
tags=["team"],
)
team_router.add_api_route("/list", endpoint=list_teams, methods=["GET"])
team_router.add_api_route("/add", endpoint=add_team, methods=["POST"])
@ -70,7 +67,7 @@ somethings_fishy = HTTPException(
)
@api_router.put("/mvps", tags=["analysis"])
@api_router.put("/mvps")
def submit_mvps(
mvps: MVPRanking,
user: Annotated[Player, Depends(get_current_active_user)],
@ -90,7 +87,7 @@ def submit_mvps(
raise wrong_user_id_exception
@api_router.get("/mvps", tags=["analysis"])
@api_router.get("/mvps")
def get_mvps(
user: Annotated[Player, Depends(get_current_active_user)],
):
@ -114,7 +111,7 @@ def get_mvps(
)
@api_router.put("/chemistry", tags=["analysis"])
@api_router.put("/chemistry")
def submit_chemistry(
chemistry: Chemistry, user: Annotated[Player, Depends(get_current_active_user)]
):
@ -135,7 +132,7 @@ def submit_chemistry(
raise wrong_user_id_exception
@api_router.get("/chemistry", tags=["analysis"])
@api_router.get("/chemistry")
def get_chemistry(user: Annotated[Player, Depends(get_current_active_user)]):
with Session(engine) as session:
subquery = (

View File

@ -1,6 +1,5 @@
from typing import Annotated
from fastapi import APIRouter, Depends, Security
from fastapi.responses import PlainTextResponse
from fastapi import APIRouter, Depends
from sqlmodel import Session, select
from cutt.db import Player, Team, engine
@ -8,8 +7,6 @@ from cutt.security import change_password, get_current_active_user, read_player_
P = Player
player_router = APIRouter(prefix="/player", tags=["player"])
def add_player(player: P):
with Session(engine) as session:
@ -17,19 +14,6 @@ def add_player(player: P):
session.commit()
def add_player_to_team(player_id: int, team_id: int):
with Session(engine) as session:
player = session.exec(select(P).where(P.id == player_id)).one()
team = session.exec(select(Team).where(Team.id == team_id)).one()
if player and team:
team.players.append(player)
session.add(team)
session.commit()
return PlainTextResponse(
f"added {player.display_name} ({player.username}) to {team.name}"
)
def add_players(players: list[P]):
with Session(engine) as session:
for player in players:
@ -37,11 +21,6 @@ def add_players(players: list[P]):
session.commit()
async def list_all_players():
with Session(engine) as session:
return session.exec(select(P)).all()
async def list_players(team_id: int):
with Session(engine) as session:
statement = select(Team).where(Team.id == team_id)
@ -53,35 +32,14 @@ async def list_players(team_id: int):
]
def read_teams_me(user: Annotated[P, Depends(get_current_active_user)]):
async def read_teams_me(user: Annotated[P, Depends(get_current_active_user)]):
with Session(engine) as session:
return [p.teams for p in session.exec(select(P).where(P.id == user.id))][0]
player_router.add_api_route(
"/add",
endpoint=add_player,
methods=["POST"],
dependencies=[Security(get_current_active_user, scopes=["admin"])],
)
player_router.add_api_route(
"/list/{team_id}",
endpoint=list_players,
methods=["GET"],
dependencies=[Depends(get_current_active_user)],
)
player_router.add_api_route(
"/list",
endpoint=list_all_players,
methods=["GET"],
dependencies=[Security(get_current_active_user, scopes=["admin"])],
)
player_router.add_api_route(
"/add/{player_id}/{team_id}",
endpoint=add_player_to_team,
methods=["GET"],
dependencies=[Security(get_current_active_user, scopes=["admin"])],
)
player_router = APIRouter(prefix="/player")
player_router.add_api_route("/list/{team_id}", endpoint=list_players, methods=["GET"])
player_router.add_api_route("/add", endpoint=add_player, methods=["POST"])
player_router.add_api_route("/me", endpoint=read_player_me, methods=["GET"])
player_router.add_api_route("/me/teams", endpoint=read_teams_me, methods=["GET"])
player_router.add_api_route(