using Microsoft.EntityFrameworkCore;
using WorkFlow.Application.Contracts.Repositories;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure.Repositories;
///
/// Repository implementation for retrieving entities from the database.
///
public class ProfileObjRepository : IProfileObjRepository
{
private readonly WFDBContext _context;
///
/// Initializes a new instance of the class.
///
/// The database context used for accessing profile data.
public ProfileObjRepository(WFDBContext context)
{
_context = context;
}
///
/// Retrieves the list of associated with a given user ID and profile ID by calling a database function.
///
/// The unique identifier of the user whose profile is to be retrieved.
/// The unique identifier of the profile whose object is to be retrieved.
/// Propagates notification that operations should be canceled.
///
/// A task that represents the asynchronous operation. The task result contains the object if found; otherwise, null.
///
///
/// Logs an error if no profile is found, or if multiple profiles are returned, indicating potential data issues.
///
public async Task> ReadAsync(int userId, int profileId, CancellationToken cancel = default)
=> await _context.Objects
.FromSqlRaw("SELECT * FROM [FNMWF_GET_PROFILE_OBJECTS] ({0}, {1})", userId, profileId)
.ToListAsync(cancel);
}