Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Navi-27/Proyecto-UPC/llms.txt

Use this file to discover all available pages before exploring further.

The Team Builder (GET /equipo) lets every registered user assemble a personal roster of up to 6 Pokémon. Unlike My Pokédex, which is populated automatically by browsing, building a team is an intentional action — you choose exactly which Pokémon to include by clicking Add to Team on each individual detail page. Your team is independent of every other user’s, and you can swap members in and out at any time.

Authentication Requirement

The team page and all team-management routes are protected. Unauthenticated requests to /equipo, /equipo/agregar/..., and /equipo/eliminar/<pokemon_id> are all redirected to /login.

Full Workflow

1

Browse to a Pokémon's detail page

Navigate to http://localhost:5000/pokemon/<nombre> for any Pokémon you want to add — for example, http://localhost:5000/pokemon/charizard. The detail page shows the sprite, types, height, weight, and base stats.
2

Click 'Add to Team'

When logged in, a green ➕ Agregar a mi equipo button appears at the bottom of the stat card. Clicking it sends a GET request to:
/equipo/agregar/<pokemon_id>/<nombre>/<imagen>/<tipos>
All the information needed to store the Pokémon (ID, name, sprite URL, and types JSON string) is passed directly in the URL path, so the server needs no additional lookup.
3

Server validates and inserts

The route handler calls Equipo.agregar_pokemon(usuario_id, pokemon_id, pokemon_nombre, pokemon_imagen, pokemon_tipos). The method performs two checks before inserting:
  • Team is full — if len(equipo) >= Equipo.MAX_POKEMONES (i.e. ≥ 6), it returns (False, "El equipo ya esta completo (6 Pokemones)") without writing to the database.
  • Duplicate Pokémon — if the Pokémon’s pokemon_id already appears in any team row for this user, it returns (False, "El pokemon ya se encuentra en tu equipo").
  • Success — otherwise, the Pokémon is inserted into the equipos table and the method returns (True, "Pokemon Agregado").
# models/equipo.py
@staticmethod
def agregar_pokemon(usuario_id, pokemon_id, pokemon_nombre, pokemon_imagen, pokemon_tipos):
    equipo = Equipo.obtener_equipo(usuario_id)
    if len(equipo) >= Equipo.MAX_POKEMONES:
        return False, "El equipo ya esta completo (6 Pokemones)"

    for p in equipo:
        if p["pokemon_id"] == pokemon_id:
            return False, "El pokemon ya se encuentra en tu equipo"

    conn = get_connection()
    conn.execute(
        "INSERT INTO equipos (usuario_id, pokemon_id, pokemon_nombre, pokemon_imagen, pokemon_tipos) VALUES (?,?,?,?,?)",
        (usuario_id, pokemon_id, pokemon_nombre, pokemon_imagen, pokemon_tipos)
    )
    conn.commit()
    conn.close()
    return True, "Pokemon Agregado"
4

Flash message confirms the result

After agregar_pokemon() returns, the route calls flash(mensaje, "success" if exito else "Error") and redirects back to the Pokémon’s detail page (/pokemon/<nombre>). A green success banner or a red error banner appears at the top of the page to confirm what happened.
5

View your full team at /equipo

Navigate to http://localhost:5000/equipo to see your complete roster. The page header shows your current count in the format n/6 pokemones. Each team slot is displayed as a card with:
  • nombre — Pokémon name (capitalised)
  • imagen — official front sprite
  • tipos — coloured type badges, parsed from the stored JSON string using the parse_tipos Jinja2 filter
6

Remove a Pokémon from your team

Each team card includes a red Eliminar button. Clicking it calls:
/equipo/eliminar/<pokemon_id>
The route calls Equipo.eliminar_pokemon(usuario_id, pokemon_id), which verifies the Pokémon belongs to this user’s team and then runs DELETE FROM equipos WHERE usuario_id = ? AND pokemon_id = ?. A flash message confirms removal, and you are redirected back to /equipo.

Team Constraints

The following hard limits are enforced server-side by the Equipo model — they cannot be bypassed by crafting a URL manually, because the validation runs inside Equipo.agregar_pokemon() before any database write occurs.
  • Maximum 6 Pokémon per team — enforced by Equipo.MAX_POKEMONES = 6. Attempting to add a seventh Pokémon returns the error message El equipo ya esta completo (6 Pokemones).
  • No duplicate Pokémon — each pokemon_id may appear at most once per user. Adding a Pokémon already on your team returns El pokemon ya se encuentra en tu equipo.
  • Teams are per-user — the equipos table is keyed on usuario_id. Every registered account maintains a completely independent roster; changes to one user’s team never affect another’s.

Equipo Database Schema

Each row in the equipos table stores everything the team page needs to render a card without any additional lookup:
ColumnTypeDescription
usuario_idintForeign key linking the entry to a registered user
pokemon_idintNational Pokédex number (used for deduplication and removal)
pokemon_nombrestrPokémon name slug (e.g. charizard)
pokemon_imagenstrAbsolute sprite URL (e.g. https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/6.png)
pokemon_tiposstrJSON-encoded list of type slugs (e.g. '["fire", "flying"]') decoded at render time by the parse_tipos filter

Build docs developers (and LLMs) love