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,6 +12,10 @@ using Newtonsoft.Json;
namespace adas_core.Application.Services;
/// <summary>
/// Provides an implementation of the <see cref="IAuthService"/> interface, offering
/// authentication-related services to consuming components.
/// </summary>
public class AuthService : IAuthService
{
private readonly IAuthorityRepository _authorityRepository;
@@ -33,6 +37,10 @@ public class AuthService : IAuthService
_ = InstanceAuthUtils();
}
/// <summary>
/// Asynchronously obtains a login token from the recording API using the configured client credentials and caches it for reuse via <see cref="AuthUtils"/>.
/// </summary>
/// <returns>A <see cref="LoginResponse"/> containing the authentication token when the request succeeds and the response is valid; otherwise, <c>null</c> if the API URL is not configured, the request fails, the returned token is empty, or an exception is caught and logged.</returns>
public async Task<LoginResponse?> GetLoginResponse()
{
try
@@ -79,6 +87,11 @@ public class AuthService : IAuthService
}
}
/// <summary>
/// Retrieves an authentication token, returning the cached token if it is not empty or expired.
/// Otherwise, attempts a fresh login and returns the new token, falling back to an empty string when no token is obtained.
/// </summary>
/// <returns>A task that resolves to the authentication token, or an empty string if the token could not be obtained.</returns>
public async Task<string> GetToken()
{
var loginResponse = AuthUtils.Instance.GetLoginResponse();
@@ -89,26 +102,49 @@ public class AuthService : IAuthService
return "";
}
/// <summary>
/// Retrieves a list of authorizations associated with the specified unit identifier by delegating to the authority repository.
/// </summary>
/// <param name="unitId">The unique identifier of the unit whose authorizations are being retrieved.</param>
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="Authorization"/> objects for the specified unit.</returns>
public async Task<List<Authorization>> GetByUnitId(ObjectId unitId)
{
return await _authorityRepository.GetByUnitId(unitId);
}
/// <summary>
/// Retrieves the list of authorizations associated with the specified user identifier.
/// </summary>
/// <param name="id">The unique identifier of the user whose authorities are being requested.</param>
/// <returns>A task that represents the asynchronous operation, containing a list of <see cref="Authorization"/> entries for the user.</returns>
public async Task<List<Authorization>> GetUserAuthorities(ObjectId id)
{
return await _authorityRepository.GetUserAuthorities(id);
}
/// <summary>
/// Deletes all authorities associated with the specified unit identifier by delegating to the authority repository.
/// </summary>
/// <param name="unitId">The identifier of the unit whose authorities are to be removed.</param>
/// <returns>A task that represents the asynchronous operation. The task result is <c>true</c> if the deletion was successful; otherwise, <c>false</c>.</returns>
public async Task<bool> DeleteByUnitId(ObjectId unitId)
{
return await _authorityRepository.DeleteAllAuthoritiesByUnit(unitId);
}
/// <summary>
/// Deletes all authorities associated with the specified display identifier by delegating to the authority repository.
/// </summary>
/// <param name="displayId">The unique identifier of the display whose related authorities should be removed.</param>
/// <returns>A task that resolves to <c>true</c> if authorities were successfully deleted; otherwise, <c>false</c>.</returns>
public async Task<bool> DeleteByDisplayId(ObjectId displayId)
{
return await _authorityRepository.DeleteAllAuthoritiesByDisplay(displayId);
}
/// <summary>
/// Ensures the authentication utilities are initialized with a valid login token. Returns early if the recording API URL is not configured; otherwise, requests a new token when the current one is missing or expired, and updates the shared <see cref="AuthUtils"/> instance with the refreshed response when successful.
/// </summary>
private async Task InstanceAuthUtils()
{
if (_recordingSettings.RecordingApiUrl.IsEmpty())