Save finished games and add history views

This commit is contained in:
2026-03-03 19:05:54 +01:00
parent 7887986a5a
commit d1b432f8aa
11 changed files with 919 additions and 33 deletions
+30 -2
View File
@@ -1,5 +1,11 @@
from flask import Blueprint, render_template, redirect, url_for, request
from flask import Blueprint, render_template, redirect, url_for, request, abort
from flask_login import login_required, current_user
from app.models.game import (
build_board_rows,
get_game_for_user,
group_move_pairs,
list_games_for_user,
)
from app.routes.friends import _friends_page_data
main_bp = Blueprint("main", __name__)
@@ -23,9 +29,31 @@ def play():
return render_template("play.html")
@main_bp.route("/games", methods=["GET"])
@login_required
def games_history():
games = list_games_for_user(current_user.id)
return render_template("games.html", games=games)
@main_bp.route("/games/<int:game_id>", methods=["GET"])
@login_required
def game_detail(game_id: int):
game = get_game_for_user(game_id, current_user.id)
if not game:
abort(404)
return render_template(
"game_detail.html",
game=game,
board_rows=build_board_rows(game.final_fen),
move_pairs=group_move_pairs(game.move_history),
)
#todo: decide if this should get moved to the friends.py file
@main_bp.route("/friends", methods=["GET"])
@login_required
def friends():
data = _friends_page_data(request.args.get("q", ""))
return render_template("friends.html", **data)
return render_template("friends.html", **data)