Compare commits
11 Commits
f3784d24bd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 307c81001a | |||
| 9c5346213e | |||
| 6542d804f8 | |||
| f470367d89 | |||
| 6ec2187361 | |||
| 8c6102d161 | |||
| 3c3744c0ce | |||
| 46da385b92 | |||
| 210c1f414c | |||
| ca3772e2a8 | |||
| a01e61aafe |
@@ -0,0 +1,8 @@
|
|||||||
|
using DigitalData.TaskFlow.Domain.ProcedureResults;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
public interface IUserRepository : IRepository
|
||||||
|
{
|
||||||
|
Task<IEnumerable<AuthorizedUser>> GetAuthorizedAsync(CancellationToken cancellationToken);
|
||||||
|
}
|
||||||
@@ -14,4 +14,24 @@ public interface IWorkflowRepository : IRepository
|
|||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
/// <returns>Workflow data grouped by source.</returns>
|
/// <returns>Workflow data grouped by source.</returns>
|
||||||
Task<Workflow?> GetByWisagIdAsync(int wisagId, CancellationToken cancellationToken);
|
Task<Workflow?> GetByWisagIdAsync(int wisagId, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes a workflow item and returns procedure result code/message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">Internal user identifier expected by the procedure.</param>
|
||||||
|
/// <param name="source">Source system identifier.</param>
|
||||||
|
/// <param name="processId">Process identifier.</param>
|
||||||
|
/// <param name="closingMethodId">Closing method identifier.</param>
|
||||||
|
/// <param name="comment">Optional comment.</param>
|
||||||
|
/// <param name="rejectionReasonId">Optional rejection reason identifier.</param>
|
||||||
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
|
/// <returns>Close operation result.</returns>
|
||||||
|
Task<WorkflowClosing?> CloseAsync(
|
||||||
|
int userId,
|
||||||
|
string source,
|
||||||
|
long processId,
|
||||||
|
int closingMethodId,
|
||||||
|
string? comment,
|
||||||
|
byte? rejectionReasonId,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.Application.Features.Users.Queries;
|
||||||
|
|
||||||
|
public sealed record GetAuthorizedUsersQuery : IRequest<GetAuthorizedUsersResult>;
|
||||||
|
|
||||||
|
public sealed record GetAuthorizedUsersResult(IEnumerable<GetAuthorizedUsersMeta> Meta, IEnumerable<int> Wisagids);
|
||||||
|
|
||||||
|
public sealed record GetAuthorizedUsersMeta(int? Code, string Message);
|
||||||
|
|
||||||
|
public sealed class GetAuthorizedUsersQueryHandler(IUserRepository repo) : IRequestHandler<GetAuthorizedUsersQuery, GetAuthorizedUsersResult>
|
||||||
|
{
|
||||||
|
public async Task<GetAuthorizedUsersResult> Handle(GetAuthorizedUsersQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var users = await repo.GetAuthorizedAsync(cancellationToken);
|
||||||
|
|
||||||
|
return new GetAuthorizedUsersResult(
|
||||||
|
Meta: [new GetAuthorizedUsersMeta(Code: 0, Message: "OK")],
|
||||||
|
Wisagids: users.Select(x => x.WisagId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.Application.Features.Workflows.Commands;
|
||||||
|
|
||||||
|
public sealed record CloseWorkflowCommand(
|
||||||
|
int WisagId,
|
||||||
|
string Source,
|
||||||
|
long ProcessId,
|
||||||
|
int ClosingMethodId,
|
||||||
|
string? Comment,
|
||||||
|
byte? RejectionReasonId) : IRequest<CloseWorkflowResult>;
|
||||||
|
|
||||||
|
public sealed record CloseWorkflowResult(
|
||||||
|
int? Code,
|
||||||
|
string Message);
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||||
|
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.Application.Features.Workflows.Commands;
|
||||||
|
|
||||||
|
public sealed class CloseWorkflowCommandHandler(IWorkflowRepository Repo) : IRequestHandler<CloseWorkflowCommand, CloseWorkflowResult>
|
||||||
|
{
|
||||||
|
public async Task<CloseWorkflowResult> Handle(CloseWorkflowCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var procedureResult = await Repo.CloseAsync(
|
||||||
|
userId: request.WisagId,
|
||||||
|
source: request.Source,
|
||||||
|
processId: request.ProcessId,
|
||||||
|
closingMethodId: request.ClosingMethodId,
|
||||||
|
comment: request.Comment,
|
||||||
|
rejectionReasonId: request.RejectionReasonId,
|
||||||
|
cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
return procedureResult is null
|
||||||
|
? throw new InvalidWorkflowPayloadException("Close workflow closing procedure returned no result.")
|
||||||
|
: new CloseWorkflowResult(
|
||||||
|
Code: procedureResult.Code,
|
||||||
|
Message: procedureResult.Result ?? string.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace DigitalData.TaskFlow.Domain.ProcedureResults;
|
||||||
|
|
||||||
|
public class AuthorizedUser
|
||||||
|
{
|
||||||
|
public int WisagId { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
namespace DigitalData.TaskFlow.Domain.ProcedureResults;
|
||||||
|
|
||||||
|
public sealed class WorkflowClosing : ProcedureResultBase
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
services.AddScoped<IWorkflowRepository, WorkflowRepository>();
|
services.AddScoped<IWorkflowRepository, WorkflowRepository>();
|
||||||
services.AddScoped<IDocumentRepository, DocumentRepository>();
|
services.AddScoped<IDocumentRepository, DocumentRepository>();
|
||||||
|
services.AddScoped<IUserRepository, UserRepository>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,16 @@ public sealed class TaskFlowDbContext(DbContextOptions<TaskFlowDbContext> option
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DbSet<Document> Documents => Set<Document>();
|
public DbSet<Document> Documents => Set<Document>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the keyless result model used for workflow close procedure results.
|
||||||
|
/// </summary>
|
||||||
|
public DbSet<WorkflowClosing> WorkflowClosings => Set<WorkflowClosing>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the keyless result model used for authorized users procedure results.
|
||||||
|
/// </summary>
|
||||||
|
public DbSet<AuthorizedUser> AuthorizedUsers => Set<AuthorizedUser>();
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
@@ -37,5 +47,20 @@ public sealed class TaskFlowDbContext(DbContextOptions<TaskFlowDbContext> option
|
|||||||
entity.Property(x => x.Code).HasColumnName("CODE").HasColumnType("int");
|
entity.Property(x => x.Code).HasColumnName("CODE").HasColumnType("int");
|
||||||
entity.Property(x => x.Result).HasColumnName("RESULT").HasColumnType("nvarchar(max)");
|
entity.Property(x => x.Result).HasColumnName("RESULT").HasColumnType("nvarchar(max)");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<WorkflowClosing>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasNoKey();
|
||||||
|
entity.ToView(null);
|
||||||
|
entity.Property(x => x.Code).HasColumnName("CODE").HasColumnType("int");
|
||||||
|
entity.Property(x => x.Result).HasColumnName("RESULT").HasColumnType("nvarchar(400)");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<AuthorizedUser>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasNoKey();
|
||||||
|
entity.ToView(null);
|
||||||
|
entity.Property(x => x.WisagId).HasColumnName("wisagid").HasColumnType("int");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using DigitalData.TaskFlow.Application.Common.Interfaces;
|
||||||
|
using DigitalData.TaskFlow.Domain.ProcedureResults;
|
||||||
|
using DigitalData.TaskFlow.Infrastructure.Persistence;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.Infrastructure.Repositories;
|
||||||
|
|
||||||
|
public sealed class UserRepository(TaskFlowDbContext context) : IUserRepository
|
||||||
|
{
|
||||||
|
public async Task<IEnumerable<AuthorizedUser>> GetAuthorizedAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return await context.AuthorizedUsers
|
||||||
|
.FromSqlInterpolated($"EXEC [dbo].[PRCUST_F19_GET_AUTHORIZED_USERS]")
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,4 +19,35 @@ public sealed class WorkflowRepository(TaskFlowDbContext context) : IWorkflowRep
|
|||||||
|
|
||||||
return rows.FirstOrDefault();
|
return rows.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<WorkflowClosing?> CloseAsync(
|
||||||
|
int userId,
|
||||||
|
string source,
|
||||||
|
long processId,
|
||||||
|
int closingMethodId,
|
||||||
|
string? comment,
|
||||||
|
byte? rejectionReasonId,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var rows = await context.WorkflowClosings
|
||||||
|
.FromSqlInterpolated($@"
|
||||||
|
DECLARE @ResultCode INT;
|
||||||
|
DECLARE @ResultMessage NVARCHAR(400);
|
||||||
|
|
||||||
|
EXEC dbo.PRCUST_F19_CLOSING
|
||||||
|
@UserID = {userId},
|
||||||
|
@Source = {source},
|
||||||
|
@ProcessID = {processId},
|
||||||
|
@ClosingMethodID = {closingMethodId},
|
||||||
|
@Comment = {comment},
|
||||||
|
@RejectionReasonID = {rejectionReasonId},
|
||||||
|
@ResultCode = @ResultCode OUTPUT,
|
||||||
|
@ResultMessage = @ResultMessage OUTPUT;
|
||||||
|
|
||||||
|
SELECT @ResultCode AS CODE, @ResultMessage AS RESULT;")
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return rows.FirstOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using DigitalData.TaskFlow.Application.Features.Users.Queries;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.API.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/users")]
|
||||||
|
public sealed class UsersController(ISender sender) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("authorized")]
|
||||||
|
[ProducesResponseType(typeof(GetAuthorizedUsersResult), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(GetAuthorizedUsersResult), StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(typeof(GetAuthorizedUsersResult), StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<IActionResult> GetAuthorizedAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await sender.Send(new GetAuthorizedUsersQuery(), cancellationToken);
|
||||||
|
var code = result.Meta.FirstOrDefault()?.Code;
|
||||||
|
|
||||||
|
return code switch
|
||||||
|
{
|
||||||
|
0 => Ok(result),
|
||||||
|
4 => Unauthorized(result),
|
||||||
|
_ => StatusCode(StatusCodes.Status500InternalServerError, result)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using DigitalData.TaskFlow.API.Models;
|
||||||
|
using DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||||
|
using DigitalData.TaskFlow.Application.Features.Workflows.Commands;
|
||||||
using DigitalData.TaskFlow.Application.Features.Workflows.Queries;
|
using DigitalData.TaskFlow.Application.Features.Workflows.Queries;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -29,18 +32,45 @@ public sealed class WorkflowsController(ISender sender) : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Closes a workflow for a WISAG user identifier, source, and process identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="wisagId"></param>
|
/// <param name="wisagId"></param>
|
||||||
/// <param name="source"></param>
|
|
||||||
/// <param name="processId"></param>
|
/// <param name="processId"></param>
|
||||||
|
/// <param name="body"></param>
|
||||||
|
/// <param name="source"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
|
||||||
[HttpPost("{wisagId:int}/{source}/{processId:long}/closing")]
|
[HttpPost("{wisagId:int}/{source}/{processId:long}/closing")]
|
||||||
[ProducesResponseType(StatusCodes.Status501NotImplemented)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public Task<ActionResult<JsonElement>> CloseAsync([FromRoute] int wisagId, [FromRoute] string source, [FromRoute] long processId, CancellationToken cancellationToken)
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status409Conflict)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<IActionResult> CloseAsync(
|
||||||
|
[FromRoute] int wisagId,
|
||||||
|
[FromRoute] long processId,
|
||||||
|
[FromBody] CloseWorkflowReqBody body,
|
||||||
|
[FromRoute] string source = "Ferdinand",
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var result = await sender.Send(
|
||||||
|
new CloseWorkflowCommand(
|
||||||
|
WisagId: wisagId,
|
||||||
|
Source: source,
|
||||||
|
ProcessId: processId,
|
||||||
|
ClosingMethodId: body.ClosingMethodId,
|
||||||
|
Comment: body.Comment,
|
||||||
|
RejectionReasonId: body.RejectionReasonId),
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
|
var metaResult = new CloseWorkflowReqResponse() { Meta = [result] };
|
||||||
|
return result.Code switch
|
||||||
|
{
|
||||||
|
0 => Ok(metaResult),
|
||||||
|
4 => BadRequest(metaResult),
|
||||||
|
6 => NotFound(metaResult),
|
||||||
|
7 => Conflict(metaResult),
|
||||||
|
_ => StatusCode(StatusCodes.Status500InternalServerError, metaResult)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
<Authors>Digital Data GmbH</Authors>
|
<Authors>Digital Data GmbH</Authors>
|
||||||
<Company>Digital Data GmbH</Company>
|
<Company>Digital Data GmbH</Company>
|
||||||
<Product>DigitalData.TaskFlow.API</Product>
|
<Product>DigitalData.TaskFlow.API</Product>
|
||||||
<Version>1.2.0-beta</Version>
|
<Version>1.4.0-beta</Version>
|
||||||
<FileVersion>1.2.0.0</FileVersion>
|
<FileVersion>1.4.0.0</FileVersion>
|
||||||
<AssemblyVersion>1.2.0.0</AssemblyVersion>
|
<AssemblyVersion>1.4.0.0</AssemblyVersion>
|
||||||
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.API.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class CloseWorkflowReqBody
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("closing_method_id")]
|
||||||
|
public int ClosingMethodId { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string? Comment { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("rejection_reason_id")]
|
||||||
|
public byte? RejectionReasonId { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using DigitalData.TaskFlow.Application.Features.Workflows.Commands;
|
||||||
|
|
||||||
|
namespace DigitalData.TaskFlow.API.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class CloseWorkflowReqResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public List<CloseWorkflowResult> Meta { get; init; } = [];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user