TheDocumentation 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.
models/ directory contains five classes that represent the core domain objects of the application. Each class is responsible for its own data and behavior — there is no shared base class or ORM. Database models (Usuario, Equipo, and PokedexUsuario) use static methods that open and close their own SQLite connections per operation, while Pokemon and Pokedex are pure Python objects with no direct database coupling.
Pokemon — models/pokemon.py
Pokemon — models/pokemon.py
Pokemon is a pure data class. It stores all attributes for a single Pokémon entry and provides two instance methods for convenience. It carries no database logic and is constructed both by PokeAPI (from API responses or cache rows) and by Pokedex operations.Constructor| Attribute | Type | Description |
|---|---|---|
id | int | National Pokédex number |
nombre | str | Pokémon name (lowercase) |
tipos | list[str] | List of type names (e.g. ["fire", "flying"]) |
altura | int | Height in decimeters |
peso | int | Weight in hectograms |
imagen | str | URL to the front-facing sprite image |
stats | dict | Base stats keyed by name: hp, attack, defense, special-attack, special-defense, speed |
| Method | Return type | Description |
|---|---|---|
get_tipo_principal() | str | Returns tipos[0] if the list is non-empty, otherwise returns "Normal" |
__str__() | str | Returns a formatted string: Pokemon({id}: {nombre} - {tipos}) |
Pokedex — models/pokedex.py
Pokedex — models/pokedex.py
Pokedex is a collection class that wraps an ordered list of Pokemon objects. It provides search, filter, and bulk persistence capabilities. The guardar_en_db() method is the only place where Pokedex touches the database — it writes its current contents to the cache_pokemon SQLite table using INSERT OR IGNORE so re-runs are safe.Constructorpokemones list ([]). No arguments are required.Methods| Method | Return type | Description |
|---|---|---|
agregar_pokemon(pokemon) | None | Appends a Pokemon instance to the internal pokemones list |
guardar_en_db() | None | Iterates over all Pokemon in the list and inserts each into cache_pokemon using INSERT OR IGNORE; serializes tipos and stats as JSON strings |
buscar_por_nombre(nombre) | list[Pokemon] | Case-insensitive substring search on pokemon.nombre; returns a filtered list |
filtrar_por_tipo(tipo) | list[Pokemon] | Returns all Pokémon whose tipos list contains the given type string (case-insensitive) |
obtener_todos() | list[Pokemon] | Returns the full pokemones list with no filtering |
__len__() | int | Returns the count of Pokémon in the collection (enables len(pokedex)) |
listar() | None | Prints each Pokémon entry as pokemon {nombre} to stdout — intended as a debug utility |
guardar_en_db() commits after each individual Pokémon insert rather than
batching all inserts into a single transaction. This means a failure
partway through a bulk load will leave a partial cache rather than rolling
back to an empty state.buscar_por_nombre and filtrar_por_tipoUsuario — models/usuario.py
Usuario — models/usuario.py
Usuario represents an authenticated user. Instance objects carry only id and username — the password hash is never stored in memory after authentication. All database operations are exposed as @staticmethod methods, so the class can be used without instantiating a user object first.Constructor| Attribute | Type | Description |
|---|---|---|
id | int | Primary key from the usuarios table |
username | str | The user’s unique display name |
| Method | Return type | Description |
|---|---|---|
crear(username, password) | bool | Hashes password with Werkzeug’s generate_password_hash, inserts a new row into usuarios, and returns True on success. Returns False if the username already exists (UNIQUE constraint violation). |
login(username, password) | Usuario | None | Fetches the row for username, verifies the plaintext password against the stored hash using check_password_hash, and returns a Usuario instance on match. Returns None if the user does not exist or the password is wrong. |
Equipo — models/equipo.py
Equipo — models/equipo.py
Equipo manages a per-user team of Pokémon. It enforces a hard limit of six members via the MAX_POKEMONES class constant and prevents duplicate entries. All database rows are returned as sqlite3.Row objects (dict-like), not as Pokemon instances — this is intentional since the team table stores a denormalized snapshot of each Pokémon’s display data.Class constant| Constant | Value | Description |
|---|---|---|
MAX_POKEMONES | 6 | Maximum number of Pokémon allowed on a single user’s team |
| Method | Return type | Description |
|---|---|---|
obtener_equipo(usuario_id) | list[Row] | Returns all rows from equipos where usuario_id matches |
agregar_pokemon(usuario_id, pokemon_id, pokemon_nombre, pokemon_imagen, pokemon_tipos) | (bool, str) | Validates that the team is not full and the Pokémon is not already present, then inserts the row. Returns (True, "Pokemon Agregado") on success, or (False, reason) on failure. |
eliminar_pokemon(usuario_id, pokemon_id) | (bool, str) | Searches the user’s current team for the given pokemon_id. If found, deletes the row and returns (True, "Pokémon eliminado"). Returns (False, "Este pokémon no está en tu equipo") if not found. |
agregar_pokemonPokedexUsuario — models/pokedex_usuario.py
PokedexUsuario — models/pokedex_usuario.py
PokedexUsuario tracks which Pokémon a logged-in user has viewed, recording a timestamp for each first visit. The underlying pokedex_usuario table has a UNIQUE(usuario_id, pokemon_id) constraint, so registrar_visto uses INSERT OR IGNORE to silently skip re-visits. This class has no constructor — all functionality is exposed via @staticmethod methods.Static methods| Method | Return type | Description |
|---|---|---|
registrar_visto(usuario_id, pokemon_id, pokemon_nombre) | None | Inserts a row into pokedex_usuario with the current timestamp. Silently ignores duplicates via INSERT OR IGNORE. |
obtener_vistos(usuario_id) | list[Row] | Returns all rows for the given user ordered by fecha_visto DESC (most recently viewed first). |
esta_visto(usuario_id, pokemon_id) | bool | Returns True if a row exists for the (usuario_id, pokemon_id) pair, False otherwise. |
Database Schema Reference
All four tables are created automatically bymodels/database.py on first startup via init_db(). The schema is defined inline using executescript:
| Table | Primary key | Notable constraints |
|---|---|---|
usuarios | id (AUTOINCREMENT) | username UNIQUE NOT NULL |
equipos | id (AUTOINCREMENT) | FK → usuarios.id |
cache_pokemon | id (Pokédex number) | No AUTOINCREMENT — ID is set by the API |
pokedex_usuario | id (AUTOINCREMENT) | FK → usuarios.id; UNIQUE(usuario_id, pokemon_id) |