Compare commits

...

4 Commits

Author SHA1 Message Date
8ceaa9cb21 feat(ReadObject): created to handle objects.
- Add ObjectDto and mapping profile
2025-07-29 22:19:48 +02:00
27e4b4b2ef feat(ReadProfile): add logic to read buttons 2025-07-29 22:09:11 +02:00
82eb03b420 refactor(ReadProfile): update to read buttons 2025-07-29 21:49:21 +02:00
559127a931 feat(ReadButton): add dto and handler 2025-07-29 21:41:54 +02:00
10 changed files with 111 additions and 24 deletions

View File

@ -0,0 +1,29 @@
using DigitalData.Core.Abstractions;
using MediatR;
namespace WorkFlow.Application.Buttons;
public record ButtonDto : IUnique<int>
{
public int Id { get; init; }
public required int ProfileId { get; init; }
public byte? DialogNo { get; init; }
public string? BtnType { get; init; }
public string? Icon { get; init; }
public string? ForeColor { get; init; }
public string? BackColor { get; init; }
public string? Command { get; init; }
public string? DialogCommand { get; init; }
public string? ConfirmationText { get; init; }
}
public record ReadButtonRequest : IRequest<ButtonDto>;

View File

@ -5,4 +5,5 @@ namespace WorkFlow.Application.Contracts.Repositories;
public interface IButtonRepository : ICRUDRepository<Button, int>
{
public Task<IEnumerable<Button>> ReadAllAsync(int profileId);
}

View File

@ -1,12 +0,0 @@
namespace WorkFlow.Application.DTO.Profile
{
public record ProfileDto(int Id,
string IntlName,
int ExtId1,
bool Active,
byte TypeId,
string AddedWho,
DateTime AddedWhen,
string? ChangedWho = null,
DateTime? ChangedWhen = null);
}

View File

@ -16,6 +16,5 @@ namespace WorkFlow.Application.DTO.ProfileControlsTF
string AddedWho,
DateTime AddedWhen,
string? ChoiceList = null,
ProfileDto? Profile = null,
UserReadDto? User = null);
}

View File

@ -14,7 +14,6 @@ namespace WorkFlow.Application.DTO.ProfileObjState
string? State2 = null,
string? State3 = null,
string? State4 = null,
ProfileDto? Profile = null,
UserReadDto? User = null,
StateDto? State = null);
}

View File

@ -1,9 +1,12 @@
using AutoMapper;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.DTO.Config;
using WorkFlow.Application.DTO.Profile;
using WorkFlow.Application.DTO.ProfileControlsTF;
using WorkFlow.Application.DTO.ProfileObjState;
using WorkFlow.Application.DTO.State;
using WorkFlow.Application.Objects;
using WorkFlow.Application.Profiles;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application
@ -18,6 +21,13 @@ namespace WorkFlow.Application
CreateMap<ProfileControlsTF, ProfileControlsTFDto>();
CreateMap<ProfileObjState, ProfileObjStateDto>();
CreateMap<State, StateDto>();
CreateMap<Button, ButtonDto>();
CreateMap<ProfileObject, ObjectDto>()
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src =>
new[] { src.Headline1, src.Headline2 }))
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src =>
new[] { src.Subline1, src.Subline2 }));
// Mapping create-DTO to entity
CreateMap<ConfigCreateDto, Config>();

View File

@ -0,0 +1,19 @@
using MediatR;
namespace WorkFlow.Application.Objects;
public class ObjectDto
{
public long? ObjStateId { get; set; }
public long? Id { get; set; }
public IEnumerable<string> Headlines { get; set; } = Array.Empty<string>();
public IEnumerable<string> Sublines { get; set; } = Array.Empty<string>();
public string? CmdCheckIn { get; set; }
}
public record ReadObjectRequest : IRequest
{
}

View File

@ -1,54 +1,92 @@
using MediatR;
using AutoMapper;
using MediatR;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Application.Objects;
namespace WorkFlow.Application.Profiles;
public class ProfileDto
{
public int? Id { get; init; }
public byte? TypeId { get; init; }
public string? Caption { get; init; }
public string? Subtitle { get; init; }
public int? CountObj { get; init; }
public string? ForeColor { get; init; }
public string? BackColor { get; init; }
public IEnumerable<ObjectDto> Objects { get; init; } = Array.Empty<ObjectDto>();
public IEnumerable<ButtonDto>? Buttons { get; set; } = Array.Empty<ButtonDto>();
}
/// <summary>
/// Represents a request to read a user profile by their user ID.
/// </summary>
/// <param name="UserId">The ID of the user whose profile is being requested.</param>
public record ReadProfile(int UserId, bool IncludeObject = true) : IRequest<Domain.Entities.Profile?>;
public record ReadProfileRequest(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
/// <summary>
/// Handles the <see cref="ReadProfile"/> request by retrieving the user profile
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the user profile
/// from the data store using the <see cref="IProfileRepository"/>.
/// </summary>
public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.Profile?>
public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto?>
{
private readonly IProfileRepository _profileRepository;
private readonly IProfileObjRepository _objRepository;
private readonly IButtonRepository _bttnRepository;
private readonly IMapper _mapper;
/// <summary>
/// Initializes a new instance of the <see cref="ReadProfileHandler"/> class.
/// </summary>
/// <param name="profileRepository">The profile repository used to access profile data.</param>
/// <param name="objRepository">The profile object repository used to access object data.</param>
public ReadProfileHandler(IProfileRepository profileRepository, IProfileObjRepository objRepository)
public ReadProfileHandler(IProfileRepository profileRepository, IProfileObjRepository objRepository, IButtonRepository buttonRepository, IMapper mapper)
{
_profileRepository = profileRepository;
_objRepository = objRepository;
_bttnRepository = buttonRepository;
_mapper = mapper;
}
/// <summary>
/// Handles the <see cref="ReadProfile"/> request by retrieving the profile
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the profile
/// corresponding to the specified user ID.
/// </summary>
/// <param name="request">The request containing the user ID.</param>
/// <param name="cancel">A cancellation token for the operation.</param>
/// <returns>The user profile if found; otherwise, <c>null</c>.</returns>
public async Task<Domain.Entities.Profile?> Handle(ReadProfile request, CancellationToken cancel = default)
public async Task<ProfileDto?> Handle(ReadProfileRequest request, CancellationToken cancel = default)
{
var profile = await _profileRepository.ReadAsync(request.UserId, cancel);
if (request.IncludeObject && profile?.Id is int profileId)
profile.Objects = await _objRepository.ReadAsync(request.UserId, profileId, cancel);
return profile;
var profileDto = _mapper.Map<ProfileDto>(profile);
if (profile?.Id is int pId)
{
var bttns = await _bttnRepository.ReadAllAsync(pId);
profileDto.Buttons = _mapper.Map<IEnumerable<ButtonDto>>(bttns);
}
return profileDto;
}
}
public static class ReadProfileExtensions
{
public static Task<Domain.Entities.Profile?> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
=> mediator.Send(new ReadProfile(UserId: userId, IncludeObject: includeObject));
public static Task<ProfileDto?> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
=> mediator.Send(new ReadProfileRequest(UserId: userId, IncludeObject: includeObject));
}

View File

@ -15,6 +15,7 @@ public static class DependencyInjection
services.TryAddScoped<IProfileRepository, ProfileRepository>();
services.TryAddScoped<IProfileObjRepository, ProfileObjRepository>();
services.TryAddScoped<IStateRepository, StateRepository>();
services.TryAddScoped<IButtonRepository, ButtonRepository>();
return services;
}
}

View File

@ -1,5 +1,6 @@
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
@ -11,4 +12,6 @@ public class ButtonRepository : CRUDRepository<Button, int, WFDBContext>, IButto
public ButtonRepository(WFDBContext dbContext) : base(dbContext, dbContext.Buttons)
{
}
public async Task<IEnumerable<Button>> ReadAllAsync(int profileId) => await _dbSet.Where(b => b.ProfileId == profileId).ToListAsync();
}