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
@@ -7,6 +7,10 @@ using MongoDB.Driver;
namespace adas_core.Infrastructure.Repositories
{
/// <summary>
/// Provides a repository implementation for <see cref="PumpState"/> entities backed by a MongoDB data store.
/// </summary>
/// <remarks>Inherits base functionality from <see cref="MongoRepository{T}"/> and implements the <see cref="IPumpStateRepository"/> contract.</remarks>
public class PumpStateRepository : MongoRepository<PumpState>, IPumpStateRepository
{
private readonly ApiSettings _apiSettings;
@@ -18,10 +22,14 @@ namespace adas_core.Infrastructure.Repositories
}
/// <summary>
/// Retrieves the collection name for pump states, returning the configured value from API settings or the default name "pump_states" when the setting is not provided.
/// </summary>
/// <returns>The configured pump states collection name, or the default value "pump_states" if the setting is null.</returns>
public override string GetCollectionName()
{
return _apiSettings.PumpStates ?? "pump_states";
}
{
return _apiSettings.PumpStates ?? "pump_states";
}
public override async Task CreateIndexes()
{
@@ -48,32 +56,45 @@ namespace adas_core.Infrastructure.Repositories
await Collection.Indexes.CreateManyAsync(indexModels);
}
/// <summary>
/// Retrieves the pump state associated with the specified device identifier, returning null when no matching record exists.
/// </summary>
/// <param name="deviceId">The unique identifier of the device whose pump state should be looked up.</param>
/// <returns>A <see cref="PumpState"/> instance if a matching record is found; otherwise, null.</returns>
public async Task<PumpState?> FindByDeviceIdAsync(string deviceId)
{
return await Collection.Find(x => x.DeviceId == deviceId).FirstOrDefaultAsync();
}
{
return await Collection.Find(x => x.DeviceId == deviceId).FirstOrDefaultAsync();
}
/// <summary>
/// Inserts the specified <see cref="PumpState"/> or updates the existing one identified by its <c>DeviceId</c>. If a matching record is found, its identifier is reused; otherwise a new identifier is generated when the provided one is empty.
/// </summary>
/// <param name="state">The pump state to persist. Its <c>Id</c> is preserved or assigned based on whether a record with the same <c>DeviceId</c> already exists.</param>
public async Task UpsertAsync(PumpState state)
{
var existing = await Collection
.Find(x => x.DeviceId == state.DeviceId)
.FirstOrDefaultAsync();
if (existing != null)
state.Id = existing.Id;
else
if (state.Id == ObjectId.Empty)
state.Id = ObjectId.GenerateNewId();
await Collection.ReplaceOneAsync(
x => x.DeviceId == state.DeviceId,
state,
new ReplaceOptions { IsUpsert = true });
}
{
var existing = await Collection
.Find(x => x.DeviceId == state.DeviceId)
.FirstOrDefaultAsync();
if (existing != null)
state.Id = existing.Id;
else
if (state.Id == ObjectId.Empty)
state.Id = ObjectId.GenerateNewId();
await Collection.ReplaceOneAsync(
x => x.DeviceId == state.DeviceId,
state,
new ReplaceOptions { IsUpsert = true });
}
/// <summary>
/// Asynchronously retrieves all <see cref="PumpState"/> records from the data store.
/// </summary>
/// <returns>A task that represents the asynchronous operation, containing an <see cref="IEnumerable{T}"/> of all <see cref="PumpState"/> records; an empty collection is returned if no records exist.</returns>
public async Task<IEnumerable<PumpState>> GetAllAsync()
{
return await Collection.Find(Builders<PumpState>.Filter.Empty).ToListAsync();
}
{
return await Collection.Find(Builders<PumpState>.Filter.Empty).ToListAsync();
}
}
}