The Battles page, accessible atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/HectorDNC/galactic-tournament-front/llms.txt
Use this file to discover all available pages before exploring further.
/battles, is the combat engine of the Galactic Tournament. It supports two distinct modes: a manual battle where you hand-pick both fighters from live search dropdowns, and a random battle where the server selects the combatants entirely at random. In both cases the result is displayed inline with the winner clearly highlighted, and toast notifications confirm success or surface errors via AlertService.
API Endpoints
| Method | Path | Description |
|---|---|---|
GET | /api/species?page=0&size=10&name=<search> | Search species by name to populate fighter dropdowns. |
POST | /api/battles | Start a manual battle between two chosen species. |
POST | /api/battles/random | Start a random battle; the server selects both fighters. |
https://galactic-tournament-app-production.up.railway.app
Data Models
BattleRequest Fields
The
id of the species assigned to the left position in the arena.The
id of the species assigned to the right position in the arena. Must be different from fighterLeftId.BattleResult Fields
Unique identifier of the battle record.
Full species object for the left-side fighter.
Full species object for the right-side fighter. Same shape as
fighterLeft.Full species object for the victor. The component compares
winner.id with fighterLeft.id and fighterRight.id to apply visual highlighting.ISO timestamp of when the battle was executed.
Fighter Search Dropdowns
Both the left and right fighter panels use live search powered bySpeciesService.findAll. As you type, the component fires a request to:
The left dropdown automatically excludes the species already selected as the right fighter, and vice versa. This prevents the same species from fighting itself.
clearLeft() / clearRight() removes the selection and resets the current result. Dropdowns also close when you click anywhere outside their container thanks to a @HostListener('document:click') handler.
Manual Battle
To start a manual battle both fighter slots must be filled. The orange ⚔️ ¡Iniciar Combate! button is disabled (canFight = false) until both fighters are selected and no fight is already in progress.
Clicking Fight calls BattleService.start:
BattleResult is stored in result and a success toast announces the winner’s name. While the request is in-flight the button label changes to Combatiendo… and a spinner is shown.
Random Battle
Clicking the purple 🎲 Combate Aleatorio button first opens a confirmation dialog asking “Se generará un combate entre dos especies aleatorias. ¿Deseas continuar?”. Confirming callsBattleService.randomBattle:
selectFighterLeft(res.fighterLeft) and selectFighterRight(res.fighterRight), then stores the result exactly as in a manual battle.
The random battle button is disabled while any battle is currently in progress (
fighting = true) to prevent concurrent requests.Winner Highlighting
After aBattleResult is returned, isWinner(specie) evaluates result.winner.id === specie.id. The winning fighter card receives:
- A gold border (
border-yellow-400) - A yellow background tint (
bg-yellow-50) - A 🏆 GANADOR badge
Reset
After a battle resolves a Nuevo combate link appears beneath the arena. Clicking it callsresetBattle(), which clears both fighter selections, both search inputs, and the stored result:
Toast Notifications
All outcomes are surfaced throughAlertService:
| Event | Message |
|---|---|
| Manual battle success | "Batalla realizada! Ganador: {winner.name}" |
| Manual battle error | "Error al realizar la batalla" |
| Random battle success | "Batalla aleatoria realizada! Ganador: {winner.name}" |
| Random battle error | "Error al generar la batalla aleatoria" |