Table of Contents

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

apiSettings IOptions<ApiSettings>

API settings containing collection names configuration.

database IMongoDatabase

The 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

Task

Delete(ObjectId)

Deletes a notice by its ID.

public Task Delete(ObjectId id)

Parameters

id ObjectId

The ObjectId of the notice to delete.

Returns

Task

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

date DateTime

The 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

displayId ObjectId

The 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

id ObjectId

The ObjectId of the notice to retrieve.

Returns

Task<Notice>

The Notice if found; otherwise, null.

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

type string

The 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

notice Notice

The Notice entity to insert.

Returns

Task

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

notice Notice

The Notice entity with updated values.

Returns

Task

Exceptions

Exception

Throws and re-throws exceptions after logging.