From 3da16ba640379786e25393e6bb8235ab50e52b86 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 12 Dec 2025 15:16:38 +0100 Subject: [PATCH] Introduce DTOs and refactor app layer to use them Added DTO classes for Connection, Endpoint, EndpointAuth, EndpointParam, Profile, and RecAction. Updated AutoMapper profiles, DbContext, and command handlers to use DTOs instead of domain entities. This decouples the application layer from the domain model, improving maintainability and flexibility. Cleaned up some using directives and file headers. --- .../Common/Dto/ConnectionDto.cs | 32 +++++++++++ .../Common/Dto/DtoMappingProfile.cs | 8 +++ .../Common/Dto/EndpointAuthDto.cs | 40 ++++++++++++++ src/ReC.Application/Common/Dto/EndpointDto.cs | 22 ++++++++ .../Common/Dto/EndpointParamDto.cs | 33 ++++++++++++ src/ReC.Application/Common/Dto/ProfileDto.cs | 31 +++++++++++ .../Common/Dto/RecActionDto.cs | 54 +++++++++++++++++++ .../Common/Dto/RecActionViewDto.cs | 3 +- .../Common/Interfaces/IRecDbContext.cs | 10 ++-- .../Commands/ObtainEndpointCommand.cs.cs | 6 +-- .../Endpoints/MappingProfile.cs | 2 +- .../RecActionViews/MappingProfile.cs | 2 +- .../Commands/CreateRecActionCommand.cs | 2 +- .../Commands/DeleteRecActionsCommand.cs | 2 +- 14 files changed, 233 insertions(+), 14 deletions(-) create mode 100644 src/ReC.Application/Common/Dto/ConnectionDto.cs create mode 100644 src/ReC.Application/Common/Dto/EndpointAuthDto.cs create mode 100644 src/ReC.Application/Common/Dto/EndpointDto.cs create mode 100644 src/ReC.Application/Common/Dto/EndpointParamDto.cs create mode 100644 src/ReC.Application/Common/Dto/ProfileDto.cs create mode 100644 src/ReC.Application/Common/Dto/RecActionDto.cs diff --git a/src/ReC.Application/Common/Dto/ConnectionDto.cs b/src/ReC.Application/Common/Dto/ConnectionDto.cs new file mode 100644 index 0000000..7f45796 --- /dev/null +++ b/src/ReC.Application/Common/Dto/ConnectionDto.cs @@ -0,0 +1,32 @@ +namespace ReC.Application.Common.Dto; + +public record ConnectionDto +{ + public short? Id { get; set; } + + public string? Bezeichnung { get; set; } + + public string? SqlProvider { get; set; } + + public string? Server { get; set; } + + public string? Datenbank { get; set; } + + public string? Username { get; set; } + + public string? Password { get; set; } + + public string? Bemerkung { get; set; } + + public bool? Aktiv { get; set; } + + public string? ErstelltWer { get; set; } + + public DateTime? ErstelltWann { get; set; } + + public string? GeandertWer { get; set; } + + public DateTime? GeaendertWann { get; set; } + + public bool? SysConnection { get; set; } +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Dto/DtoMappingProfile.cs b/src/ReC.Application/Common/Dto/DtoMappingProfile.cs index c4b67ee..ed9ffd3 100644 --- a/src/ReC.Application/Common/Dto/DtoMappingProfile.cs +++ b/src/ReC.Application/Common/Dto/DtoMappingProfile.cs @@ -8,5 +8,13 @@ public class DtoMappingProfile : AutoMapper.Profile { CreateMap(); CreateMap(); + + + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); } } diff --git a/src/ReC.Application/Common/Dto/EndpointAuthDto.cs b/src/ReC.Application/Common/Dto/EndpointAuthDto.cs new file mode 100644 index 0000000..8bd4636 --- /dev/null +++ b/src/ReC.Application/Common/Dto/EndpointAuthDto.cs @@ -0,0 +1,40 @@ +using ReC.Domain.Constants; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ReC.Application.Common.Dto; + +[Table("TBREC_CFG_ENDPOINT_AUTH")] +public record EndpointAuthDto +{ + public long? Id { get; set; } + + public bool? Active { get; set; } + + public string? Description { get; set; } + + public EndpointAuthType? Type { get; set; } + + public string? ApiKey { get; set; } + + public string? ApiValue { get; set; } + + public ApiKeyLocation? ApiKeyAddTo { get; set; } + + public string? Token { get; set; } + + public string? Username { get; set; } + + public string? Password { get; set; } + + public string? Domain { get; set; } + + public string? Workstation { get; set; } + + public string? AddedWho { get; set; } + + public DateTime? AddedWhen { get; set; } + + public string? ChangedWho { get; set; } + + public DateTime? ChangedWhen { get; set; } +} diff --git a/src/ReC.Application/Common/Dto/EndpointDto.cs b/src/ReC.Application/Common/Dto/EndpointDto.cs new file mode 100644 index 0000000..3505d50 --- /dev/null +++ b/src/ReC.Application/Common/Dto/EndpointDto.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace ReC.Application.Common.Dto; + +public record EndpointDto +{ + public long Id { get; set; } + + public bool? Active { get; set; } + + public string? Description { get; set; } + + public string? Uri { get; set; } + + public string? AddedWho { get; set; } + + public DateTime? AddedWhen { get; set; } + + public string? ChangedWho { get; set; } + + public DateTime? ChangedWhen { get; set; } +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Dto/EndpointParamDto.cs b/src/ReC.Application/Common/Dto/EndpointParamDto.cs new file mode 100644 index 0000000..7b7343c --- /dev/null +++ b/src/ReC.Application/Common/Dto/EndpointParamDto.cs @@ -0,0 +1,33 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace ReC.Application.Common.Dto; + +/// +/// Represents the TBREC_CFG_ENDPOINT_PARAMS table. +/// All properties are nullable to provide flexibility on the database side, +/// preventing breaking changes if columns are altered to be nullable in production. +/// +public record EndpointParamDto +{ + public long? Id { get; set; } + + public bool? Active { get; set; } + + public string? Description { get; set; } + + public short? GroupId { get; set; } + + public byte? Sequence { get; set; } + + public string? Key { get; set; } + + public string? Value { get; set; } + + public string? AddedWho { get; set; } + + public DateTime? AddedWhen { get; set; } + + public string? ChangedWho { get; set; } + + public DateTime? ChangedWhen { get; set; } +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Dto/ProfileDto.cs b/src/ReC.Application/Common/Dto/ProfileDto.cs new file mode 100644 index 0000000..a0e01aa --- /dev/null +++ b/src/ReC.Application/Common/Dto/ProfileDto.cs @@ -0,0 +1,31 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace ReC.Application.Common.Dto; + +[Table("TBREC_CFG_PROFILE", Schema = "dbo")] +public record ProfileDto +{ + public long Id { get; set; } + + public bool? Active { get; set; } + + public string? Type { get; set; } + + public string? Mandantor { get; set; } + + public string? Name { get; set; } + + public string? Description { get; set; } + + public string? LogLevel { get; set; } + + public string? Language { get; set; } + + public string? AddedWho { get; set; } + + public DateTime? AddedWhen { get; set; } + + public string? ChangedWho { get; set; } + + public DateTime? ChangedWhen { get; set; } +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Dto/RecActionDto.cs b/src/ReC.Application/Common/Dto/RecActionDto.cs new file mode 100644 index 0000000..9fcf277 --- /dev/null +++ b/src/ReC.Application/Common/Dto/RecActionDto.cs @@ -0,0 +1,54 @@ +using ReC.Domain.Constants; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ReC.Application.Common.Dto; + +[Table("TBREC_CFG_ACTION")] +public record RecActionDto +{ + public long? Id { get; set; } + + public long? ProfileId { get; set; } + + public ProfileDto? Profile { get; set; } + + public bool? Active { get; set; } + + public byte? Sequence { get; set; } + + public long? EndpointId { get; set; } + + public EndpointDto? Endpoint { get; set; } + + public long? EndpointAuthId { get; set; } + + public EndpointAuthDto? EndpointAuth { get; set; } + + public short? EndpointParamsId { get; set; } + + public short? SqlConnectionId { get; set; } + + public ConnectionDto? SqlConnection { get; set; } + + public string? Type { get; set; } + + public string? PreprocessingQuery { get; set; } + + public string? HeaderQuery { get; set; } + + public string? BodyQuery { get; set; } + + public string? PostprocessingQuery { get; set; } + + public ErrorAction? ErrorAction { get; set; } + + public string? AddedWho { get; set; } + + public DateTime? AddedWhen { get; set; } + + public string? ChangedWho { get; set; } + + public DateTime? ChangedWhen { get; set; } + + public OutResDto? OutRes { get; set; } +} \ No newline at end of file diff --git a/src/ReC.Application/Common/Dto/RecActionViewDto.cs b/src/ReC.Application/Common/Dto/RecActionViewDto.cs index ec5c344..4e78374 100644 --- a/src/ReC.Application/Common/Dto/RecActionViewDto.cs +++ b/src/ReC.Application/Common/Dto/RecActionViewDto.cs @@ -1,5 +1,4 @@ -using ReC.Application.Common.Constants; -using ReC.Domain.Constants; +using ReC.Domain.Constants; namespace ReC.Application.Common.Dto; diff --git a/src/ReC.Application/Common/Interfaces/IRecDbContext.cs b/src/ReC.Application/Common/Interfaces/IRecDbContext.cs index e0046fc..f0e2bf4 100644 --- a/src/ReC.Application/Common/Interfaces/IRecDbContext.cs +++ b/src/ReC.Application/Common/Interfaces/IRecDbContext.cs @@ -15,15 +15,15 @@ public interface IRecDbContext public DbSet BodyQueryResults { get; set; } - public DbSet Connections { get; set; } + public DbSet Connections { get; set; } - public DbSet Endpoints { get; set; } + public DbSet Endpoints { get; set; } - public DbSet EndpointAuths { get; set; } + public DbSet EndpointAuths { get; set; } - public DbSet Profiles { get; set; } + public DbSet Profiles { get; set; } - public DbSet RecActions { get; set; } + public DbSet RecActions { get; set; } public Task SaveChangesAsync(CancellationToken cancel = default); } \ No newline at end of file diff --git a/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs b/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs index ca401c5..9a1df6a 100644 --- a/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs +++ b/src/ReC.Application/Endpoints/Commands/ObtainEndpointCommand.cs.cs @@ -5,14 +5,14 @@ using ReC.Domain.Entities; namespace ReC.Application.Endpoints.Commands; -public class ObtainEndpointCommand : IRequest +public class ObtainEndpointCommand : IRequest { public string Uri { get; init; } = null!; } -public class ObtainEndpointCommandHandler(IRepository repo) : IRequestHandler +public class ObtainEndpointCommandHandler(IRepository repo) : IRequestHandler { - public async Task Handle(ObtainEndpointCommand request, CancellationToken cancel) + public async Task Handle(ObtainEndpointCommand request, CancellationToken cancel) { var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel); diff --git a/src/ReC.Application/Endpoints/MappingProfile.cs b/src/ReC.Application/Endpoints/MappingProfile.cs index 8bfbd0f..b392e07 100644 --- a/src/ReC.Application/Endpoints/MappingProfile.cs +++ b/src/ReC.Application/Endpoints/MappingProfile.cs @@ -8,7 +8,7 @@ public class MappingProfile : AutoMapper.Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(e => e.Active, exp => exp.MapFrom(cmd => true)) .ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow)) .ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API")); diff --git a/src/ReC.Application/RecActionViews/MappingProfile.cs b/src/ReC.Application/RecActionViews/MappingProfile.cs index 13f659b..67c5950 100644 --- a/src/ReC.Application/RecActionViews/MappingProfile.cs +++ b/src/ReC.Application/RecActionViews/MappingProfile.cs @@ -8,7 +8,7 @@ public class MappingProfile : AutoMapper.Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(e => e.Active, exp => exp.MapFrom(cmd => true)) .ForMember(e => e.AddedWhen, exp => exp.MapFrom(cmd => DateTime.UtcNow)) .ForMember(e => e.AddedWho, exp => exp.MapFrom(cmd => "ReC.API")); diff --git a/src/ReC.Application/RecActions/Commands/CreateRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/CreateRecActionCommand.cs index 28816be..0605a7d 100644 --- a/src/ReC.Application/RecActions/Commands/CreateRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/CreateRecActionCommand.cs @@ -27,7 +27,7 @@ public record CreateRecActionCommand : IRequest public long? EndpointAuthId { get; set; } } -public class CreateRecActionCommandHandler(ISender sender, IRepository repo) : IRequestHandler +public class CreateRecActionCommandHandler(ISender sender, IRepository repo) : IRequestHandler { public async Task Handle(CreateRecActionCommand request, CancellationToken cancel) { diff --git a/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs b/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs index 84e52d9..92e93a9 100644 --- a/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/DeleteRecActionsCommand.cs @@ -11,7 +11,7 @@ public class DeleteRecActionsCommand : IRequest public required long ProfileId { get; init; } } -public class DeleteRecActionsCommandHandler(IRepository repo) : IRequestHandler +public class DeleteRecActionsCommandHandler(IRepository repo) : IRequestHandler { public async Task Handle(DeleteRecActionsCommand request, CancellationToken cancel) {