Skip to content

Commit 7c90dfb

Browse files
authored
Merge pull request #10 from honamic/ComandResult
new project Applications.Abstractions for results
2 parents 46dbc3d + 9f84c2c commit 7c90dfb

File tree

65 files changed

+324
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+324
-108
lines changed

Honamic.Framework.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03.Facade", "03.Facade", "{
129129
EndProject
130130
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Honamic.IdentityPlus.Facade", "src\IdentityPlus\Facade\Honamic.IdentityPlus.Facade.csproj", "{D7D9D8C5-EBDF-480C-A693-E6ED04143FFA}"
131131
EndProject
132+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Honamic.Framework.Applications.Abstractions", "src\Core\Applications.Abstractions\Honamic.Framework.Applications.Abstractions.csproj", "{29C37841-0CA2-9A52-9A08-90CA63C5E63A}"
133+
EndProject
132134
Global
133135
GlobalSection(SolutionConfigurationPlatforms) = preSolution
134136
Debug|Any CPU = Debug|Any CPU
@@ -299,6 +301,10 @@ Global
299301
{D7D9D8C5-EBDF-480C-A693-E6ED04143FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
300302
{D7D9D8C5-EBDF-480C-A693-E6ED04143FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
301303
{D7D9D8C5-EBDF-480C-A693-E6ED04143FFA}.Release|Any CPU.Build.0 = Release|Any CPU
304+
{29C37841-0CA2-9A52-9A08-90CA63C5E63A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
305+
{29C37841-0CA2-9A52-9A08-90CA63C5E63A}.Debug|Any CPU.Build.0 = Debug|Any CPU
306+
{29C37841-0CA2-9A52-9A08-90CA63C5E63A}.Release|Any CPU.ActiveCfg = Release|Any CPU
307+
{29C37841-0CA2-9A52-9A08-90CA63C5E63A}.Release|Any CPU.Build.0 = Release|Any CPU
302308
EndGlobalSection
303309
GlobalSection(SolutionProperties) = preSolution
304310
HideSolutionNode = FALSE
@@ -365,6 +371,7 @@ Global
365371
{8F5EAEEB-467C-412D-B131-D7469C70D375} = {3F098285-E155-4D9A-9371-E7C4CAEA17F3}
366372
{82C3E682-28F0-4F65-93F1-A646085A9198} = {7ACD81EB-9F97-44A5-B91B-2E12C5F45607}
367373
{D7D9D8C5-EBDF-480C-A693-E6ED04143FFA} = {82C3E682-28F0-4F65-93F1-A646085A9198}
374+
{29C37841-0CA2-9A52-9A08-90CA63C5E63A} = {BC728FCA-02C3-4522-A7EB-7403B8674BBA}
368375
EndGlobalSection
369376
GlobalSection(ExtensibilityGlobals) = postSolution
370377
SolutionGuid = {E15D83FC-8F5C-4D9C-9DCD-D114F5609922}

TodoSample/Core/Application.Contracts/Honamic.Todo.Application.Contracts.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<ItemGroup>
1212

13+
<ProjectReference Include="..\..\..\src\Core\Applications.Abstractions\Honamic.Framework.Applications.Abstractions.csproj" />
14+
1315
<ProjectReference Include="..\..\..\src\Core\Commands.Abstractions\Honamic.Framework.Commands.Abstractions.csproj" />
1416
</ItemGroup>
1517

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11

2+
using Honamic.Framework.Applications.Results;
23
using Honamic.Framework.Commands;
34

45
namespace Honamic.Todo.Application.TodoItems.Commands;
56
public record CreateTodoItemCommand(string title, string content, List<string> tags) : ICommand;
7+
8+
9+
10+
11+
public record CreateTodoItem2Command(string title, string content, List<string> tags)
12+
: ICommand<Result<CreateTodoItem2ResultCommand>>;
13+
14+
15+
16+
public class CreateTodoItem2ResultCommand
17+
{
18+
public long Id { get; set; }
19+
}

TodoSample/Core/Application/Extensions/ApplicationServiceCollectionExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Honamic.Framework.Tools.IdGenerators;
88
using Honamic.Todo.Application.TodoItems.EventHandlers;
99
using Honamic.IdentityPlus.Domain.Users;
10+
using Honamic.Framework.Applications.Results;
1011

1112
namespace Honamic.Todo.Application.Extensions;
1213

@@ -25,6 +26,11 @@ private static void AddCommandHandlers(this IServiceCollection services)
2526
{
2627
services.AddCommandHandler<DeleteTodoItemCommand, DeleteTodoItemCommandHandler>();
2728
services.AddCommandHandler<CreateTodoItemCommand, CreateTodoItemCommandHandler>();
29+
services.AddCommandHandler<
30+
CreateTodoItem2Command,
31+
CreateTodoItem2CommandHandler,
32+
Result<CreateTodoItem2ResultCommand>>();
33+
2834
services.AddCommandHandler<MakeCompletedTodoItemCommand, MakeCompletedTodoItemCommandHandler>();
2935
}
3036

TodoSample/Core/Application/Honamic.Todo.Application.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
1312
</ItemGroup>
1413

1514
<ItemGroup>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Honamic.Framework.Applications.Results;
2+
using Honamic.Framework.Commands;
3+
using Honamic.Framework.Domain;
4+
using Honamic.Todo.Application.TodoItems.Commands;
5+
using Honamic.Todo.Domain.TodoItems;
6+
7+
namespace Honamic.Todo.Application.TodoItems.CommandHandlers;
8+
internal class CreateTodoItem2CommandHandler :
9+
ICommandHandler<CreateTodoItem2Command, Result<CreateTodoItem2ResultCommand>>
10+
{
11+
private readonly ITodoItemRepository _todoItemRepository;
12+
private readonly IIdGenerator _idGenerator;
13+
14+
public CreateTodoItem2CommandHandler(ITodoItemRepository todoItemRepository, IIdGenerator idGenerator)
15+
{
16+
_todoItemRepository = todoItemRepository;
17+
_idGenerator = idGenerator;
18+
}
19+
20+
public async Task<Result<CreateTodoItem2ResultCommand>> HandleAsync(CreateTodoItem2Command command, CancellationToken cancellationToken)
21+
{
22+
var todoItem = new TodoItem(_idGenerator.GetNewId(), command.title, command.content, command.tags);
23+
await _todoItemRepository.InsertAsync(todoItem);
24+
25+
var result = new CreateTodoItem2ResultCommand
26+
{
27+
Id = todoItem.Id
28+
};
29+
30+
return result;
31+
}
32+
33+
}

TodoSample/Core/Domain/Honamic.Todo.Domain.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

TodoSample/Endpoints/WebApi/Honamic.Todo.Endpoints.WebApi/Honamic.Todo.Endpoints.WebApi.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.16">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
</PackageReference>
18-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
19-
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.0" />
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.1" />
19+
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.3" />
2020
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.1" />
2121
<PackageReference Include="MudBlazor" Version="6.15.0" />
2222
</ItemGroup>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Honamic.Framework.Applications.Results;
2+
using Honamic.Framework.Commands;
3+
using Honamic.Todo.Application.TodoItems.Commands;
4+
using Microsoft.AspNetCore.Mvc;
5+
6+
namespace Honamic.Todo.Endpoints.WebApi.Controllers;
7+
8+
[Route("api/[controller]")]
9+
[ApiController]
10+
public class TodoItems2Controller : ControllerBase
11+
{
12+
private readonly ILogger<TodoItemsController> _logger;
13+
private readonly ICommandBus _commandBus;
14+
15+
public TodoItems2Controller(ILogger<TodoItemsController> logger, ICommandBus commandBus)
16+
{
17+
_logger = logger;
18+
_commandBus = commandBus;
19+
}
20+
21+
[HttpPost]
22+
public async Task<Result<CreateTodoItem2ResultCommand>> Post([FromBody] CreateTodoItem2Command model, CancellationToken cancellationToken)
23+
{
24+
return await _commandBus
25+
.DispatchAsync<CreateTodoItem2Command, Result<CreateTodoItem2ResultCommand>>
26+
(model, cancellationToken);
27+
}
28+
29+
30+
}

TodoSample/Endpoints/WebApi/Honamic.Todo.Endpoints.WebApi/TodoItems/TodoItemsController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Honamic.Framework.Facade.Results;
1+
using Honamic.Framework.Applications.Results;
22
using Honamic.Framework.Queries;
33
using Honamic.Todo.Application.TodoItems.Commands;
44
using Honamic.Todo.Facade.TodoItems;
@@ -37,6 +37,12 @@ public Task<Result<TodoItemQuery>> Get(long id, CancellationToken cancellationTo
3737

3838
}
3939

40+
[HttpPost("Create")]
41+
public Task<Result<long>> Create([FromBody] CreateTodoItemCommand model, CancellationToken cancellationToken)
42+
{
43+
return _todoItemFacade.Create(model, cancellationToken);
44+
}
45+
4046
[HttpPost]
4147
public Task<Result<long>> Post([FromBody] CreateTodoItemCommand model, CancellationToken cancellationToken)
4248
{

0 commit comments

Comments
 (0)