This is an ASP.NET Core Web API project that fetches cat images from the Cats as a Service (CaaS) API and stores them in a Microsoft SQL Server database using Entity Framework Core.
Before you begin, ensure you have the following installed:
- .NET 8 SDK
- Docker
- JetBrains Rider (or any other compatible IDE)
-
Navigate to the Project Directory:
- Open your terminal or command prompt and navigate to the directory containing the
compose.yaml
file.
- Open your terminal or command prompt and navigate to the directory containing the
-
Start the SQL Server Container:
- Run the following command:
docker compose up -d
- This will start a SQL Server container using the configuration defined in
compose.yaml
.
- Run the following command:
-
Verify Container Status:
- Run
docker ps
to ensure the sql server container is running.
- Run
-
Open the Project in JetBrains Rider:
- Open the project in JetBrains Rider.
- Install the following nugets:
- Microsoft.EntityFrameworkCore.SqlServer
- Microsoft.EntityFrameworkCore.Tools
- Swashbuckle.AspNetCore
- Newtonsoft.Json
-
Database Migration:
- Open the terminal within Rider.
- Run the following Entity Framework Core migration commands:
dotnet ef migrations add InitialCreate
anddotnet ef database update
- This will create the database and tables in your SQL Server instance.
-
Run the Application:
- Run the ASP.NET Core Web API project from Rider.
-
Access Swagger UI:
- Open your web browser and navigate to
https://localhost:<port>/swagger
(replace<port>
with the port number shown in the Rider console).
- Open your web browser and navigate to
- POST /api/cats/fetch:
- Fetches at most 25 cats that have breeds from https://api.thecatapi.com/
- GET /api/cats/{id}:
- Gets a specific cat with a given id from our DB
- GET /api/cats:
- Gets a number of cats, paginated from our DB. You may apply a criterion (having a specific tag) or not.
- appsettings.json:
- Contains the database connection string. Make sure to update the password if you changed the default from compose.yaml.
You need to add the following nugets:
- xunit
- Microsoft.EntityFrameworkCore.InMemory
- Moq
- Microsoft.NET.Test.Sdk
The file containing the tests is under Tests folder and tests the CatsController code.