31 lines
812 B
Python
31 lines
812 B
Python
from flask import Blueprint, jsonify
|
|
from backend.models import db, Team
|
|
|
|
bp = Blueprint('teams', __name__, url_prefix='/api/teams')
|
|
|
|
|
|
@bp.route('/past-names', methods=['GET'])
|
|
def get_past_team_names():
|
|
"""Get distinct team names from past games"""
|
|
past_names = db.session.query(Team.name)\
|
|
.distinct()\
|
|
.order_by(Team.name)\
|
|
.all()
|
|
return jsonify([name[0] for name in past_names]), 200
|
|
|
|
|
|
@bp.route('/<int:team_id>', methods=['DELETE'])
|
|
def delete_team(team_id):
|
|
"""Delete a team"""
|
|
team = Team.query.get_or_404(team_id)
|
|
|
|
try:
|
|
db.session.delete(team)
|
|
db.session.commit()
|
|
|
|
return jsonify({'message': 'Team deleted successfully'}), 200
|
|
|
|
except Exception as e:
|
|
db.session.rollback()
|
|
return jsonify({'error': str(e)}), 500
|