feat(repository): Implementieren Sie ProfileRepository mit ReadAsync unter Verwendung von FNMWF_GET_PROFILES.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user