feat: Basis-DTOs, Service und Controller für automatische Metadatenverwaltung hinzugefügt

- Basis-DTOs für Lese-, Erstellungs- und Aktualisierungsvorgänge erstellt, um die Felder "hinzugefügt von", "hinzugefügt am", "geändert von" und "geändert am" automatisch über Middleware zu ergänzen.
- Diese Basiskomponenten in die Gruppenstruktur integriert.
This commit is contained in:
Developer 02
2024-08-14 18:49:59 +02:00
parent 4746d63aea
commit 36d763d5e5
16 changed files with 240 additions and 50 deletions

View File

@@ -0,0 +1,47 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
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]
public class BaseAuthController<TCRUDService, TCreateDto, TReadDto, TUpdateDto, TBaseEntity> : CRUDControllerBaseWithErrorHandling<TCRUDService, TCreateDto, TReadDto, TUpdateDto, TBaseEntity, int>
where TCRUDService : IBaseService<TCreateDto, TReadDto, TUpdateDto, 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;
};
}
}
}

View File

@@ -1,4 +1,3 @@
using DigitalData.Core.API;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Group;
@@ -9,9 +8,9 @@ using Microsoft.AspNetCore.Mvc;
namespace DigitalData.UserManager.API.Controllers
{
[Authorize]
public class GroupController : CRUDControllerBaseWithErrorHandling<IGroupService, GroupCreateDto, GroupReadDto, GroupUpdateDto, Group, int>
public class GroupController : BaseAuthController<IGroupService, GroupCreateDto, GroupReadDto, GroupUpdateDto, Group>
{
public GroupController(ILogger<GroupController> logger, IGroupService service) : base(logger, service)
public GroupController(ILogger<GroupController> logger, IGroupService service, IUserService userService) : base(logger, service, userService)
{
}