rama creada apartir de master en j

This commit is contained in:
jrojas
2026-06-26 10:29:23 +02:00
parent 319fd3dfb0
commit c1517fda87
2810 changed files with 1927392 additions and 25392 deletions
@@ -12,21 +12,40 @@ using System.Text.RegularExpressions;
namespace adas_core.Infrastructure.Repositories;
/// <summary>
/// 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.
/// </summary>
public class CameraRepository : MongoRepository<Camera>, ICameraRepository
{
private readonly ApiSettings _apiSettings;
/// <summary>
/// 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.
/// </summary>
/// <param name="database">The MongoDB database instance.</param>
/// <param name="apiSettings">The API settings containing configuration for the repository.</param>
public CameraRepository(IMongoDatabase database, IOptions<ApiSettings> apiSettings) : base(database)
{
_apiSettings = apiSettings.Value;
}
/// <summary>
/// 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.
/// </summary>
/// <returns>The name of the MongoDB collection for cameras.</returns>
public override string GetCollectionName()
{
return _apiSettings.Cameras;
}
/// <summary>
/// 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.
/// </summary>
/// <param name="cameraId">The unique identifier of the camera to retrieve.</param>
/// <returns>The Camera object if found; otherwise, null.</returns>
public async Task<Camera?> GetById(ObjectId cameraId)
{
try
@@ -42,6 +61,11 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
}
}
/// <summary>
/// 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.
/// </summary>
/// <param name="name">The name of the camera to retrieve.</param>
/// <returns>The Camera object if found; otherwise, null.</returns>
public async Task<Camera?> GetByName(string name)
{
var filterBuilder = Builders<Camera>.Filter;
@@ -51,6 +75,12 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
return await Collection.Find(filter).FirstOrDefaultAsync();
}
/// <summary>
/// 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.
/// </summary>
/// <param name="configurationRelayList">The list of camera IDs to retrieve.</param>
/// <returns>A list of Camera objects that match the provided IDs.</returns>
public List<Camera> GetCameraInList(List<ObjectId> configurationRelayList)
{
var filterBuilder = Builders<Camera>.Filter;
@@ -61,6 +91,13 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
return Collection.Find(filter).ToList();
}
/// <summary>
/// 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.
/// </summary>
/// <param name="filter">The pagination filter containing page number, page size, and any additional filtering criteria.</param>
/// <returns>A paginated list of Camera objects.</returns>
/// <exception cref="BadRequestException">Thrown when the provided filter is invalid or contains invalid data.</exception>
public IFindFluent<Camera, Camera> GetPaginatedCameras(PaginationFilter filter)
{
var filterBuilder = Builders<Camera>.Filter;
@@ -90,6 +127,12 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
return CreateFindFluent(filters, sort);
}
/// <summary>
/// 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.
/// </summary>
/// <param name="camera">The Camera object to insert into the database.</param>
/// <returns>The inserted Camera object if successful; otherwise, null.</returns>
public async Task<Camera?> InsertOneCamera(Camera camera)
{
try
@@ -106,6 +149,12 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
}
}
/// <summary>
/// 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.
/// </summary>
/// <param name="objectId">The unique identifier of the camera to update.</param>
/// <param name="camera">The Camera object containing the updated information.</param>
/// <returns>The updated Camera object if successful; otherwise, null.</returns>
public async Task<Camera?> UpdateCameraAsync(ObjectId objectId, Camera camera)
{
var filter = Builders<Camera>.Filter.Eq("_id", objectId);
@@ -122,6 +171,13 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
new FindOneAndUpdateOptions<Camera, Camera> { ReturnDocument = ReturnDocument.After });
}
/// <summary>
/// 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.
/// </summary>
/// <param name="textToSearch">The text string to search for in the camera names.</param>
/// <returns>A list of Camera objects whose names match the search criteria.</returns>
/// <exception cref="BadRequestException">Thrown when the search text is too long.</exception>
public async Task<List<Camera>> GetSearchByNameCameras(string textToSearch)
{
if (string.IsNullOrWhiteSpace(textToSearch))
@@ -140,6 +196,12 @@ public class CameraRepository : MongoRepository<Camera>, ICameraRepository
return await Collection.Find(filter).ToListAsync();
}
/// <summary>
/// Creates an IFindFluent object for querying the MongoDB collection based on a list of filter definitions and a sort definition.
/// </summary>
/// <param name="filters">A list of filter definitions to apply to the query.</param>
/// <param name="sort">A sort definition to apply to the query results.</param>
/// <returns>An IFindFluent object for further query customization or execution.</returns>
private IFindFluent<Camera, Camera> CreateFindFluent(List<FilterDefinition<Camera>> filters, SortDefinition<Camera> sort)
{
var combinedFilter = filters.Any()