Class HistoricalConfigChangesRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository implementation for managing HistoricalConfigChanges entities in MongoDB. Provides CRUD operations and specialized queries for tracking configuration changes over time.
public class HistoricalConfigChangesRepository : MongoRepository<HistoricalConfigChanges>, IHistoricalConfigChangesRepository, IMongoRepository<HistoricalConfigChanges>
- Inheritance
-
HistoricalConfigChangesRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
HistoricalConfigChangesRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<HistoricalConfigChangesRepository>)
Initializes a new instance of the HistoricalConfigChangesRepository.
public HistoricalConfigChangesRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<HistoricalConfigChangesRepository> logger)
Parameters
apiSettingsIOptions<ApiSettings>API settings containing collection names configuration.
databaseIMongoDatabaseThe MongoDB database instance.
loggerILogger<HistoricalConfigChangesRepository>Logger for repository operations.
Exceptions
- ArgumentNullException
Thrown when apiSettings is null.
Methods
CreateIndexes()
Creates the necessary indexes for the HistoricalConfigChanges collection. Creates compound indexes on (configType, time) and (username, time) for improved query performance.
public override Task CreateIndexes()
Returns
Exceptions
- Exception
Throws an exception if index creation fails; logs error details before throwing.
Delete(ObjectId)
Deletes a historical configuration change record by its ID.
public Task<HistoricalConfigChanges?> Delete(ObjectId id)
Parameters
idObjectIdThe ObjectId of the record to delete.
Returns
- Task<HistoricalConfigChanges>
The deleted HistoricalConfigChanges if found; otherwise, null.
FindAll()
Retrieves all historical configuration change records.
public Task<ICollection<HistoricalConfigChanges>> FindAll()
Returns
- Task<ICollection<HistoricalConfigChanges>>
A collection of all HistoricalConfigChanges entities.
FindAllIds()
Retrieves all IDs of historical configuration change records.
public Task<List<ObjectId>> FindAllIds()
Returns
FindById(ObjectId)
Retrieves a historical configuration change record by its ID.
public Task<HistoricalConfigChanges?> FindById(ObjectId id)
Parameters
idObjectIdThe ObjectId of the record to retrieve.
Returns
- Task<HistoricalConfigChanges>
The HistoricalConfigChanges if found; otherwise, null.
FindLastHistoricalConfigChangesByType(ConfigTypes, int)
Retrieves the most recent historical configuration changes for a specific configuration type. Results are sorted by time in descending order.
public Task<ICollection<HistoricalConfigChanges>> FindLastHistoricalConfigChangesByType(DisplayConfigEnums.ConfigTypes cfgType, int num = 10)
Parameters
cfgTypeDisplayConfigEnums.ConfigTypesThe type of configuration to filter by.
numintThe maximum number of records to retrieve. Default is 10.
Returns
- Task<ICollection<HistoricalConfigChanges>>
A collection of the most recent HistoricalConfigChanges for the specified type.
FindLastHistoricalConfigChangesByUser(string, ConfigTypes?, int)
Retrieves the most recent historical configuration changes for a specific user. Optionally filters by configuration type. Results are sorted by time in descending order.
public Task<ICollection<HistoricalConfigChanges>> FindLastHistoricalConfigChangesByUser(string user, DisplayConfigEnums.ConfigTypes? cfgType = null, int num = 10)
Parameters
userstringThe username to filter by.
cfgTypeDisplayConfigEnums.ConfigTypes?Optional configuration type to filter by. If null, all types are included.
numintThe maximum number of records to retrieve. Default is 10.
Returns
- Task<ICollection<HistoricalConfigChanges>>
A collection of the most recent HistoricalConfigChanges for the specified user.
GetCollectionName()
Gets the name of the collection for historical configuration changes.
public override string GetCollectionName()
Returns
- string
The collection name from API settings, or default "historicalConfigChanges".
InsertOneAsync(HistoricalConfigChanges)
Inserts a new historical configuration change record and returns the inserted document.
public override Task<HistoricalConfigChanges?> InsertOneAsync(HistoricalConfigChanges historicalConfigChanges)
Parameters
historicalConfigChangesHistoricalConfigChangesThe HistoricalConfigChanges entity to insert.
Returns
- Task<HistoricalConfigChanges>
The inserted HistoricalConfigChanges with generated ID, or null if insertion fails.
Exceptions
- Exception
Logs errors and returns null on failure.
Update(HistoricalConfigChanges)
Updates an existing historical configuration change record.
public Task<HistoricalConfigChanges?> Update(HistoricalConfigChanges historicalConfigChanges)
Parameters
historicalConfigChangesHistoricalConfigChangesThe HistoricalConfigChanges with updated values.
Returns
- Task<HistoricalConfigChanges>
The updated HistoricalConfigChanges if successful; otherwise, null.