Class NoticeService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
public class NoticeService : INoticeService
- Inheritance
-
NoticeService
- Implements
- Inherited Members
- Extension Methods
Constructors
NoticeService(ILogger<NoticeService>, ISubscribersService, INoticeRepository, IClientMessageService, IDisplayService, IHttpContextAccessor, ILocalAuditService)
public NoticeService(ILogger<NoticeService> logger, ISubscribersService subscribersService, INoticeRepository noticeRepository, IClientMessageService clientMessageService, IDisplayService displayService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService)
Parameters
loggerILogger<NoticeService>subscribersServiceISubscribersServicenoticeRepositoryINoticeRepositoryclientMessageServiceIClientMessageServicedisplayServiceIDisplayServicehttpContextAccessorIHttpContextAccessorauditServiceILocalAuditService
Methods
DeleteNoticeAsync(Notice)
Deletes the specified notice by delegating to the ID-based deletion routine.
public Task DeleteNoticeAsync(Notice notice)
Parameters
noticeNoticeThe notice to delete; its
Idis used to identify the record to remove.
Returns
DeleteNoticeByIdAsync(ObjectId)
Deletes a notice identified by its unique ID, creating an audit log entry and broadcasting the deletion when successful. If the notice is not found, the operation is logged and the method returns without making changes; any unexpected exception is logged without being rethrown.
public Task DeleteNoticeByIdAsync(ObjectId noticeId)
Parameters
noticeIdObjectIdThe unique identifier of the notice to delete.
Returns
GetNoticeByIdAsync(ObjectId)
Retrieves a notice by its unique identifier asynchronously. Returns null if an error occurs during the lookup, with the exception being logged.
public Task<Notice?> GetNoticeByIdAsync(ObjectId noticeId)
Parameters
noticeIdObjectIdThe unique MongoDB.Bson.ObjectId of the notice to retrieve.
Returns
- Task<Notice>
A Notice instance if found; otherwise,
nullwhen an exception is thrown during the search.
GetNoticeByTypeAsync(string)
Asynchronously retrieves a collection of notices filtered by the specified notice type. If no notices are found for the given type, a NotFoundException is thrown.
public Task<IEnumerable<Notice>?> GetNoticeByTypeAsync(string noticeType)
Parameters
noticeTypestringThe type of notice to filter the search by.
Returns
- Task<IEnumerable<Notice>>
A task that represents the asynchronous operation, containing a collection of Notice objects matching the specified type.
Exceptions
- NotFoundException
Thrown when no notices are found for the specified
noticeType.
GetNoticesAsync()
Retrieves all notices from the repository asynchronously.
public Task<IEnumerable<Notice>> GetNoticesAsync()
Returns
- Task<IEnumerable<Notice>>
A task that represents the asynchronous operation. The task result contains a collection of all Notice entities.
GetNoticesByDisplayId(ObjectId)
Retrieves a collection of notices associated with the specified display identifier. Returns null if an error occurs while querying the notice repository.
public Task<IEnumerable<Notice>?> GetNoticesByDisplayId(ObjectId displayId)
Parameters
displayIdObjectIdThe ObjectId of the display used to look up associated notices.
Returns
- Task<IEnumerable<Notice>>
A task containing an IEnumerable<T> of Notice objects matching the display, or null if the operation fails.
InsertNotice(Notice)
Inserts a new notice, creates an audit log entry, and broadcasts a notification about the new notice. Returns null if an exception occurs during the operation.
public Task<Notice?> InsertNotice(Notice notice)
Parameters
noticeNoticeThe notice to insert. A new identifier is assigned before persistence.
Returns
- Task<Notice>
The inserted notice with its newly assigned identifier, or null if the operation fails.
SaveRequest(ApiRequest)
Processes an API request to create, update, or delete a notice based on the request type. Validates required fields for new and updated notices, skips processing when the notice or its description is missing, and logs any exceptions encountered.
public Task SaveRequest(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request containing the notice payload and the operation type (NewNotice, UpdateNotice, or DeleteNotice) to perform.
Returns
SaveRequestAsync(ApiRequest)
Asynchronously saves the specified API request by executing the save operation on a background thread.
public Task SaveRequestAsync(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request to save.
Returns
- Task
A task that represents the asynchronous save operation.
UpdateNoticeAsync(Notice)
Updates an existing notice, records an audit log entry, and broadcasts the update notification. If no notice is found by the supplied identifier, a conflict exception is thrown. Errors are caught and logged.
public Task UpdateNoticeAsync(Notice notice)
Parameters
noticeNoticeThe notice entity containing the updated data.
Returns
Exceptions
- ConflictException
Thrown when the notice cannot be found in the repository.