feat(ReadProfile): Unterstützung für das bedingte Laden von Profilobjekten hinzugefügt
- Flag „IncludeObject” in ReadProfile-Anfrage eingeführt - IProfileObjRepository in ReadProfileHandler eingefügt - Handler aktualisiert, um Profilobjekte zu laden, wenn IncludeObject wahr ist
This commit is contained in:
parent
8eb8801c41
commit
dd4cd1b39e
@ -7,7 +7,7 @@ namespace WorkFlow.Application.Profiles;
|
||||
/// 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) : IRequest<Domain.Entities.Profile?>;
|
||||
public record ReadProfile(int UserId, bool IncludeObject = true) : IRequest<Domain.Entities.Profile?>;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the <see cref="ReadProfile"/> request by retrieving the user profile
|
||||
@ -15,15 +15,19 @@ public record ReadProfile(int UserId) : IRequest<Domain.Entities.Profile?>;
|
||||
/// </summary>
|
||||
public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.Profile?>
|
||||
{
|
||||
private readonly IProfileRepository _repository;
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
|
||||
private readonly IProfileObjRepository _objRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReadProfileHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="repository">The profile repository used to access profile data.</param>
|
||||
public ReadProfileHandler(IProfileRepository repository)
|
||||
/// <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)
|
||||
{
|
||||
_repository = repository;
|
||||
_profileRepository = profileRepository;
|
||||
_objRepository = objRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -35,7 +39,10 @@ public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.P
|
||||
/// <returns>The user profile if found; otherwise, <c>null</c>.</returns>
|
||||
public async Task<Domain.Entities.Profile?> Handle(ReadProfile request, CancellationToken cancel = default)
|
||||
{
|
||||
var profile = await _repository.ReadAsync(request.UserId, cancel);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,5 +26,5 @@ public class Profile
|
||||
public string? BackColor { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public IEnumerable<ProfileObject>? Objects;
|
||||
public IEnumerable<ProfileObject>? Objects { get; set; }
|
||||
}
|
||||
@ -5,10 +5,10 @@ namespace WorkFlow.Domain.Entities;
|
||||
public class ProfileObject
|
||||
{
|
||||
[Column("ObjStateID")]
|
||||
public int? ObjStateId { get; set; }
|
||||
public long? ObjStateId { get; set; }
|
||||
|
||||
[Column("ObjectID")]
|
||||
public int? ObjectId { get; set; }
|
||||
public long? Id { get; set; }
|
||||
|
||||
[Column("Headline1")]
|
||||
public string? Headline1 { get; set; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user