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

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

View File

@ -5,6 +5,7 @@ VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
ProjectSection(SolutionItems) = preProject
scripts\GetProfile.sql = scripts\GetProfile.sql
README.md = README.md
EndProjectSection
EndProject

View File

@ -1,5 +1,8 @@
namespace WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Application.Contracts.Repositories;
public interface IProfileRepository
{
Task<Profile?> ReadAsync(int userId);
}

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();
}
}