TekH 40deb9968f Update namespaces and package references
Refactor namespaces from `DigitalData.Core.DTO` to `DigitalData.Core.Abstraction.Application.DTO` in multiple controllers to adopt a new abstraction layer. Update `DigitalData.Core.API` package from version `2.2.0` to `2.2.1` and add `DigitalData.Core.Abstraction.Application` package with version `1.0.0`. Add `[Obsolete("Use MediatR")]` attribute to several controllers to encourage transitioning to MediatR for request handling.
2025-06-26 11:47:43 +02:00

47 lines
1.7 KiB
C#

using DigitalData.Core.Abstraction.Application.DTO;
using DigitalData.Core.API;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Base;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;
namespace DigitalData.UserManager.API.Controllers;
[Authorize]
[Obsolete("Use MediatR")]
public class BaseAuthController<TCRUDService, TCreateDto, TReadDto, TUpdateDto, TBaseEntity> : CRUDControllerBaseWithErrorHandling<TCRUDService, TCreateDto, TReadDto, TUpdateDto, TBaseEntity, int>
where TCRUDService : IBaseService<TCreateDto, TReadDto, TBaseEntity>
where TCreateDto : BaseCreateDto
where TReadDto : class
where TUpdateDto : BaseUpdateDto
where TBaseEntity : BaseEntity
{
private readonly Lazy<int?> _lUserId;
public BaseAuthController(ILogger logger, TCRUDService service, IUserService userService) : base(logger, service)
{
_lUserId = new(() =>
{
var idSt = User.FindFirstValue(ClaimTypes.NameIdentifier);
bool hasId = int.TryParse(idSt, out int id);
return hasId ? id : null;
});
service.UserFactoryAsync = async () =>
{
var id = _lUserId.Value;
return id is int intId
? await userService.ReadByIdAsync(intId).ThenAsync(
Success: res => res,
Fail: UserReadDto? (m, n) =>
{
_logger.LogNotice(n);
return null;
})
: null;
};
}
}