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.
This commit is contained in:
2025-12-12 15:16:38 +01:00
parent 71a0220c3f
commit 3da16ba640
14 changed files with 233 additions and 14 deletions

View File

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

View File

@@ -8,5 +8,13 @@ public class DtoMappingProfile : AutoMapper.Profile
{
CreateMap<RecActionView, RecActionViewDto>();
CreateMap<OutRes, OutResDto>();
CreateMap<Connection, ConnectionDto>();
CreateMap<EndpointAuth, EndpointAuthDto>();
CreateMap<Endpoint, EndpointDto>();
CreateMap<EndpointParam, EndpointParamDto>();
CreateMap<Profile, ProfileDto>();
CreateMap<RecAction, RecActionDto>();
}
}

View File

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

View File

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

View File

@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
/// <summary>
/// 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.
/// </summary>
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; }
}

View File

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

View File

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

View File

@@ -1,5 +1,4 @@
using ReC.Application.Common.Constants;
using ReC.Domain.Constants;
using ReC.Domain.Constants;
namespace ReC.Application.Common.Dto;

View File

@@ -15,15 +15,15 @@ public interface IRecDbContext
public DbSet<BodyQueryResult> BodyQueryResults { get; set; }
public DbSet<Connection> Connections { get; set; }
public DbSet<ConnectionDto> Connections { get; set; }
public DbSet<Endpoint> Endpoints { get; set; }
public DbSet<EndpointDto> Endpoints { get; set; }
public DbSet<EndpointAuth> EndpointAuths { get; set; }
public DbSet<EndpointAuthDto> EndpointAuths { get; set; }
public DbSet<Profile> Profiles { get; set; }
public DbSet<ProfileDto> Profiles { get; set; }
public DbSet<RecAction> RecActions { get; set; }
public DbSet<RecActionDto> RecActions { get; set; }
public Task<int> SaveChangesAsync(CancellationToken cancel = default);
}

View File

@@ -5,14 +5,14 @@ using ReC.Domain.Entities;
namespace ReC.Application.Endpoints.Commands;
public class ObtainEndpointCommand : IRequest<Endpoint>
public class ObtainEndpointCommand : IRequest<EndpointDto>
{
public string Uri { get; init; } = null!;
}
public class ObtainEndpointCommandHandler(IRepository<Endpoint> repo) : IRequestHandler<ObtainEndpointCommand, Endpoint>
public class ObtainEndpointCommandHandler(IRepository<EndpointDto> repo) : IRequestHandler<ObtainEndpointCommand, EndpointDto>
{
public async Task<Endpoint> Handle(ObtainEndpointCommand request, CancellationToken cancel)
public async Task<EndpointDto> Handle(ObtainEndpointCommand request, CancellationToken cancel)
{
var endpoint = await repo.Where(e => e.Uri == request.Uri).FirstOrDefaultAsync(cancel);

View File

@@ -8,7 +8,7 @@ public class MappingProfile : AutoMapper.Profile
{
public MappingProfile()
{
CreateMap<ObtainEndpointCommand, Endpoint>()
CreateMap<ObtainEndpointCommand, EndpointDto>()
.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"));

View File

@@ -8,7 +8,7 @@ public class MappingProfile : AutoMapper.Profile
{
public MappingProfile()
{
CreateMap<CreateRecActionCommand, RecAction>()
CreateMap<CreateRecActionCommand, RecActionDto>()
.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"));

View File

@@ -27,7 +27,7 @@ public record CreateRecActionCommand : IRequest
public long? EndpointAuthId { get; set; }
}
public class CreateRecActionCommandHandler(ISender sender, IRepository<RecAction> repo) : IRequestHandler<CreateRecActionCommand>
public class CreateRecActionCommandHandler(ISender sender, IRepository<RecActionDto> repo) : IRequestHandler<CreateRecActionCommand>
{
public async Task Handle(CreateRecActionCommand request, CancellationToken cancel)
{

View File

@@ -11,7 +11,7 @@ public class DeleteRecActionsCommand : IRequest
public required long ProfileId { get; init; }
}
public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand>
public class DeleteRecActionsCommandHandler(IRepository<RecActionDto> repo) : IRequestHandler<DeleteRecActionsCommand>
{
public async Task Handle(DeleteRecActionsCommand request, CancellationToken cancel)
{