using Dapper; using SIGCM.Domain.Entities; using SIGCM.Domain.Interfaces; using SIGCM.Infrastructure.Data; namespace SIGCM.Infrastructure.Repositories; public class ImageRepository : IImageRepository { private readonly IDbConnectionFactory _connectionFactory; public ImageRepository(IDbConnectionFactory connectionFactory) { _connectionFactory = connectionFactory; } public async Task AddAsync(ListingImage image) { using var conn = _connectionFactory.CreateConnection(); var sql = @" INSERT INTO ListingImages (ListingId, Url, IsMainInfo, DisplayOrder) VALUES (@ListingId, @Url, @IsMainInfo, @DisplayOrder)"; await conn.ExecuteAsync(sql, image); } public async Task> GetByListingIdAsync(int listingId) { using var conn = _connectionFactory.CreateConnection(); return await conn.QueryAsync( "SELECT * FROM ListingImages WHERE ListingId = @ListingId ORDER BY DisplayOrder", new { ListingId = listingId }); } }