Skip to content

SaraRasoulian/DotNet-WebAPI-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

66 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Web API Application

This repository is a sample ASP.NET Core Web API (.NET 8) project.

Avaliable endpoints

The endpoints can be tested using postman or swagger.

Login
Post    http://localhost:5000/api/identity/login
Input from body:
Content-Type: application/json
{
  "userName": "sara",
  "password": "123456"
}
Get User
Needs authorization
GET    http://localhost:5000/api/users/{userId}
Earn Points
Needs authorization
Post    http://localhost:5000/api/users/{userId}/earn
Input from body:
Content-Type: application/json
{
  "points": 100
}

Tech Stack

  • ASP.NET Core Web API -v8
  • Entity Framework Core -v8
  • TDD (Test-Driven Development)
  • DDD (Domain-Driven Design)
  • Clean Architecture
  • Clean Code
  • Repository Design Pattern
  • CQRS Design Pattern
  • Mediator Design pattern
  • JWT (JSON Web Token)
  • PostgreSQL Database
  • Redis for Caching
  • Docker
Nuget Packages

Here are some of the NuGet packages used in this repository:

  • xUnit for unit and integration testing
  • Testcontainers for integration testing
  • Moq for mocking
  • Serilog for logging in console and text file
  • FluentValidation for server-side validation
  • FluentAssertions for test assertions
  • MediatR for implementing mediator pattern
  • Mapster for object mapping
  • Newtosoft.Json for serializing and deserializing objects
  • Microsoft.Extensions.Caching.StackExchangeRedis for implementing redis cache

Get started

1. Clone the repository

git clone https://github.com/SaraRasoulian/Loyalty-System-API.git

2. Start with Docker compose

Make sure docker is installed on your machine.

Run the following command in project directory:

docker-compose up -d

Docker compose in this project includes 4 services:

  • Web API application will be listening at http://localhost:5000

  • Postgres database will be listening at http://localhost:5433

  • PgAdmin4 web interface will be listening at http://localhost:8080

  • Redis cache will be listening at http://localhost:6379

To apply your modified code, you can add build option:

  docker-compose up -d --build

To stop and remove all containers, use the following command:

  docker-compose down

3. Run the migrations

Open CustomerLoyalty.sln file in visual studio, then in package manager console tab, run:

update-database

This command will generate the database schema in postgres container.


Make sure Docker engine is running, before running the integration tests.