Various work around the architecture

This commit is contained in:
Janus C. H. Knudsen 2025-03-03 00:42:20 +01:00
parent b1e134490d
commit 71576a4b1f
18 changed files with 522 additions and 358 deletions

View file

@ -0,0 +1,7 @@
namespace PlanTempus.Components
{
public class Class1
{
}
}

View file

@ -0,0 +1,9 @@
namespace PlanTempus.Components.Organizations.Create
{
public class CreateOrganizationCommand
{
public string Name { get; set; }
public string Description { get; set; }
public Guid CreatedById { get; set; }
}
}

View file

@ -0,0 +1,52 @@
using Insight.Database;
namespace PlanTempus.Components.Organizations.Create
{
public class CreateOrganizationHandler
{
private readonly IDatabaseOperations _databaseOperations;
public CreateOrganizationHandler(IDatabaseOperations databaseOperations)
{
_databaseOperations = databaseOperations;
}
public async Task<CreateOrganizationResponse> Handle(CreateOrganizationCommand command)
{
using var db = _databaseOperations.CreateScope(nameof(CreateOrganizationHandler));
try
{
var organizationId = Guid.NewGuid();
var now = DateTime.UtcNow;
var sql = @"
INSERT INTO Organizations (Id, Name, Description, CreatedById, CreatedAt, UpdatedAt)
VALUES (@Id, @Name, @Description, @CreatedById, @CreatedAt, @UpdatedAt)";
await db.Connection.ExecuteSqlAsync(sql, new
{
Id = organizationId,
command.Name,
command.Description,
CreatedById = command.CreatedById,
CreatedAt = now,
UpdatedAt = now
});
db.Success();
return new CreateOrganizationResponse
{
Id = organizationId,
Name = command.Name,
CreatedAt = now
};
}
catch (Exception ex)
{
db.Error(ex);
throw;
}
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlanTempus.Components.Organizations.Create
{
public class CreateOrganizationResponse
{
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}
}

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Core\PlanTempus.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Organizations\Delete\" />
<Folder Include="Organizations\Update\" />
</ItemGroup>
</Project>