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
databaseIMongoDatabaseThe MongoDB database instance.
apiSettingsIOptions<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
cameraIdObjectIdThe unique identifier of the camera to retrieve.
Returns
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
namestringThe name of the camera to retrieve.
Returns
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
configurationRelayListList<ObjectId>The list of camera IDs to retrieve.
Returns
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
filterPaginationFilterThe pagination filter containing page number, page size, and any additional filtering criteria.
Returns
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
textToSearchstringThe text string to search for in the camera names.
Returns
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
cameraCameraThe Camera object to insert into the database.
Returns
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
objectIdObjectIdThe unique identifier of the camera to update.
cameraCameraThe Camera object containing the updated information.