Fase 3: Soporte de Imágenes en Wizard y Backend (Upload Local)
This commit is contained in:
@@ -154,6 +154,18 @@ BEGIN
|
||||
FOREIGN KEY (AttributeDefinitionId) REFERENCES AttributeDefinitions(Id) ON DELETE NO ACTION
|
||||
);
|
||||
END
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'ListingImages')
|
||||
BEGIN
|
||||
CREATE TABLE ListingImages (
|
||||
Id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
ListingId INT NOT NULL,
|
||||
Url NVARCHAR(500) NOT NULL,
|
||||
IsMainInfo BIT DEFAULT 0,
|
||||
DisplayOrder INT DEFAULT 0,
|
||||
FOREIGN KEY (ListingId) REFERENCES Listings(Id) ON DELETE CASCADE
|
||||
);
|
||||
END
|
||||
";
|
||||
await connection.ExecuteAsync(schemaSql);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public static class DependencyInjection
|
||||
services.AddScoped<IAuthService, Services.AuthService>();
|
||||
services.AddScoped<IAttributeDefinitionRepository, AttributeDefinitionRepository>();
|
||||
services.AddScoped<IListingRepository, ListingRepository>();
|
||||
services.AddScoped<IImageRepository, ImageRepository>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
33
src/SIGCM.Infrastructure/Repositories/ImageRepository.cs
Normal file
33
src/SIGCM.Infrastructure/Repositories/ImageRepository.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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<IEnumerable<ListingImage>> GetByListingIdAsync(int listingId)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
return await conn.QueryAsync<ListingImage>(
|
||||
"SELECT * FROM ListingImages WHERE ListingId = @ListingId ORDER BY DisplayOrder",
|
||||
new { ListingId = listingId });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user