Welcome to the PokeLike API! This project helps you track Pokémon you find cute 🥰 using an ASP.NET Core Web API backed by a PostgreSQL database.
git clone https://github.com/fac30/PRO05_BACK_Gaj_Khalos_Max.git
cd PRO05_BACK_Gaj_Khalos_Max
When using Docker, the PostgreSQL database is automatically set up in a container. No additional manual configuration is required.
Pull the Docker image from Docker Hub:
docker-compose pull
Build and start the Docker containers:
docker-compose up -d
The API will be available at http://localhost/
.
To stop the containers, run:
docker-compose down
The API will be available at http://localhost/
- no port number is needed.
To start the application locally, follow these steps:
Modify ConnectionString in appsettings.json to be hosted on localhost rather than db Docker container:
"ConnectionStrings": {
"PokeLikeDbContext": "Host=localhost;Port=5432;Database=PokeLikeDb;Username=postgres;Password=password"
}
Restore dependencies:
dotnet restore
Run the application:
dotnet run
Program.cs
: Configures services and middleware for the application.Data/PokeLikeDbContext.cs
: EF Core DbContext
configuration for managing the database context.Models/
: Contains entity models such as Pokemon
and Collection
.Migrations/
: Contains EF Core migration files.Naming Conventions:
The project uses the EFCore.NamingConventions
plugin for consistent naming. By default, snake_case
is applied to all table and column names.
builder.Services.AddDbContextPool<PokeLikeDbContext>(opt =>
opt.UseNpgsql(builder.Configuration.GetConnectionString("PokeLikeDbContext"))
.UseSnakeCaseNamingConvention());
To add a new migration after modifying models, run:
dotnet ef migrations add <MigrationName>
If you need to undo the last migration:
dotnet ef migrations remove
Ensure the latest migrations are applied to the database:
dotnet ef database update
http://localhost:8080
http://localhost:5050
{
"name": "Pikachu",
"imageUrl": "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/dream-world/25.svg",
"apiUrl": "https://pokeapi.co/api/v2/pokemon/pikachu",
"likes": 100
}
Port conflicts:
Ensure no other services are running on the ports specified in docker-compose.yml
.
Database connection issues: If the application cannot connect to the database, verify that the database container is running:
docker ps
Resetting Docker containers: To rebuild and reset all containers:
docker-compose down -v
docker system prune -a
docker-compose up --build
Resetting migration If there have been updates to the codebase, remove migrations and re-initialise them before re-running container commands:
dotnet ef migrations remove
dotnet ef migrations add InitialCreate
Pulling Docker image from Docker Hub If you have trouble authenticating and pulling the image from Docker Hub, you may need to login with Docker:
docker login