Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/marchena96/Paradigma-lab1/llms.txt

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

This guide walks you through cloning the repository, wiring up your PostgreSQL credentials with .NET User Secrets, building the solution, and making your first authenticated API calls — all in under 5 minutes.

Prerequisites

Before you begin, make sure you have:
  • .NET 8 SDKdownload from microsoft.com
  • A PostgreSQL database — a Supabase project (free tier works) or any local PostgreSQL 15+ instance
  • dotnet-ef global tool v8.0.2 — used by the startup auto-migration (see Step 2 below)

Setup

1

Clone the repository

Clone the repo and move into the solution root:
git clone https://github.com/marchena96/Paradigma-lab1.git && cd Paradigma-lab1
2

Install the dotnet-ef global tool

If you don’t already have dotnet-ef v8.0.2 installed globally, run:
dotnet tool install --global dotnet-ef --version 8.0.2
This tool is required for migration introspection and is used by db.Database.Migrate() at startup.
3

Register your database credentials via User Secrets

The appsettings.json file ships with the placeholder [SUPABASE-PASSWORD]no real credentials are stored in the repository. You must supply the real connection string through .NET User Secrets, which are loaded only in the Development environment.From the HackerRank1/ directory, run:
cd HackerRank1
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Host=<host>;Port=5432;Database=postgres;Username=<user>;Password=<password>;SSL Mode=Require;Trust Server Certificate=true;Pooling=false"
Replace <host>, <user>, and <password> with your actual PostgreSQL connection details. For Supabase, these are found under Project Settings → Database → Connection string (URI).
4

Build the solution

From the solution root (Paradigma-lab1/), restore packages and compile:
dotnet clean && dotnet restore && dotnet build
A successful build reports 0 errors. Any warnings shown are cosmetic nullable-reference warnings and do not affect runtime behaviour.
5

Run the API

Start the API using the --project flag to target the correct project:
dotnet run --project HackerRank1
You should see output similar to:
Now listening on: https://localhost:7098
Now listening on: http://localhost:5219
On first run, Startup.cs automatically applies any pending EF Core migrations to your database (db.Database.Migrate()), creating the Libraries and Books tables if they do not yet exist.
6

Open Swagger UI

Navigate to the interactive documentation in your browser:
https://localhost:7098/swagger
The Swagger UI lists all available endpoints and lets you send test requests directly from the browser.
Always use dotnet run --project HackerRank1 from the solution root. Running dotnet run without the --project flag fails because the solution contains two projects (HackerRank1 and LibraryService.Integration.Test) and the CLI cannot determine which one to launch.

First API call

1 — Obtain a JWT token

Use the hardcoded development credentials (admin / 1234) to get a token:
curl -X POST https://localhost:7098/login \
  -H "Content-Type: application/json" \
  -d '{"email":"admin","password":"1234"}'
A successful response returns a JSON object with a token field containing the signed JWT:
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Copy the value of token — you’ll use it as the Bearer token for protected endpoints.

2 — List all libraries

curl https://localhost:7098/api/libraries
Returns an array of library objects (empty on a fresh database):
[]

3 — Create a library

curl -X POST https://localhost:7098/api/libraries \
  -H "Content-Type: application/json" \
  -d '{"name": "My Library", "location": "123 Main St"}'
A successful response returns 201 Created with the new library object:
{
  "id": 1,
  "name": "My Library",
  "location": "123 Main St"
}
The app compiles and starts successfully even without valid database credentials. However, Migrate() is called during startup and will throw a connection exception if the DefaultConnection string is not set (or still contains the [SUPABASE-PASSWORD] placeholder). Make sure User Secrets are configured before running.

Build docs developers (and LLMs) love