A .NET 7 ASP.NET Core Web API that models New Zealand walks (regions, difficulties, walks), with EF Core persistence, Identity + JWT authentication, image hosting, and Swagger documentation. This repository is suitable as a learning project or small backend service.
- Language: C# (.NET 7)
- Framework: ASP.NET Core Web API
- Notable libraries: AutoMapper, Entity Framework Core (SqlServer), ASP.NET Core Identity + JWT, Swashbuckle (Swagger), Serilog
Prerequisites
- .NET 7 SDK installed
- SQL Server instance reachable (local or remote)
Steps
# from repo root
cd NZWalks.API
dotnet restore
dotnet build
# apply EF Core migrations (ensure connection strings are set)
dotnet ef database update --project .
# run the API
dotnet runBy default, in Development the Swagger UI will be available at: https://localhost:/swagger
Create or update appsettings.Development.json (or set equivalent environment variables) with your connection strings and JWT settings. Example:
{
"ConnectionStrings": {
"NZWalksConnectionString": "Server=.;Database=NZWalksDb;Trusted_Connection=True;",
"NZWalksAuthConnectionString": "Server=.;Database=NZWalksAuthDb;Trusted_Connection=True;"
},
"Jwt": {
"Issuer": "your-issuer",
"Audience": "your-audience",
"Key": "a-very-strong-secret-key-change-me"
},
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}Notes:
- The app expects two connection strings:
NZWalksConnectionString(application data) andNZWalksAuthConnectionString(Identity data). Jwt:Keyshould be a long, unpredictable secret in production (store in user secrets or an environment variable).
The EF Core DbContext (NZWalksDbContext) seeds initial data in OnModelCreating:
Difficulties (fixed GUIDs):
- Easy: a5f52eb3-6ab7-4e29-b06b-b1d7197dc934
- Medium: c6a0adc7-2cb7-47bf-82ee-b0c391700fcb
- Hard: 28852d9f-7af0-4f50-82de-4b686a61d880
Regions (sample fixed GUIDs):
- Auckland: f7248fc3-2585-4efb-8d1d-1c555f4087f6
- Northland: 6884f7d7-ad1f-4101-8df3-7a6fa7387d81
- Bay Of Plenty: 14ceba71-4b51-4777-9b17-46602cf66153
- Wellington: cfa06ed2-bf65-4b65-93ed-c9d286ddb0de
- Nelson: 906cb139-415a-4bbb-a174-1a1faf9fb1f6
- Southland: f077a22e-4248-4bf6-b564-c7cf4e250263
These seeded GUIDs are useful for automated tests or quick manual checks after applying migrations.
If you have the dotnet-ef tool installed, run:
# from NZWalks.API folder
dotnet ef migrations add InitialCreate
dotnet ef database updateOr use the provided Migrations/ folder if migrations are already present; just run dotnet ef database update to apply them.
- GET /api/regions -> list regions (requires Reader role for single-region endpoint; GetAll is public in current code)
- GET /api/regions/{id} -> get a region by GUID (requires Reader role)
- POST /api/regions -> create region (requires Writer role)
- PUT /api/regions/{id} -> update region (requires Writer role)
- DELETE /api/regions/{id} -> delete region (requires Writer/Reader role)
Swagger UI shows the full endpoint list and request/response models when the app is running in Development.
- Program.cs configures static file serving for the
Images/folder at request path/Images. - Identity is registered and uses
NZWalksAuthDbContextfor persistence; ensure that DbContext exists in the project and migrations are applied for the auth DB too. - Logging via Serilog is included but commented out in Program.cs; enable/configure as needed.
Feel free to open issues or pull requests. Suggestions:
- Add integration tests for controllers (use the seeded GUIDs)
- Add Dockerfile / docker-compose for local development
- Add detailed README sections for CI and deployment
Repository owner: @venkatavvari3