Fase 2: Gestión de Atributos Dinámicos (Back & Front EAV Definition)
This commit is contained in:
@@ -111,6 +111,18 @@ BEGIN
|
||||
FOREIGN KEY (OperationId) REFERENCES Operations(Id) ON DELETE CASCADE
|
||||
);
|
||||
END
|
||||
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'AttributeDefinitions')
|
||||
BEGIN
|
||||
CREATE TABLE AttributeDefinitions (
|
||||
Id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
CategoryId INT NOT NULL,
|
||||
Name NVARCHAR(100) NOT NULL,
|
||||
DataType NVARCHAR(20) NOT NULL,
|
||||
Required BIT DEFAULT 0,
|
||||
FOREIGN KEY (CategoryId) REFERENCES Categories(Id) ON DELETE CASCADE
|
||||
);
|
||||
END
|
||||
";
|
||||
await connection.ExecuteAsync(schemaSql);
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ public static class DependencyInjection
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
services.AddScoped<ITokenService, Services.TokenService>();
|
||||
services.AddScoped<IAuthService, Services.AuthService>();
|
||||
services.AddScoped<IAttributeDefinitionRepository, AttributeDefinitionRepository>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using SIGCM.Domain.Entities;
|
||||
using SIGCM.Domain.Interfaces;
|
||||
using SIGCM.Infrastructure.Data;
|
||||
|
||||
namespace SIGCM.Infrastructure.Repositories;
|
||||
|
||||
public class AttributeDefinitionRepository : IAttributeDefinitionRepository
|
||||
{
|
||||
private readonly IDbConnectionFactory _connectionFactory;
|
||||
|
||||
public AttributeDefinitionRepository(IDbConnectionFactory connectionFactory)
|
||||
{
|
||||
_connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AttributeDefinition>> GetByCategoryIdAsync(int categoryId)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
return await conn.QueryAsync<AttributeDefinition>(
|
||||
"SELECT * FROM AttributeDefinitions WHERE CategoryId = @CategoryId",
|
||||
new { CategoryId = categoryId });
|
||||
}
|
||||
|
||||
public async Task<int> AddAsync(AttributeDefinition attribute)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
var sql = @"
|
||||
INSERT INTO AttributeDefinitions (CategoryId, Name, DataType, Required)
|
||||
VALUES (@CategoryId, @Name, @DataType, @Required);
|
||||
SELECT CAST(SCOPE_IDENTITY() as int);";
|
||||
return await conn.QuerySingleAsync<int>(sql, attribute);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
using var conn = _connectionFactory.CreateConnection();
|
||||
await conn.ExecuteAsync("DELETE FROM AttributeDefinitions WHERE Id = @Id", new { Id = id });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user