Skip to content

Saved games on user profiles#126

Merged
byte-the-bot merged 1 commit into
mainfrom
saved-games
Jul 13, 2026
Merged

Saved games on user profiles#126
byte-the-bot merged 1 commit into
mainfrom
saved-games

Conversation

@byte-the-bot

Copy link
Copy Markdown
Collaborator

Implements task BS-219e7007: users can save games to their public profile with an optional title, matching the saved-games feature from play.battlesnake.com.

(Originally stacked on #121 / public-profiles; that PR has since merged, so this now targets main directly and includes only the saved-games work.)

What's included

  • Migration: saved_games table — UNIQUE (user_id, game_id) so a user can save a game once; FK'd to users and games. Up + down migrations.
  • Model (server/src/models/saved_game.rs): upsert-on-save (re-saving updates the title in place), owner-scoped delete, and a profile listing query joined with games for fallback-title metadata.
  • Routes (auth required):
    • POST /games/{id}/save — optional title form field, trimmed and capped at 100 chars server-side; flashes "Game saved to your profile" and redirects back to the game page. 404s for nonexistent games.
    • POST /saved-games/{id}/delete — owner-only (404 for anyone else), flashes and redirects to the owner's /users/{login} profile.
  • Game page: logged-in users get a small Save Game form in the aside next to the game details; if they already saved the game it pre-fills their title and the button reads "Update". Diff kept localized since other in-flight PRs touch view.rs.
  • Public profile: new "Saved Games" section after Battlesnakes — each entry links to the game, shows the title (falling back to "{game_type} on {board_size}" when untitled) plus the game date, with a Remove button visible only to the profile owner. The section itself is public.

Testing

  • #[sqlx::test] model tests: upsert behavior (same row updated on re-save, separate rows per user) and owner-scoped delete.
  • Unit tests for title normalization (trim, 100-char cap incl. multi-byte) and the display-title fallback.
  • cargo clippy --all-targets warning-free, cargo fmt clean, full suite cargo test -p arena --bin arena green (384 passed).
  • .sqlx offline cache regenerated and committed.

🤖 Generated with Claude Code

Users can save any game to their public profile with an optional title,
matching the saved-games feature from play.battlesnake.com (BS-219e7007).

- saved_games table: one row per (user, game), UNIQUE-constrained so
  re-saving a game upserts the title instead of duplicating.
- Save form in the game page aside (logged-in only): pre-fills the
  existing title and switches to an "Update" label when already saved.
- Saved Games section on the public profile: links to the game, falls
  back to "{game_type} on {board_size}" when untitled, and shows a
  Remove button to the owner (delete is owner-scoped, 404 otherwise).
- Titles are trimmed and capped at 100 chars server-side.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@byte-the-bot
byte-the-bot enabled auto-merge (squash) July 13, 2026 02:05
@byte-the-bot
byte-the-bot merged commit 8c5fd09 into main Jul 13, 2026
6 checks passed
@byte-the-bot
byte-the-bot deleted the saved-games branch July 13, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant