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