feat(game): add GET /{gameId}/fen-history endpoint
Build & Test (NowChessSystems) TeamCity build finished

Returns a FEN string for every ply of the game (initial position + one
per move) by replaying moves via ruleSet.applyMove and exporting each
GameContext to FEN. Enables full per-move engine analysis from clients
without requiring a chess library on their side.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Janis Eccarius
2026-06-21 10:54:35 +02:00
parent 7bf91b2280
commit fba324a5b0
2 changed files with 15 additions and 0 deletions
@@ -0,0 +1,3 @@
package de.nowchess.api.dto
final case class FenHistoryDto(fens: List[String])
@@ -339,6 +339,18 @@ class GameResource:
log.infof("Imported PGN game %s", entry.gameId)
created(GameDtoMapper.toGameFullDto(entry, ioClient))
@GET
@Path("/{gameId}/fen-history")
@Produces(Array(MediaType.APPLICATION_JSON))
def getFenHistory(@PathParam("gameId") gameId: String): Response =
val entry = registry.get(gameId).getOrElse(throw GameNotFoundException(gameId))
val engine = entry.engine
val initial = engine.initialContext
val moves = engine.context.moves
val contexts = moves.scanLeft(initial)((ctx, move) => engine.ruleSet.applyMove(ctx)(move))
val fens = contexts.map(ctx => ioClient.exportFen(ctx))
ok(FenHistoryDto(fens))
@GET
@Path("/{gameId}/export/fen")
@Produces(Array(MediaType.TEXT_PLAIN))