Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sararasoulian/dotnet-webapi-sample

👑 A Sample Web API Application
https://github.com/sararasoulian/dotnet-webapi-sample

authentication clean-architecture clean-code cqrs-pattern docker entity-framework-core integration-testing postgresql-database redis-cache restful-api serilog tdd unit-testing

Last synced: about 13 hours ago
JSON representation

👑 A Sample Web API Application

Awesome Lists containing this project

README

        

## 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](https://docs.docker.com/get-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.