feat(repository): Implementieren Sie ProfileRepository mit ReadAsync unter Verwendung von FNMWF_GET_PROFILES.

This commit is contained in:
2025-07-24 11:24:20 +02:00
parent 30bb3ffa11
commit 8c08beba4e
3 changed files with 32 additions and 2 deletions

View File

@@ -1,7 +1,33 @@
using WorkFlow.Application.Contracts.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
public class ProfileRepository : IProfileRepository
{
private readonly ILogger<ProfileRepository> _logger;
private readonly WFDBContext _context;
public ProfileRepository(WFDBContext context, ILogger<ProfileRepository> logger)
{
_logger = logger;
_context = context;
}
public async Task<Profile?> ReadAsync(int userId)
{
var profiles = await _context.Profiles
.FromSqlRaw("SELECT * FROM FNMWF_GET_PROFILES ({0})", userId)
.ToListAsync();
if (profiles == null || profiles.Count == 0)
_logger.LogError("No profile record was found associated with user ID {userId}.", userId);
else if (profiles.Count > 0)
_logger.LogError("Multiple profile records were found for user ID {userId}, which may indicate a data integrity issue.", userId);
return profiles?.FirstOrDefault();
}
}