Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NZWalks API

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.

Stack

  • 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

Quick start — run locally

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 run

By default, in Development the Swagger UI will be available at: https://localhost:/swagger

appsettings (example)

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) and NZWalksAuthConnectionString (Identity data).
  • Jwt:Key should be a long, unpredictable secret in production (store in user secrets or an environment variable).

Database and seed data

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.

Running migrations

If you have the dotnet-ef tool installed, run:

# from NZWalks.API folder
dotnet ef migrations add InitialCreate
dotnet ef database update

Or use the provided Migrations/ folder if migrations are already present; just run dotnet ef database update to apply them.

Important endpoints

  • 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.

Notes and gotchas

  • Program.cs configures static file serving for the Images/ folder at request path /Images.
  • Identity is registered and uses NZWalksAuthDbContext for 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.

Contributing

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

Contact

Repository owner: @venkatavvari3


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages