diff --git a/src/WorkFlow.Infrastructure/Repositories/ProfileObjRepository.cs b/src/WorkFlow.Infrastructure/Repositories/ProfileObjRepository.cs new file mode 100644 index 0000000..b8db9a2 --- /dev/null +++ b/src/WorkFlow.Infrastructure/Repositories/ProfileObjRepository.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using WorkFlow.Domain.Entities; + +namespace WorkFlow.Infrastructure.Repositories; + +/// +/// Repository implementation for retrieving entities from the database. +/// +public class ProfileObjRepository +{ + 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); +} \ No newline at end of file