rama creada apartir de master en j

This commit is contained in:
jrojas
2026-06-26 10:29:23 +02:00
parent 319fd3dfb0
commit c1517fda87
2810 changed files with 1927392 additions and 25392 deletions
@@ -19,6 +19,10 @@ public class HistoricalConfigChangesService(
{
private readonly ILogger<HistoricalConfigChangesService> _logger = logger;
/// <summary>
/// Deletes a historical configuration change record by its identifier and creates an audit log entry recording the deletion.
/// </summary>
/// <param name="id">The unique identifier of the historical configuration change to delete.</param>
public async Task DeleteHistoricalConfigChange(ObjectId id)
{
var filter = Builders<HistoricalConfigChanges>.Filter.Eq("_id", id);
@@ -28,6 +32,11 @@ public class HistoricalConfigChangesService(
await auditService.CreateAuditLogAsync(httpContextAccessor.HttpContext?.User!, result, null);
}
/// <summary>
/// Retrieves the most recent historical configuration change entry for the specified configuration type.
/// </summary>
/// <param name="configType">The configuration type used to look up the last historical change.</param>
/// <returns>The most recent <see cref="HistoricalConfigChanges"/> entry, or <c>null</c> if no changes exist for the given type.</returns>
public async Task<HistoricalConfigChanges?> FindLastConfigChanges(DisplayConfigEnums.ConfigTypes configType)
{
var result = await historicalConfigChangesRepository.FindLastHistoricalConfigChangesByType(configType);
@@ -35,28 +44,58 @@ public class HistoricalConfigChangesService(
return result.FirstOrDefault();
}
/// <summary>
/// Retrieves a historical configuration change record by its unique identifier.
/// Returns null when no matching record is found in the repository.
/// </summary>
/// <param name="id">The unique identifier of the historical configuration change to retrieve.</param>
/// <returns>The matching <see cref="HistoricalConfigChanges"/> record, or null if no record is found.</returns>
public async Task<HistoricalConfigChanges?> Get(ObjectId id)
{
return await historicalConfigChangesRepository.FindById(id);
}
/// <summary>
/// Retrieves all historical configuration changes from the repository.
/// </summary>
/// <returns>A task that represents the asynchronous operation, containing a collection of all <see cref="HistoricalConfigChanges"/> records.</returns>
public async Task<ICollection<HistoricalConfigChanges>> GetAll()
{
return await historicalConfigChangesRepository.FindAll();
}
/// <summary>
/// Retrieves the most recent historical configuration changes for the specified configuration type, limited to a given number of entries.
/// </summary>
/// <param name="type">The configuration type used to filter the historical changes.</param>
/// <param name="num">The maximum number of recent changes to return. Defaults to 10.</param>
/// <returns>A collection of the latest <see cref="HistoricalConfigChanges"/> entries matching the specified type.</returns>
public async Task<ICollection<HistoricalConfigChanges>> GetByType(DisplayConfigEnums.ConfigTypes type, int num = 10)
{
return await historicalConfigChangesRepository.FindLastHistoricalConfigChangesByType(type, num);
}
/// <summary>
/// Retrieves the most recent historical configuration changes for a given user, optionally filtered by configuration type and limited to a specified maximum number of entries.
/// </summary>
/// <param name="user">The identifier of the user whose historical configuration changes are being retrieved.</param>
/// <param name="configTypes">Optional filter for the configuration type; when null, all configuration types are included.</param>
/// <param name="num">The maximum number of historical change entries to return. Defaults to 10.</param>
/// <returns>A task that represents the asynchronous operation, containing a collection of the user's historical configuration changes.</returns>
public async Task<ICollection<HistoricalConfigChanges>> GetByUser(string user,
DisplayConfigEnums.ConfigTypes? configTypes = null, int num = 10)
DisplayConfigEnums.ConfigTypes? configTypes = null, int num = 10)
{
return await historicalConfigChangesRepository.FindLastHistoricalConfigChangesByUser(user, configTypes, num);
}
/// <summary>
/// Inserts a new historical configuration change record into the repository and creates a corresponding audit log entry.
/// If the repository returns null, a conflict exception is thrown; on failure, the error is logged and null is returned.
/// </summary>
/// <param name="historicalConfigChanges">The historical configuration change entity to insert.</param>
/// <returns>The inserted <see cref="HistoricalConfigChanges"/> entity, or null if the operation fails.</returns>
/// <exception cref="ConflictException">Thrown when the repository returns null after the insert operation.</exception>
public async Task<HistoricalConfigChanges?> InsertOne(HistoricalConfigChanges historicalConfigChanges)
{
try
@@ -74,8 +113,15 @@ public class HistoricalConfigChangesService(
}
}
/// <summary>
/// Updates an existing historical configuration change record, creating an audit log entry for the change.
/// If the record is not found, a <see cref="ConflictException"/> is thrown; any other exception is logged and the method returns <c>null</c>.
/// </summary>
/// <param name="historicalConfigChanges">The historical configuration change entity containing the updated values to persist.</param>
/// <returns>The updated <see cref="HistoricalConfigChanges"/> entity on success, or <c>null</c> if an error occurs during the operation.</returns>
/// <exception cref="ConflictException">Thrown when no existing historical configuration change is found with the specified <c>Id</c>.</exception>
public async Task<HistoricalConfigChanges?> UpdateHistoricalConfigChange(
HistoricalConfigChanges historicalConfigChanges)
HistoricalConfigChanges historicalConfigChanges)
{
try
{
@@ -93,8 +139,17 @@ public class HistoricalConfigChangesService(
}
}
/// <summary>
/// Asynchronously logs a change to a display configuration, recording the user who made the change,
/// the configuration type, the previous value, and the new value. Logs an error if the insertion fails,
/// or a debug message if it succeeds.
/// </summary>
/// <param name="user">The username of the user who made the configuration change.</param>
/// <param name="configType">The type of configuration that was changed.</param>
/// <param name="newConfig">The new configuration value after the change.</param>
/// <param name="oldConfig">The previous configuration value before the change.</param>
public async Task LogConfigChanged(string user, DisplayConfigEnums.ConfigTypes configType, string newConfig,
string oldConfig)
string oldConfig)
{
HistoricalConfigChanges historicalConfigChanges = new()
{