diff --git a/.template.config/template.json b/.template.config/template.json index 35a616e..f16794f 100644 --- a/.template.config/template.json +++ b/.template.config/template.json @@ -1,7 +1,12 @@ { "$schema": "http://json.schemastore.org/template", "author": "Enis Mulic", - "classifications": ["Api", "Minimal Api", "Vertical Slice Architecture", "CQRS"], + "classifications": [ + "Api", + "Minimal Api", + "Vertical Slice Architecture", + "CQRS" + ], "identity": "VerticalSliceMinimalApi", "name": "Vertical Slice Minimal Api", "shortName": "vsma", @@ -48,7 +53,7 @@ "datatype": "choice", "choices": [ { - "choice": "MSSql", + "choice": "MsSql", "description": "Use Microsoft SQL or Azure SQL" }, { @@ -63,9 +68,9 @@ "defaultValue": "None", "description": "The type of database to use" }, - "UseMSSql": { + "UseMsSql": { "type": "computed", - "value": "(Database == \"MSSql\")" + "value": "(Database == \"MsSql\")" }, "UsePostgreSql": { "type": "computed", @@ -96,8 +101,31 @@ { "condition": "(!UseDatabase)", "exclude": [ - "src/Application/Infrastructure/Persistance/**" + "src/Application/Infrastructure/Persistance/**", + "appsettings.*.json" ] + }, + { + "condition": "(UseMsSql)", + "exclude": [ + "src/Api/appsettings.PostgreSql.json", + "docker-compose.postgresql.yml" + ], + "rename": { + "appsettings.MsSql.json": "appsettings.Development.json", + "docker-compose.mssql.yml": "docker-compose.yml" + } + }, + { + "condition": "(UsePostgreSql)", + "exclude": [ + "src/Api/appsettings.MsSql.json", + "docker-compose.mssql.yml" + ], + "rename": { + "appsettings.PostgreSql.json": "appsettings.Development.json", + "docker-compose.postgresql.yml": "docker-compose.yml" + } } ] } diff --git a/README.md b/README.md index f67d31e..fa29e46 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build](https://github.com/EnisMulic/VerticalSliceMinimalApi/actions/workflows/ci.yml/badge.svg)](https://github.com/EnisMulic/VerticalSliceMinimalApi/actions/workflows/ci.yml) -## Getting Started +## Getting Started 1. Clone the repository @@ -19,10 +19,11 @@ dotnet new install ./VerticalSliceMinimalApi 3. Use the installed template to create your API ```sh -dotnet new vsma --name ProjectName +dotnet new vsma --name ProjectName ``` ## Synopsis + ``` dotnet new vsma --name [ProjectName] [-gh|--git-host [Github|AzureDevOps|None]] @@ -31,17 +32,18 @@ dotnet new vsma --name [ProjectName] ### Options -* `--name [ProjectName]` +- `--name [ProjectName]` Specify the name of the project you are creating, this will replace all occurrences of `ProjectName` in the template with the name you pass in. -* `-gh|--git-host [Github|AzureDevOps|None]` +- `-gh|--git-host [Github|AzureDevOps|None]` Choose the platform you will host your projects git repository, this will give you a base CI workflow, pull request template, and anything specific to the platform that might be of use. The default value is `None`. -* `-db|--database [MsSql|PostgreSql|None]` +- `-db|--database [MsSql|PostgreSql|None]` Choose what database to use for your project. The default is `None` ## How to Run To start the app run: + ```sh dotnet run --project src/Api ``` diff --git a/docker-compose.yml b/docker-compose.mssql.yml similarity index 100% rename from docker-compose.yml rename to docker-compose.mssql.yml diff --git a/docker-compose.postgresql.yml b/docker-compose.postgresql.yml new file mode 100644 index 0000000..b935d98 --- /dev/null +++ b/docker-compose.postgresql.yml @@ -0,0 +1,10 @@ +services: + postgres: + image: postgres:14-alpine + restart: unless-stopped + ports: + - 5432:5432 + environment: + - POSTGRES_PASSWORD=QWElkj132! + - POSTGRES_USER=todos_user + - POSTGRES_DB=todos_db diff --git a/src/Api/appsettings.Development.json b/src/Api/appsettings.MSSql.json similarity index 75% rename from src/Api/appsettings.Development.json rename to src/Api/appsettings.MSSql.json index 9851083..0928f5b 100644 --- a/src/Api/appsettings.Development.json +++ b/src/Api/appsettings.MSSql.json @@ -1,6 +1,6 @@ -{ +{ "ConnectionStrings": { - "Default": "Server=.;Database=TodoDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True" + "Default": "Server=.;Database=TodoDatabase;MultipleActiveResultSets=true;TrustServerCertificate=True;User Id=sa;Password=QWElkj132!" }, "Logging": { "LogLevel": { @@ -21,4 +21,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/Api/appsettings.PostgreSql.json b/src/Api/appsettings.PostgreSql.json new file mode 100644 index 0000000..8729e10 --- /dev/null +++ b/src/Api/appsettings.PostgreSql.json @@ -0,0 +1,24 @@ +{ + "ConnectionStrings": { + "Default": "Host=localhost;Port=5432;Database=todos_db;Integrated Security=true;Pooling=true;Username=todos_user;Password=QWElkj132!" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "Authentication": { + "Schemes": { + "Bearer": { + "ValidAudiences": [ + "http://localhost:44986", + "https://localhost:44337", + "http://localhost:5191", + "https://localhost:7079" + ], + "ValidIssuer": "dotnet-user-jwts" + } + } + } +} diff --git a/src/Api/appsettings.json b/src/Api/appsettings.json index 1b4ba7d..5bead84 100644 --- a/src/Api/appsettings.json +++ b/src/Api/appsettings.json @@ -10,8 +10,5 @@ } } }, - "AllowedHosts": "*", - "ConnectionStrings": { - "Default": "Server=.;Database=TodoDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True" - } + "AllowedHosts": "*" } diff --git a/src/Application/Infrastructure/ConfigureServices.cs b/src/Application/Infrastructure/ConfigureServices.cs index 71262b1..25fb214 100644 --- a/src/Application/Infrastructure/ConfigureServices.cs +++ b/src/Application/Infrastructure/ConfigureServices.cs @@ -29,7 +29,7 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti { options.AddInterceptors(sp.GetServices()); -#if UseMSSql +#if UseMsSql options.UseSqlServer(configuration.GetConnectionString("Default"), builder => builder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)); #elif UsePostgreSql