Skip to content

Commit

Permalink
make it easier to run the app
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed Apr 27, 2024
1 parent 2a11b96 commit 83bb495
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .run/CleanAspCore.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="CleanAspCore" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/CleanAspCore/CleanAspCore.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="https" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand All @@ -11,7 +11,7 @@
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" default="false" projectName="CleanAspCore" projectPath="file://$PROJECT_DIR$/CleanAspCore/CleanAspCore.csproj" />
<option name="Build" default="false" projectName="CleanAspCore" projectPath="$PROJECT_DIR$/CleanAspCore/CleanAspCore.csproj" />
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Run db" run_configuration_type="docker-deploy" />
</method>
</configuration>
Expand Down
12 changes: 0 additions & 12 deletions .run/Run App.run.xml

This file was deleted.

2 changes: 1 addition & 1 deletion CleanAspCore/Data/HrContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public static void MigrateHrContext(this IHost host)
{
using var serviceScope = host.Services.GetRequiredService<IServiceScopeFactory>().CreateScope();
var context = serviceScope.ServiceProvider.GetRequiredService<HrContext>();
context.Database.Migrate();
context.Database.EnsureCreated();
}
}
3 changes: 2 additions & 1 deletion CleanAspCore/Features/Employees/DeleteEmployeeById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ internal static class DeleteEmployeeById
{
internal static async Task<Results<Ok, NotFound>> Handle(Guid id, HrContext context, CancellationToken cancellationToken)
{
var result = await context.Employees.Where(x => x.Id == id)
var result = await context.Employees
.Where(x => x.Id == id)
.ExecuteDeleteAsync(cancellationToken);

return result switch
Expand Down
5 changes: 4 additions & 1 deletion CleanAspCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(options =>
{
options.SupportNonNullableReferenceTypes();
});
builder.Services.AddAuthorization();
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
builder.Services.AddDbContext<HrContext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
Expand Down
26 changes: 0 additions & 26 deletions CleanAspCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:46824",
"sslPort": 44330
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5015",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
Expand All @@ -29,14 +11,6 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"CONNECTIONSTRINGS__DEFAULT": "User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=postgres;"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
12 changes: 9 additions & 3 deletions CleanAspCore/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ public static class EndpointRouteBuilderExtensions
{
public static void AddRoutes(this IEndpointRouteBuilder host)
{
var departmentGroup = host.MapGroup("/departments");
var departmentGroup = host
.MapGroup("/departments")
.WithTags("Departments");

departmentGroup.MapPost("/", AddDepartments.Handle)
.WithRequestValidation<CreateDepartmentRequest>();

departmentGroup.MapGet("/{id:guid}", GetDepartmentById.Handle)
.WithName(nameof(GetDepartmentById));

var employeeGroup = host.MapGroup("/employees");
var employeeGroup = host
.MapGroup("/employees")
.WithTags("Employees");

employeeGroup.MapPost("/", AddEmployee.Handle)
.WithRequestValidation<CreateEmployeeRequest>();
Expand All @@ -30,7 +34,9 @@ public static void AddRoutes(this IEndpointRouteBuilder host)
employeeGroup.MapPut("/{id:guid}", UpdateEmployeeById.Handle);


var jobGroup = host.MapGroup("/jobs");
var jobGroup = host
.MapGroup("/jobs")
.WithTags("Jobs");

jobGroup.MapPost("/",AddJobs.Handle)
.WithRequestValidation<CreateJobRequest>();
Expand Down
14 changes: 8 additions & 6 deletions CleanAspCore/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"DbConnectionString": "Host=127.0.0.1;Port=5432;Database=CleanAspCore;Username=postgres;Password=postgres;Include Error Detail=true"
}
26 changes: 0 additions & 26 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
version: '3'

networks:
kitchen-table-dev:
driver: bridge

services:
api:
image: api
depends_on:
- postgres
build:
context: .
volumes:
- ~/.aspnet/https:/https:ro
ports:
- "80:80"
- "443:443"
environment:
- CONNECTIONSTRINGS__DEFAULT=User ID=postgres;Password=postgres;Host=postgres;Port=5432;Database=postgres;
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_Kestrel__Certificates__Default__Password=password
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
networks:
- kitchen-table-dev

postgres:
image: postgres
container_name: "postgres"
Expand All @@ -34,5 +10,3 @@ services:
- POSTGRES_DB=postgres
ports:
- "5432:5432"
networks:
- kitchen-table-dev

0 comments on commit 83bb495

Please sign in to comment.