Class NoticeRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository implementation for managing Notice entities in MongoDB. Provides CRUD operations for notices/notifications that can be displayed on screens.
public class NoticeRepository : MongoRepository<Notice>, INoticeRepository, IMongoRepository<Notice>
- Inheritance
-
NoticeRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
NoticeRepository(IOptions<ApiSettings>?, IMongoDatabase)
Initializes a new instance of the NoticeRepository.
public NoticeRepository(IOptions<ApiSettings>? apiSettings, IMongoDatabase database)
Parameters
apiSettingsIOptions<ApiSettings>API settings containing collection names configuration.
databaseIMongoDatabaseThe MongoDB database instance.
Exceptions
- ArgumentNullException
Thrown when apiSettings is null.
Methods
CreateIndexes()
Creates the necessary indexes for the Notice collection. Creates compound indexes on (noticeType, noticeDate) and (noticeDate) for improved query performance.
public override Task CreateIndexes()
Returns
Delete(ObjectId)
Deletes a notice by its ID.
public Task Delete(ObjectId id)
Parameters
idObjectIdThe ObjectId of the notice to delete.
Returns
Exceptions
- Exception
Throws and re-throws exceptions after logging.
FindAll()
Retrieves all notices from the database.
public Task<IEnumerable<Notice>> FindAll()
Returns
- Task<IEnumerable<Notice>>
An enumerable of all Notice entities.
Exceptions
- Exception
Logs errors and returns empty list on failure.
FindByDate(DateTime)
Retrieves all notices for a specific date.
public Task<IEnumerable<Notice>?> FindByDate(DateTime date)
Parameters
dateDateTimeThe date to filter notices by.
Returns
- Task<IEnumerable<Notice>>
An enumerable of Notice entities matching the date, or null on error.
Exceptions
- Exception
Logs errors and returns null on failure.
FindByDisplayId(ObjectId)
Retrieves all notices associated with a specific display.
public Task<IEnumerable<Notice>?> FindByDisplayId(ObjectId displayId)
Parameters
displayIdObjectIdThe ObjectId of the display to filter by.
Returns
- Task<IEnumerable<Notice>>
An enumerable of Notice entities for the display, or null on error.
Exceptions
- Exception
Logs errors and returns null on failure.
FindById(ObjectId)
Retrieves a notice by its ID.
public Task<Notice?> FindById(ObjectId id)
Parameters
idObjectIdThe ObjectId of the notice to retrieve.
Returns
Exceptions
- Exception
Logs errors and returns null on failure.
FindByType(string)
Retrieves all notices of a specific type.
public Task<IEnumerable<Notice>?> FindByType(string type)
Parameters
typestringThe notice type to filter by.
Returns
- Task<IEnumerable<Notice>>
An enumerable of Notice entities matching the type, or null on error.
Exceptions
- Exception
Logs errors and returns null on failure.
GetCollectionName()
Gets the name of the collection for notices.
public override string GetCollectionName()
Returns
- string
The collection name from API settings.
InsertOneAsync(Notice)
Inserts a new notice into the database. Automatically sets the NoticeDate to UTC current date and time before inserting.
public override Task InsertOneAsync(Notice notice)
Parameters
noticeNoticeThe Notice entity to insert.
Returns
Exceptions
- Exception
Logs warning and silently fails on insertion error.
Update(Notice)
Updates an existing notice with new values.
public Task Update(Notice notice)
Parameters
noticeNoticeThe Notice entity with updated values.
Returns
Exceptions
- Exception
Throws and re-throws exceptions after logging.