Skip to content

Simple Auction API : Implementation of different types of auctions

License

Notifications You must be signed in to change notification settings

wallymathieu/auctions-api-csharp

Repository files navigation

auctions-api-simple

Simple Auction API

There are currently these main implementations:

Getting started

First copy .env sample to a new .env file

cp .env.sample .env

Then do change the password.

To start the database run:

docker compose up -d db

To start azurite run:

docker compose up -d azurite

To start redis run:

docker compose up -d redis

To build the app run:

cd src/Auctions.WebApi
dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer

To run api/func/migrations locally you need the following env:

source .env
export ConnectionStrings__DefaultConnection="Server=localhost;Database=master;TrustServerCertificate=true;MultipleActiveResultSets=true;User Id=sa;Password=${SA_PASSWORD}"
export ConnectionStrings__Redis="localhost"
export ConnectionStrings__AzureStorage="UseDevelopmentStorage=true"

export AzureWebJobsStorage="UseDevelopmentStorage=true"

If you want to run inside dev containers then the setup will be slightly different (since it should be the same environment as you have if you the apps through docker compose):

. .devcontainer/env.sh

To run migrations and api using above environment:

dotnet tool restore
cd src/Auctions.WebApi
dotnet ef database update
dotnet run

In the frontend app you need to specify the frontend db context

cd src/Auctions.Frontend
dotnet ef database update --context Wallymathieu.Auctions.Frontend.Data.FrontendDbContext

To run Azure Functions locally using above environment:

cd src/Auctions.AzureFunctions
func start

Auth

The API assumes that you have auth middleware in front of the app.

Either the decoded JWT in the x-jwt-payload header or specify an encoded claims principal by using configuration value in PrincipalHeader, such as x-ms-client-principal.

Add migration

dotnet ef migrations add NewMigration --project ./src/Auctions.Infrastructure/Auctions.Infrastructure.csproj --startup-project ./src/Auctions.WebApi/Auctions.WebApi.csproj

Inspiration

The main inspiration for the architecture of the API is found in this book:

Note that there are many variants of "the clean architecture" described in the .net space with different interpretations of what it means to implement this architecture.