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:
tekh 2025-07-25 17:42:58 +02:00
parent 8eb8801c41
commit dd4cd1b39e
3 changed files with 16 additions and 9 deletions

View File

@ -7,7 +7,7 @@ namespace WorkFlow.Application.Profiles;
/// Represents a request to read a user profile by their user ID. /// Represents a request to read a user profile by their user ID.
/// </summary> /// </summary>
/// <param name="UserId">The ID of the user whose profile is being requested.</param> /// <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> /// <summary>
/// Handles the <see cref="ReadProfile"/> request by retrieving the user profile /// 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> /// </summary>
public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.Profile?> public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.Profile?>
{ {
private readonly IProfileRepository _repository; private readonly IProfileRepository _profileRepository;
private readonly IProfileObjRepository _objRepository;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ReadProfileHandler"/> class. /// Initializes a new instance of the <see cref="ReadProfileHandler"/> class.
/// </summary> /// </summary>
/// <param name="repository">The profile repository used to access profile data.</param> /// <param name="profileRepository">The profile repository used to access profile data.</param>
public ReadProfileHandler(IProfileRepository repository) /// <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> /// <summary>
@ -35,7 +39,10 @@ public class ReadProfileHandler : IRequestHandler<ReadProfile, Domain.Entities.P
/// <returns>The user profile if found; otherwise, <c>null</c>.</returns> /// <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<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; return profile;
} }
} }

View File

@ -26,5 +26,5 @@ public class Profile
public string? BackColor { get; set; } public string? BackColor { get; set; }
[NotMapped] [NotMapped]
public IEnumerable<ProfileObject>? Objects; public IEnumerable<ProfileObject>? Objects { get; set; }
} }

View File

@ -5,10 +5,10 @@ namespace WorkFlow.Domain.Entities;
public class ProfileObject public class ProfileObject
{ {
[Column("ObjStateID")] [Column("ObjStateID")]
public int? ObjStateId { get; set; } public long? ObjStateId { get; set; }
[Column("ObjectID")] [Column("ObjectID")]
public int? ObjectId { get; set; } public long? Id { get; set; }
[Column("Headline1")] [Column("Headline1")]
public string? Headline1 { get; set; } public string? Headline1 { get; set; }