refactor(Profil): dto in den Ordner DTO verschieben.
- Ordner DTO in Dto umbenennen
This commit is contained in:
@@ -2,42 +2,21 @@
|
||||
using MediatR;
|
||||
using WorkFlow.Application.Buttons;
|
||||
using WorkFlow.Application.Contracts.Repositories;
|
||||
using WorkFlow.Application.Objects;
|
||||
using WorkFlow.Application.Dto;
|
||||
|
||||
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 ReadProfileRequest(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
|
||||
public record ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest<ProfileDto?>;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the user profile
|
||||
/// Handles the <see cref="ReadProfileQuery"/> request by retrieving the user profile
|
||||
/// from the data store using the <see cref="IProfileRepository"/>.
|
||||
/// </summary>
|
||||
public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto?>
|
||||
public class ReadProfileHandler : IRequestHandler<ReadProfileQuery, ProfileDto?>
|
||||
{
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
|
||||
@@ -61,13 +40,13 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="ReadProfileRequest"/> request by retrieving the profile
|
||||
/// Handles the <see cref="ReadProfileQuery"/> 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<ProfileDto?> Handle(ReadProfileRequest request, CancellationToken cancel = default)
|
||||
public async Task<ProfileDto?> Handle(ReadProfileQuery request, CancellationToken cancel = default)
|
||||
{
|
||||
var profile = await _profileRepository.ReadAsync(request.UserId, cancel);
|
||||
if (request.IncludeObject && profile?.Id is int profileId)
|
||||
@@ -85,8 +64,8 @@ public class ReadProfileHandler : IRequestHandler<ReadProfileRequest, ProfileDto
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReadProfileExtensions
|
||||
public static class ReadProfileQueryExtensions
|
||||
{
|
||||
public static Task<ProfileDto?> ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
|
||||
=> mediator.Send(new ReadProfileRequest(UserId: userId, IncludeObject: includeObject));
|
||||
=> mediator.Send(new ReadProfileQuery(UserId: userId, IncludeObject: includeObject));
|
||||
}
|
||||
Reference in New Issue
Block a user