Compare commits

...

11 Commits

Author SHA1 Message Date
307c81001a Update project version to 1.4.0-beta
Updated the `DigitalData.TaskFlow.API` project version from `1.3.0-beta` to `1.4.0-beta`. This includes updates to the `FileVersion` and `AssemblyVersion` from `1.3.0.0` to `1.4.0.0`, reflecting a new release with potential new features, improvements, or fixes.
2026-11-09 16:15:17 +01:00
9c5346213e Add GetAuthorizedUsersQuery and UsersController
Introduced the `GetAuthorizedUsersQuery` feature to retrieve
authorized users, including the query, result, metadata, and
handler implementation. The handler interacts with the
`IUserRepository` to fetch user data.

Added a new `UsersController` with an `[HttpGet("authorized")]`
endpoint to expose the query via a RESTful API. The endpoint
returns appropriate HTTP status codes (`200 OK`, `401
Unauthorized`, `500 Internal Server Error`) based on the
result metadata.

Included necessary `using` directives for MediatR, ASP.NET
Core, and application features.
2026-11-09 15:59:09 +01:00
6542d804f8 Add IUserRepository and implement UserRepository
Added the `IUserRepository` interface to define a method for retrieving authorized users asynchronously. Registered `IUserRepository` with its implementation `UserRepository` in the dependency injection container. Implemented `UserRepository` to execute a stored procedure and fetch authorized users using `TaskFlowDbContext`.
2026-11-09 15:15:16 +01:00
f470367d89 Add AuthorizedUser entity and DbSet to TaskFlowDbContext
A new `DbSet` property `AuthorizedUsers` was added to the
`TaskFlowDbContext` class to represent keyless results for
authorized users procedure results.

The `OnModelCreating` method was updated to configure the
`AuthorizedUser` entity as keyless, map it to a database view,
and define the `WisagId` property mapping.

Additionally, a new `AuthorizedUser` class was introduced in
the `DigitalData.TaskFlow.Domain.ProcedureResults` namespace
with an immutable `WisagId` property.
2026-11-09 15:07:13 +01:00
6ec2187361 Update project version to 1.3.0-beta
Updated the `DigitalData.TaskFlow.API` project version from `1.2.0-beta` to `1.3.0-beta`. This includes updates to the `FileVersion` and `AssemblyVersion` from `1.2.0.0` to `1.3.0.0`, reflecting a new release with potential new features, improvements, or changes.
2026-11-09 15:01:56 +01:00
8c6102d161 Refactor workflow closure logic and enhance API
Updated `CloseWorkflowCommand` to use nullable `Code` and `Message` properties for better result representation. Refactored `CloseWorkflowCommandHandler` to use a capitalized `Repo` and improved exception handling with `InvalidWorkflowPayloadException`. Enhanced `WorkflowsController` by implementing the `CloseAsync` method, which now processes `CloseWorkflowReqBody` and returns appropriate HTTP status codes. Updated XML documentation for clarity.
2026-11-04 10:07:33 +01:00
3c3744c0ce Add CloseWorkflowReqBody and CloseWorkflowReqResponse
Introduce two new classes in the DigitalData.TaskFlow.API.Models namespace to handle workflow closure requests and responses.

- CloseWorkflowReqBody.cs:
  - Added CloseWorkflowReqBody class with properties:
    - ClosingMethodId: int, mapped to "closing_method_id".
    - Comment: nullable string.
    - RejectionReasonId: nullable byte, mapped to "rejection_reason_id".

- CloseWorkflowReqResponse.cs:
  - Added CloseWorkflowReqResponse class with Meta property:
    - Meta: List of CloseWorkflowResult, initialized to an empty list.
2026-11-04 10:07:03 +01:00
46da385b92 Add CloseWorkflowCommandHandler for workflow closure
Introduce CloseWorkflowCommandHandler class to handle the
closure of workflows using the MediatR library. This class
implements IRequestHandler and processes CloseWorkflowCommand
requests, returning CloseWorkflowResult objects. It interacts
with IWorkflowRepository to execute the CloseAsync method,
validating the procedure result and throwing an exception if
the result is invalid. Necessary using directives for
DigitalData.TaskFlow.Application.Common.Interfaces and MediatR
are also added.
2026-11-03 20:57:45 +01:00
210c1f414c Add CloseAsync method to WorkflowRepository
Introduced a new asynchronous method `CloseAsync` in the
`WorkflowRepository` class to handle workflow process closing.
This method executes the `PRCUST_F19_CLOSING` stored procedure
with parameters for user ID, source, process ID, closing method
ID, comment, and rejection reason ID. It uses `FromSqlInterpolated`
for safe SQL parameterization and retrieves results with
`AsNoTracking()` and `ToListAsync(cancellationToken)`. The method
returns the first result as a `WorkflowClosing` object or `null`.
2026-11-03 20:44:08 +01:00
ca3772e2a8 Add CloseAsync method and WorkflowClosing entity
Introduced a new method `CloseAsync` in the `IWorkflowRepository`
interface to handle workflow item closure and return a procedure
result. Added a new class `WorkflowClosing` in `WorkflowClosing.cs`
as a sealed class inheriting from `ProcedureResultBase`.

Updated `TaskFlowDbContext` to include a `DbSet<WorkflowClosing>`
for keyless workflow close procedure results. Configured the
`WorkflowClosing` entity in `OnModelCreating` with specific
column mappings and a maximum length for the `Result` property.
2026-11-03 20:42:21 +01:00
a01e61aafe Add CloseWorkflowCommand with MediatR support
Introduce CloseWorkflowCommand and CloseWorkflowResult records
in CloseWorkflowCommand.cs within the DigitalData.TaskFlow
namespace. The command encapsulates data for closing a workflow,
including WisagId, Source, ProcessId, ClosingMethodId, Comment,
and RejectionReasonId. The result record provides ResultCode and
ResultMessage to convey the operation's outcome. These changes
utilize MediatR, aligning with the CQRS pattern for state
modification.
2026-11-03 20:34:34 +01:00
16 changed files with 291 additions and 9 deletions

View File

@@ -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);
}

View File

@@ -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);
} }

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -0,0 +1,6 @@
namespace DigitalData.TaskFlow.Domain.ProcedureResults;
public class AuthorizedUser
{
public int WisagId { get; init; }
}

View File

@@ -0,0 +1,5 @@
namespace DigitalData.TaskFlow.Domain.ProcedureResults;
public sealed class WorkflowClosing : ProcedureResultBase
{
}

View File

@@ -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;
} }

View File

@@ -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");
});
} }
} }

View File

@@ -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);
}
}

View File

@@ -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();
}
} }

View File

@@ -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)
};
}
}

View File

@@ -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)
};
} }
} }

View File

@@ -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>

View File

@@ -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; }
}

View File

@@ -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; } = [];
}