Class DisplayRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository implementation for managing Display entities in MongoDB. Provides CRUD operations and specialized queries for display devices.
public class DisplayRepository : MongoRepository<Display>, IDisplayRepository, IMongoRepository<Display>
- Inheritance
-
DisplayRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
DisplayRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<DisplayRepository>)
Initializes a new instance of the DisplayRepository.
public DisplayRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<DisplayRepository> logger)
Parameters
apiSettingsIOptions<ApiSettings>API settings containing collection names configuration.
databaseIMongoDatabaseThe MongoDB database instance.
loggerILogger<DisplayRepository>Logger for repository operations.
Methods
CountByUnitId(ObjectId)
Counts the number of displays associated with a specific unit.
public Task<long> CountByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe ObjectId of the unit.
Returns
Exceptions
- Exception
Logs errors and returns 0 on failure.
CreateIndexes()
Creates the necessary indexes for the Display collection. Creates indexes on displayConfigId and unitId fields for improved query performance.
public override Task CreateIndexes()
Returns
DeleteManyByUnitId(ObjectId)
Deletes all displays associated with a specific unit.
public Task<bool> DeleteManyByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe ObjectId of the unit whose displays should be deleted.
Returns
Exceptions
- Exception
Logs errors and returns false on failure.
GetAll()
Retrieves all displays from the database.
public Task<List<Display>> GetAll()
Returns
GetByCardConfigId(ObjectId)
Retrieves all displays that use a specific card configuration through their display configuration. Performs an aggregation to join Display with DisplayConfig and filter by cardConfigId.
public Task<List<Display>> GetByCardConfigId(ObjectId configId)
Parameters
configIdObjectIdThe ObjectId of the card configuration.
Returns
- Task<List<Display>>
A list of Display entities using the specified card config, or empty list on error.
Exceptions
- Exception
Logs errors and returns empty list on failure.
GetByConfigId(ObjectId)
Retrieves all displays associated with a specific display configuration.
public Task<List<Display>> GetByConfigId(ObjectId id)
Parameters
idObjectIdThe ObjectId of the display configuration.
Returns
GetById(ObjectId)
Retrieves a display by its ID.
public Task<Display?> GetById(ObjectId id)
Parameters
idObjectIdThe ObjectId of the display to retrieve.
Returns
GetByIdWithConfigDisplay(ObjectId)
Retrieves a display by its ID with the associated display configuration. Performs a MongoDB lookup to join the display with its configuration.
public Task<Display?> GetByIdWithConfigDisplay(ObjectId id)
Parameters
idObjectIdThe ObjectId of the display to retrieve.
Returns
GetByName(string)
Retrieves a display by its name.
public Task<Display?> GetByName(string name)
Parameters
namestringThe name of the display to retrieve.
Returns
GetByPointOfCare(PointOfCare)
Retrieves all displays associated with a specific point of care.
public Task<List<Display>> GetByPointOfCare(PointOfCare pointOfCare)
Parameters
pointOfCarePointOfCareThe PointOfCare to filter by.
Returns
GetByUnitId(ObjectId)
Retrieves all displays associated with a specific unit.
public Task<List<Display>> GetByUnitId(ObjectId id)
Parameters
idObjectIdThe ObjectId of the unit.
Returns
GetCollectionName()
Gets the name of the collection for displays.
public override string GetCollectionName()
Returns
- string
The collection name from API settings.
GetPaginatedDisplays(PaginationFilter)
Retrieves paginated displays with optional filtering. Supports filtering by text, unit ID, unit name, and display type.
public IFindFluent<Display, Display> GetPaginatedDisplays(PaginationFilter filter)
Parameters
filterPaginationFilterThe pagination and filtering parameters.
Returns
Exceptions
- BadRequestException
Thrown when the text filter exceeds 100 characters.
IsDisplayConfigInUse(ObjectId)
Checks if a display configuration is currently in use by any displays.
public Task<long> IsDisplayConfigInUse(ObjectId displayConfigId)
Parameters
displayConfigIdObjectIdThe ObjectId of the display configuration to check.
Returns
UpdateConfig(ObjectId, DisplayConfig)
Updates the display configuration for a specific display.
public Task<Display?> UpdateConfig(ObjectId objectId, DisplayConfig config)
Parameters
objectIdObjectIdThe ObjectId of the display to update.
configDisplayConfigThe new DisplayConfig to set.
Returns
Exceptions
- Exception
Logs errors and returns null on failure.
UpdateConfigId(ObjectId, ObjectId)
Updates the display configuration ID reference for a specific display.
public Task<Display?> UpdateConfigId(ObjectId objectId, ObjectId displayConfigId)
Parameters
objectIdObjectIdThe ObjectId of the display to update.
displayConfigIdObjectIdThe new display configuration ObjectId to set.
Returns
Exceptions
- Exception
Logs errors and returns null on failure.
UpdateConfigPreset(ObjectId, ObjectId)
Updates the display configuration preset for a specific display.
public Task<Display?> UpdateConfigPreset(ObjectId objectIdDisplay, ObjectId objectIdConfigDisplay)
Parameters
objectIdDisplayObjectIdThe ObjectId of the display to update.
objectIdConfigDisplayObjectIdThe ObjectId of the display configuration preset.
Returns
Exceptions
- Exception
Logs errors and returns null on failure.
UpdateName(Display, string)
Updates the name of a specific display.
public Task<Display> UpdateName(Display display, string name)
Parameters
Returns
Exceptions
- Exception
Throws an exception if MongoDB update fails.
UpdatePointOfCareList(ObjectId, List<ObjectId>)
Updates the point of care list for a specific display.
public Task<Display?> UpdatePointOfCareList(ObjectId objectId, List<ObjectId> listPocObId)
Parameters
objectIdObjectIdThe ObjectId of the display to update.
listPocObIdList<ObjectId>The new list of point of care ObjectIds.
Returns
Exceptions
- Exception
Logs errors and returns null on failure.