COVID19-PIRAT / backend

GNU General Public License v3.0
2 stars 1 forks source link

.NET Core

PIRAT Backend

This repository contains the backend service for https://pirat-tool.com.

Setup

Requirements

.Net Core Sdk 3.1

See https://dotnet.microsoft.com/download/dotnet-core/3.1 to get the SDK

Database

This program uses a PostgreSQL database. The database definition is in init.sql.

Compile

Use dotnet publish on the sln File

Example: dotnet publish Pirat.sln (this builds the executable Debug version)
Example: dotnet publish -c Release Pirat.sln (this builds the executable Release version)

Environment Variables

The following environment variables are available, most of them are required.

General

Email

API Keys

Example:

ASPNETCORE_URLS=http://127.0.0.1:5000
ASPNETCORE_ENVIRONMENT=development
PIRAT_ADMIN_KEY=i_am_admin
PIRAT_HOST=https://pirat-tool.com
PIRAT_CONNECTION="Server=localhost;Port=5432;Database=pirat;User ID=pirat;Password=secret_db_password"
PIRAT_SWAGGER_PREFIX_PATH=api/
PIRAT_WEBAPP_ENVIRONMENT=production

PIRAT_SENDER_MAIL_ADDRESS=mail@pirat-tool.com
PIRAT_SENDER_MAIL_USERNAME=mail@pirat-tool.com
PIRAT_SENDER_MAIL_PASSWORD=secret_password
PIRAT_SENDER_MAIL_SMTP_HOST=smpt.pirat-tool.com
PIRAT_INTERNAL_RECEIVER_MAIL=mail@pirat-tool.com

PIRAT_GOOGLE_API_KEY=KKKKEEEEYYYYY
PIRAT_GOOGLE_RECAPTCHA_SECRET=SSSSEEECCCRRREEEEEETTTTTTT

Run

If you want to specify the runtime platform use -r. To have a self-contained executable use --self-contained true

Examples :

dotnet publish -c Release -r linux-x64 --self-contained true Pirat.sln
dotnet publish -c Release -r osx-x64 --self-contained true Pirat.sln
dotnet publish -c Release -r win-x64 --self-contained true Pirat.sln

The backend will listen on localhost:5000.

Documentation

Swagger is used to document the API. If started in the development mode, the Swagger UI is available at /{PIRAT_SWAGGER_PREFIX_PATH}swagger.

Contributing

Please read https://github.com/COVID19-PIRAT/frontend/blob/develop/README.md#contributing

Use Feature Branches for the development and open a pull request.

Code quality: To improve the quality we use the analyzer tools FxCop and Puma. If you make a pull request try to fix all warnings. To enable both anaylzers in order to check your code locally you might have to change settings in your IDE. For Visual Studio check that full solution analysis is allowed: Optionen/Options -> Text-Editor/Text Editor -> C# -> Erweitert/Advanced -> Bereich für Hintegrundanalyse/Background analysis scope -> Gesamte Projektmappe/Entire solution must be ticked.

Executing Tests

Currently we have three Test projects: Pirat.Tests, Pirat.DatabaseTests, Pirat.IntegrationTests

If you want to execute the tests locally make sure you have a fresh build of Pirat and the Test projects. You can build them in your IDE or via console using the command "dotnet build" in the main directory.

Executing Pirat.Tests: This project contains Unit Tests. Run them in your IDE or via console using the command "dotnet test Pirat.Tests/".

Executing Pirat.DatabaseTests: This project contains Tests that need access to a database. Before starting the including tests you need first to start the postgres container. Do this by using the command "(sudo) docker-compose -f test-database_docker-compose.yml up" in your console. Now a local postgres container runs on port 5432 and you can run the tests in your IDE or via the console with the command "dotnet test Pirat.DatabaseTests/".

Executing Pirat.IntegrationTests: Documentation will come - no Integration Tests to far.