diff --git a/src/WorkFlow.API/Controllers/ProfileController.cs b/src/WorkFlow.API/Controllers/ProfileController.cs
index 7891e9f..0926e6a 100644
--- a/src/WorkFlow.API/Controllers/ProfileController.cs
+++ b/src/WorkFlow.API/Controllers/ProfileController.cs
@@ -32,6 +32,6 @@ public class ProfileController : ControllerBase
}
var profile = await _mediator.ReadProfileAsync(userId);
- return profile is null ? NotFound() : Ok(profile);
+ return Ok(profile);
}
}
\ No newline at end of file
diff --git a/src/WorkFlow.Application/Profiles/ReadProfileQuery.cs b/src/WorkFlow.Application/Profiles/ReadProfileQuery.cs
index 6717d61..b3c1fed 100644
--- a/src/WorkFlow.Application/Profiles/ReadProfileQuery.cs
+++ b/src/WorkFlow.Application/Profiles/ReadProfileQuery.cs
@@ -1,5 +1,6 @@
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
+using DigitalData.Core.Exceptions;
using MediatR;
using WorkFlow.Application.Buttons;
using WorkFlow.Application.Contracts.Repositories;
@@ -12,13 +13,13 @@ namespace WorkFlow.Application.Profiles;
/// Represents a request to read a user profile by their user ID.
///
/// The ID of the user whose profile is being requested.
-public record ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest;
+public record ReadProfileQuery(int UserId, bool IncludeObject = true) : IRequest;
///
/// Handles the request by retrieving the user profile
/// from the data store using the .
///
-public class ReadProfileHandler : IRequestHandler
+public class ReadProfileHandler : IRequestHandler
{
private readonly IProfileRepository _profileRepository;
@@ -48,15 +49,17 @@ public class ReadProfileHandler : IRequestHandler
/// The request containing the user ID.
/// A cancellation token for the operation.
/// The user profile if found; otherwise, null.
- public async Task Handle(ReadProfileQuery request, CancellationToken cancel = default)
+ public async Task Handle(ReadProfileQuery request, CancellationToken cancel = default)
{
- var profile = await _profileRepository.ReadAsync(request.UserId, cancel);
- if (request.IncludeObject && profile?.Id is int profileId)
+ var profile = await _profileRepository.ReadAsync(request.UserId, cancel)
+ ?? throw new NotFoundException();
+
+ if (request.IncludeObject && profile.Id is int profileId)
profile.Objects = await _objRepository.ReadAsync(request.UserId, profileId, cancel);
var profileDto = _mapper.Map(profile);
- if (profile?.Id is int pId)
+ if (profile.Id is int pId)
{
var bttns = await _bttnRepository.Read(b => b.ProfileId == pId).ToListAsync(cancel);
profileDto.Buttons = _mapper.Map>(bttns);
@@ -68,6 +71,6 @@ public class ReadProfileHandler : IRequestHandler
public static class ReadProfileQueryExtensions
{
- public static Task ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
+ public static Task ReadProfileAsync(this IMediator mediator, int userId, bool includeObject = true)
=> mediator.Send(new ReadProfileQuery(UserId: userId, IncludeObject: includeObject));
}
\ No newline at end of file
diff --git a/src/WorkFlow.Application/WorkFlow.Application.csproj b/src/WorkFlow.Application/WorkFlow.Application.csproj
index 32f9ac0..366b099 100644
--- a/src/WorkFlow.Application/WorkFlow.Application.csproj
+++ b/src/WorkFlow.Application/WorkFlow.Application.csproj
@@ -9,6 +9,7 @@
+