mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Defines base implementation for mediatr and fluentvalidation with samples
This commit is contained in:
1 parent
76db0c1597
commit
9a5c7473f9
33 files changed
+1123
-131
No files matched your search
+8
-8
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -19,15 +19,15 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.AddRo
|
||||
/// </summary>
|
||||
public class AddRoleEndpoint : BaseEndpoint<AddRoleRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
private readonly ICommandHandler<AddRoleCommand, ErrorOr<RolePermissionsResponse>> _addRoleCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public AddRoleEndpoint(ISender sender)
|
||||
/// <param name="addRoleCommandHandler">Injected service for handling add role commands.</param>
|
||||
public AddRoleEndpoint(ICommandHandler<AddRoleCommand, ErrorOr<RolePermissionsResponse>> addRoleCommandHandler)
|
||||
{
|
||||
_sender = sender;
|
||||
_addRoleCommandHandler = addRoleCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +35,7 @@ public class AddRoleEndpoint : BaseEndpoint<AddRoleRequest, IResult>
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.POST);
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Roles.CREATE_ROLE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
@@ -48,7 +48,7 @@ public class AddRoleEndpoint : BaseEndpoint<AddRoleRequest, IResult>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddRoleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RolePermissionsResponse> result = await _sender.Send(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<RolePermissionsResponse> result = await _addRoleCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -19,15 +19,15 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRo
|
||||
/// </summary>
|
||||
public class GetRolePermissionsEndpoint : BaseEndpoint<GetRolePermissionsRequest, IResult>
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
private readonly IQueryHandler<GetRolePermissionsQuery, ErrorOr<RolePermissionsResponse>> _addRoleQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolePermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="sender">Injected service for mediating commands and queries.</param>
|
||||
public GetRolePermissionsEndpoint(ISender sender)
|
||||
/// <param name="addRoleQueryHandler">Injected service for handling add role commands.</param>
|
||||
public GetRolePermissionsEndpoint(IQueryHandler<GetRolePermissionsQuery, ErrorOr<RolePermissionsResponse>> addRoleQueryHandler)
|
||||
{
|
||||
_sender = sender;
|
||||
_addRoleQueryHandler = addRoleQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +35,7 @@ public class GetRolePermissionsEndpoint : BaseEndpoint<GetRolePermissionsRequest
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.Roles.GET_ROLE_PERMISSIONS_BY_ROLE_ID);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
@@ -48,7 +48,7 @@ public class GetRolePermissionsEndpoint : BaseEndpoint<GetRolePermissionsRequest
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetRolePermissionsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<RolePermissionsResponse> result = await _sender.Send(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
ErrorOr<RolePermissionsResponse> result = await _addRoleQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -13,7 +13,10 @@
|
||||
<DockerfileTag>lumina-api</DockerfileTag>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in new issue
Block a user