Table of Contents

Class CameraRepository

Namespace
adas_core.Infrastructure.Repositories
Assembly
adas-core.Infrastructure.dll

Repository for managing camera entities in the MongoDB database. This repository provides methods to create, retrieve, update, and search for cameras based on various criteria. It also includes error handling and logging for debugging purposes.

public class CameraRepository : MongoRepository<Camera>, ICameraRepository, IMongoRepository<Camera>
Inheritance
CameraRepository
Implements
Inherited Members
Extension Methods

Constructors

CameraRepository(IMongoDatabase, IOptions<ApiSettings>)

Initializes a new instance of the CameraRepository class with the specified MongoDB database and API settings. The constructor sets up the repository to interact with the "Cameras" collection in the database and allows for configuration through the provided API settings.

public CameraRepository(IMongoDatabase database, IOptions<ApiSettings> apiSettings)

Parameters

database IMongoDatabase

The MongoDB database instance.

apiSettings IOptions<ApiSettings>

The API settings containing configuration for the repository.

Methods

GetById(ObjectId)

Retrieves a camera entity from the MongoDB database based on its unique identifier. The method takes an ObjectId as a parameter and returns the corresponding Camera object if found, or null if no matching camera is found. It also includes error handling to log any exceptions that occur during the retrieval process.

public Task<Camera?> GetById(ObjectId cameraId)

Parameters

cameraId ObjectId

The unique identifier of the camera to retrieve.

Returns

Task<Camera>

The Camera object if found; otherwise, null.

GetByName(string)

Retrieves a camera entity from the MongoDB database based on its name. The method takes a string parameter representing the name of the camera and returns the corresponding Camera object if found, or null if no matching camera is found.

public Task<Camera?> GetByName(string name)

Parameters

name string

The name of the camera to retrieve.

Returns

Task<Camera>

The Camera object if found; otherwise, null.

GetCameraInList(List<ObjectId>)

Retrieves a list of camera entities from the MongoDB database based on a list of unique identifiers. The method takes a list of ObjectId values representing the camera IDs and returns a list of Camera objects that match any of the provided IDs.

public List<Camera> GetCameraInList(List<ObjectId> configurationRelayList)

Parameters

configurationRelayList List<ObjectId>

The list of camera IDs to retrieve.

Returns

List<Camera>

A list of Camera objects that match the provided IDs.

GetCollectionName()

Gets the name of the MongoDB collection that this repository interacts with. In this case, it returns the collection name for cameras as specified in the API settings.

public override string GetCollectionName()

Returns

string

The name of the MongoDB collection for cameras.

GetPaginatedCameras(PaginationFilter)

Retrieves a paginated list of camera entities from the MongoDB database based on the provided pagination filter. The method takes a PaginationFilter object as a parameter, which contains information about the page number, page size, and any additional filtering criteria.

public IFindFluent<Camera, Camera> GetPaginatedCameras(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination filter containing page number, page size, and any additional filtering criteria.

Returns

IFindFluent<Camera, Camera>

A paginated list of Camera objects.

Exceptions

BadRequestException

Thrown when the provided filter is invalid or contains invalid data.

GetSearchByNameCameras(string)

Searches for camera entities in the MongoDB database based on a text string that matches the camera's name. The method takes a string parameter representing the text to search for and returns a list of Camera objects whose names match the search criteria.

public Task<List<Camera>> GetSearchByNameCameras(string textToSearch)

Parameters

textToSearch string

The text string to search for in the camera names.

Returns

Task<List<Camera>>

A list of Camera objects whose names match the search criteria.

Exceptions

BadRequestException

Thrown when the search text is too long.

InsertOneCamera(Camera)

Inserts a new camera entity into the MongoDB database. The method takes a Camera object as a parameter and attempts to insert it into the collection.

public Task<Camera?> InsertOneCamera(Camera camera)

Parameters

camera Camera

The Camera object to insert into the database.

Returns

Task<Camera>

The inserted Camera object if successful; otherwise, null.

UpdateCameraAsync(ObjectId, Camera)

Updates an existing camera entity in the MongoDB database based on its unique identifier. The method takes an ObjectId representing the camera ID and a Camera object containing the updated information.

public Task<Camera?> UpdateCameraAsync(ObjectId objectId, Camera camera)

Parameters

objectId ObjectId

The unique identifier of the camera to update.

camera Camera

The Camera object containing the updated information.

Returns

Task<Camera>

The updated Camera object if successful; otherwise, null.