availabili.tf/backend-flask/team_integration.py

61 lines
1.6 KiB
Python
Raw Permalink Normal View History

from flask import Blueprint
from spectree import Response
from sqlalchemy.orm import joinedload
from middleware import assert_team_authority, requires_authentication, requires_team_membership
from models.player_team import PlayerTeam
from models.team import Team
from models.team_integration import TeamIntegrationSchema
from spec import spec
from app_db import db
api_team_integration = Blueprint("team_integration", __name__)
2024-12-10 18:18:40 -08:00
@api_team_integration.get("/id/<int:team_id>/integrations")
@spec.validate(
resp=Response(
HTTP_200=TeamIntegrationSchema,
),
operation_id="get_integrations"
)
@requires_authentication
@requires_team_membership()
def get_integrations(player_team: PlayerTeam, **_):
team = db.session.query(
Team
).where(
Team.id == player_team.team_id
).options(
joinedload(Team.discord_integration),
joinedload(Team.logs_tf_integration),
).one()
return team.get_integrations().dict(by_alias=True)
2024-12-10 18:18:40 -08:00
@api_team_integration.put("/id/<int:team_id>/integrations")
@spec.validate(
resp=Response(
HTTP_200=TeamIntegrationSchema,
),
operation_id="update_integrations"
)
@requires_authentication
@requires_team_membership()
def update_integrations(
player_team: PlayerTeam,
json: TeamIntegrationSchema,
**_
):
assert_team_authority(player_team)
team = db.session.query(
Team
).where(
Team.id == player_team.team_id
).options(
joinedload(Team.discord_integration),
joinedload(Team.logs_tf_integration),
).one()
team.update_integrations(json)
db.session.commit()
return json.dict(by_alias=True)