Skip to content

Controller based web api, pagination, filtering, sorting, authentication, authorization, versioning, image upload, logging

Notifications You must be signed in to change notification settings

Sonseldeep/Walk.Api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NZ Walks API

A RESTful API for managing walking trails in New Zealand, built with ASP.NET Core and Entity Framework Core.

Architecture

This project follows Clean Architecture principles with the following layers:

  • API Layer: Controllers and DTOs for handling HTTP requests
  • Domain Layer: Core business entities and models
  • Data Layer: Entity Framework Core with Repository pattern
  • Infrastructure: Database context and configurations

Key Features

  • CRUD operations for Walks, Regions, and Difficulties
  • Filtering and sorting capabilities
  • Model validation with Data Annotations
  • Repository pattern implementation
  • Async/await throughout
  • Entity Framework Core with SQL Server

Technology Stack

  • Framework: ASP.NET Core 8.0
  • Database: SQL Server
  • ORM: Entity Framework Core
  • Language: C# 12
  • Architecture: Repository Pattern + Clean Architecture

Prerequisites

Getting Started

1. Clone the Repository

git clone https://github.com/Sonseldeep/Walk.Api
cd Walk.Api

2. Configuration Database Connection

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=NZWalksDb;Trusted_Connection=true;MultipleActiveResultSets=true"
  }
}

3. Apply Database Migrations

dotnet ef database update

4. Run the Application

    dotnet run --project NZWalks.Api

API Endpoints

###Regions

GET /api/regions - Get all regions
GET /api/regions/{id} - Get region by ID
POST /api/regions - Create new region
PUT /api/regions/{id} - Update region
DELETE /api/regions/{id} - Delete region

Walks

GET /api/walks - Get all walks (supports filtering & sorting)
GET /api/walks/{id} - Get walk by ID
POST /api/walks - Create new walk
PUT /api/walks/{id} - Update walk
DELETE /api/walks/{id} - Delete walk

Query Parameters for Walks

filterOn=Name&filterQuery=searchterm - Filter by name
sortBy=Name&isAscending=true - Sort by name
sortBy=Length&isAscending=false - Sort by length

Install Dependencies & Run

dotnet restore

Install Required Packages

# Entity Framework Core packages
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.EntityFrameworkCore.Design

# ASP.NET Core packages
dotnet add package Microsoft.AspNetCore.OpenApi
dotnet add package Swashbuckle.AspNetCore

Set Up Database

# Create initial migration (if not exists)
dotnet ef migrations add InitialCreate

# Update database with migrations
dotnet ef database update

Run the Project

dotnet run --project NZWalks.Api

Clean and Rebuild

dotnet clean
dotner build
# Rub with specific environment
dotnet run --environment Development

# Watch for changes (hot reload)
dotnet watcg run --project NZWalks.Api

Testing

dotnet test

About

Controller based web api, pagination, filtering, sorting, authentication, authorization, versioning, image upload, logging

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages