refactor(core): DTOs und Services an Core 2.0.0.0 angepasst

This commit is contained in:
Developer 02 2024-09-20 00:53:28 +02:00
parent 8d88148b98
commit 9458ffae42
17 changed files with 39 additions and 44 deletions

View File

@ -20,7 +20,7 @@ namespace DigitalData.UserManager.Application
/// <param name="services">The IServiceCollection to which the services will be added.</param> /// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns> /// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services) public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext where TDbContext : DbContext, IUserManagerDbContext
=> services => services
.AddAutoMapper(typeof(UserMappingProfile).Assembly) .AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly) .AddAutoMapper(typeof(GroupMappingProfile).Assembly)
@ -50,4 +50,4 @@ namespace DigitalData.UserManager.Application
return services; return services;
} }
} }
} }

View File

@ -1,9 +1,14 @@
namespace DigitalData.UserManager.Application.DTOs.Base using DigitalData.Core.Abstractions;
namespace DigitalData.UserManager.Application.DTOs.Base
{ {
public record BaseUpdateDto() public record BaseUpdateDto() : IUnique<int>
{ {
public string ChangedWho { get; set; } = "UNAUTHORIZED"; public string ChangedWho { get; set; } = "UNAUTHORIZED";
public DateTime ChangedWhen { get; set; } = DateTime.Now; public DateTime ChangedWhen { get; set; } = DateTime.Now;
public int Id { get; init; }
} }
} }

View File

@ -4,12 +4,10 @@ namespace DigitalData.UserManager.Application.DTOs.Group
{ {
public record GroupUpdateDto public record GroupUpdateDto
( (
int Id,
string? Name, string? Name,
bool? AdSync, bool? AdSync,
bool? Internal, bool? Internal,
bool? Active, bool? Active,
string? Comment, string? Comment
string? ChangedWho
) : BaseUpdateDto(); ) : BaseUpdateDto();
} }

View File

@ -3,7 +3,6 @@
namespace DigitalData.UserManager.Application.DTOs.GroupOfUser namespace DigitalData.UserManager.Application.DTOs.GroupOfUser
{ {
public record GroupOfUserUpdateDto( public record GroupOfUserUpdateDto(
int Id,
int? UserId, int? UserId,
int? GroupId, int? GroupId,
string? Comment string? Comment

View File

@ -1,8 +1,10 @@
namespace DigitalData.UserManager.Application.DTOs.Module using DigitalData.Core.Abstractions;
namespace DigitalData.UserManager.Application.DTOs.Module
{ {
public record ModuleDto( public record ModuleDto(
int Id, int Id,
string? Name, string? Name,
string? ShortName string? ShortName
); ) : IUnique<int>;
} }

View File

@ -1,4 +1,6 @@
namespace DigitalData.UserManager.Application.DTOs.ModuleOfUser using DigitalData.Core.Abstractions;
namespace DigitalData.UserManager.Application.DTOs.ModuleOfUser
{ {
public record ModuleOfUserUpdateDto( public record ModuleOfUserUpdateDto(
int Id, int Id,
@ -7,5 +9,5 @@
bool? IsAdmin, bool? IsAdmin,
string? Comment, string? Comment,
string? ChangedWho string? ChangedWho
); ) : IUnique<int>;
} }

View File

@ -3,7 +3,6 @@
namespace DigitalData.UserManager.Application.DTOs.User namespace DigitalData.UserManager.Application.DTOs.User
{ {
public record UserUpdateDto( public record UserUpdateDto(
int Id,
string? Prename, string? Prename,
string? Name, string? Name,
string? Username, string? Username,
@ -13,7 +12,6 @@ namespace DigitalData.UserManager.Application.DTOs.User
string? Comment, string? Comment,
bool? Deleted, bool? Deleted,
string? DateFormat, string? DateFormat,
bool? Active, bool? Active
string AddedWho
) : BaseUpdateDto(); ) : BaseUpdateDto();
} }

View File

@ -1,5 +1,4 @@
using AutoMapper; using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.DTO; using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts; using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.GroupOfUser; using DigitalData.UserManager.Application.DTOs.GroupOfUser;
@ -47,7 +46,7 @@ namespace DigitalData.UserManager.Application.Services
entities = await _repository.ReadAllAsync(); entities = await _repository.ReadAllAsync();
} }
var gouReadDtos = _mapper.MapOrThrow<IEnumerable<GroupOfUserReadDto>>(entities); var gouReadDtos = _mapper.Map<IEnumerable<GroupOfUserReadDto>>(entities);
return Result.Success(gouReadDtos); return Result.Success(gouReadDtos);
} }
@ -66,7 +65,7 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<IEnumerable<GroupOfUserReadDto>>> ReadByUsernameAsync(string username) public async Task<DataResult<IEnumerable<GroupOfUserReadDto>>> ReadByUsernameAsync(string username)
{ {
var groups = await _repository.ReadByUsernameAsync(username); var groups = await _repository.ReadByUsernameAsync(username);
var groupDtos = _mapper.MapOrThrow<IEnumerable<GroupOfUserReadDto>>(groups); var groupDtos = _mapper.Map<IEnumerable<GroupOfUserReadDto>>(groups);
return Result.Success(groupDtos); return Result.Success(groupDtos);
} }
} }

View File

@ -18,7 +18,7 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup) public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup)
{ {
var group = _mapper.MapOrThrow<Group>(adGroup); var group = _mapper.Map<Group>(adGroup);
//set the user //set the user
var user = await GetUserAsync(); var user = await GetUserAsync();
@ -31,7 +31,7 @@ namespace DigitalData.UserManager.Application.Services
if (createdGroup is null) if (createdGroup is null)
return Result.Fail<int>(); return Result.Fail<int>();
else else
return Result.Success(KeyValueOf(createdGroup)); return Result.Success(createdGroup.Id);
} }
} }
} }

View File

@ -5,13 +5,12 @@ using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.ModuleOfUser; using DigitalData.UserManager.Application.DTOs.ModuleOfUser;
using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts; using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services namespace DigitalData.UserManager.Application.Services
{ {
public class ModuleOfUserService : CRUDService<IModuleOfUserRepository, ModuleOfUserCreateDto, ModuleOfUserReadDto, ModuleOfUserUpdateDto, ModuleOfUser, int>, IModuleOfUserService public class ModuleOfUserService : CRUDService<IModuleOfUserRepository, ModuleOfUserCreateDto, ModuleOfUserReadDto, ModuleOfUserUpdateDto, ModuleOfUser, int>, IModuleOfUserService
{ {
public ModuleOfUserService(IModuleOfUserRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, mapper) public ModuleOfUserService(IModuleOfUserRepository repository, IMapper mapper) : base(repository, mapper)
{ {
} }
@ -30,7 +29,7 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<IEnumerable<ModuleOfUserReadDto>>> ReadByUserAsync(string username) public async Task<DataResult<IEnumerable<ModuleOfUserReadDto>>> ReadByUserAsync(string username)
{ {
var mous = await _repository.ReadByUserAsync(username: username); var mous = await _repository.ReadByUserAsync(username: username);
var mous_dtos = _mapper.MapOrThrow<IEnumerable<ModuleOfUserReadDto>>(mous); var mous_dtos = _mapper.Map<IEnumerable<ModuleOfUserReadDto>>(mous);
return Result.Success(mous_dtos); return Result.Success(mous_dtos);
} }
} }

View File

@ -4,14 +4,13 @@ using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Module; using DigitalData.UserManager.Application.DTOs.Module;
using DigitalData.UserManager.Domain.Entities; using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts; using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services namespace DigitalData.UserManager.Application.Services
{ {
public class ModuleService : BasicCRUDService<IModuleRepository, ModuleDto, Module, int>, IModuleService public class ModuleService : BasicCRUDService<IModuleRepository, ModuleDto, Module, int>, IModuleService
{ {
public ModuleService(IModuleRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, mapper) public ModuleService(IModuleRepository repository, IMapper mapper) : base(repository, mapper)
{ {
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<IEnumerable<UserRepReadDto>>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null) public async Task<DataResult<IEnumerable<UserRepReadDto>>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null)
{ {
var urs = await _repository.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId); var urs = await _repository.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId);
var urReadDTOs = _mapper.MapOrThrow<IEnumerable<UserRepReadDto>>(urs); var urReadDTOs = _mapper.Map<IEnumerable<UserRepReadDto>>(urs);
return Result.Success(urReadDTOs); return Result.Success(urReadDTOs);
} }
} }

View File

@ -19,34 +19,34 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int moduleId) public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int moduleId)
{ {
var users = await _repository.ReadByModuleIdAsync(moduleId); var users = await _repository.ReadByModuleIdAsync(moduleId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users); IEnumerable<UserReadDto> readDTOs = _mapper.Map<IEnumerable<UserReadDto>>(users);
return Result.Success(readDTOs); return Result.Success(readDTOs);
} }
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int groupId) public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int groupId)
{ {
var users = await _repository.ReadByGroupIdAsync(groupId); var users = await _repository.ReadByGroupIdAsync(groupId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users); IEnumerable<UserReadDto> readDTOs = _mapper.Map<IEnumerable<UserReadDto>>(users);
return Result.Success(readDTOs); return Result.Success(readDTOs);
} }
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int moduleId) public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int moduleId)
{ {
var users = await _repository.ReadUnassignedByModuleIdAsync(moduleId); var users = await _repository.ReadUnassignedByModuleIdAsync(moduleId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users); IEnumerable<UserReadDto> readDTOs = _mapper.Map<IEnumerable<UserReadDto>>(users);
return Result.Success(readDTOs); return Result.Success(readDTOs);
} }
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int groupId) public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int groupId)
{ {
var users = await _repository.ReadUnassignedByGroupIdAsync(groupId); var users = await _repository.ReadUnassignedByGroupIdAsync(groupId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users); IEnumerable<UserReadDto> readDTOs = _mapper.Map<IEnumerable<UserReadDto>>(users);
return Result.Success(readDTOs); return Result.Success(readDTOs);
} }
public async Task<DataResult<int>> CreateAsync(UserPrincipalDto upDto) public async Task<DataResult<int>> CreateAsync(UserPrincipalDto upDto)
{ {
var user = _mapper.MapOrThrow<User>(upDto); var user = _mapper.Map<User>(upDto);
if (await HasEntity(user.Id)) if (await HasEntity(user.Id))
return Result.Fail<int>().Message(_localizer[Key.UserAlreadyExists]); return Result.Fail<int>().Message(_localizer[Key.UserAlreadyExists]);
@ -59,7 +59,7 @@ namespace DigitalData.UserManager.Application.Services
if (createdUser is null) if (createdUser is null)
return Result.Fail<int>(); return Result.Fail<int>();
else else
return Result.Success(KeyValueOf(createdUser)); return Result.Success(createdUser.Id);
} }
public async Task<DataResult<UserReadDto>> ReadByUsernameAsync(string username) public async Task<DataResult<UserReadDto>> ReadByUsernameAsync(string username)
@ -68,7 +68,7 @@ namespace DigitalData.UserManager.Application.Services
if (user is null) if (user is null)
return Result.Fail<UserReadDto>().Message(_localizer[Key.UserNotFoundInLocalDB]); return Result.Fail<UserReadDto>().Message(_localizer[Key.UserNotFoundInLocalDB]);
var userDto = _mapper.MapOrThrow<UserReadDto>(user); var userDto = _mapper.Map<UserReadDto>(user);
return Result.Success(userDto); return Result.Success(userDto);
} }
} }

View File

@ -6,4 +6,4 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
public interface IGroupRepository : ICRUDRepository<Group, int> public interface IGroupRepository : ICRUDRepository<Group, int>
{ {
} }
} }

View File

@ -11,4 +11,4 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username); Task<IEnumerable<ModuleOfUser>> ReadByUserAsync(string username);
} }
} }

View File

@ -6,4 +6,4 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
public interface IModuleRepository : ICRUDRepository<Module, int> public interface IModuleRepository : ICRUDRepository<Module, int>
{ {
} }
} }

View File

@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Dom
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Application", "DigitalData.UserManager.Application\DigitalData.UserManager.Application.csproj", "{0634853C-C515-48AF-8E27-E5CBF592BCE7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Application", "DigitalData.UserManager.Application\DigitalData.UserManager.Application.csproj", "{0634853C-C515-48AF-8E27-E5CBF592BCE7}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.NgWebUI", "DigitalData.UserManager.NgWebUI\DigitalData.UserManager.NgWebUI.csproj", "{BFBD26C1-2E95-41EC-A5CC-F334CB2309A8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Infrastructure", "DigitalData.UserManager.Infrastructure\DigitalData.UserManager.Infrastructure.csproj", "{1DD81373-82F9-4872-95C6-888624DB1797}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Infrastructure", "DigitalData.UserManager.Infrastructure\DigitalData.UserManager.Infrastructure.csproj", "{1DD81373-82F9-4872-95C6-888624DB1797}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.API", "DigitalData.UserManager.API\DigitalData.UserManager.API.csproj", "{07CCD651-647C-49F7-9715-30CEBC13710D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.API", "DigitalData.UserManager.API\DigitalData.UserManager.API.csproj", "{07CCD651-647C-49F7-9715-30CEBC13710D}"
@ -27,10 +25,6 @@ Global
{0634853C-C515-48AF-8E27-E5CBF592BCE7}.Debug|Any CPU.Build.0 = Debug|Any CPU {0634853C-C515-48AF-8E27-E5CBF592BCE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0634853C-C515-48AF-8E27-E5CBF592BCE7}.Release|Any CPU.ActiveCfg = Release|Any CPU {0634853C-C515-48AF-8E27-E5CBF592BCE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0634853C-C515-48AF-8E27-E5CBF592BCE7}.Release|Any CPU.Build.0 = Release|Any CPU {0634853C-C515-48AF-8E27-E5CBF592BCE7}.Release|Any CPU.Build.0 = Release|Any CPU
{BFBD26C1-2E95-41EC-A5CC-F334CB2309A8}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{BFBD26C1-2E95-41EC-A5CC-F334CB2309A8}.Debug|Any CPU.Build.0 = Release|Any CPU
{BFBD26C1-2E95-41EC-A5CC-F334CB2309A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFBD26C1-2E95-41EC-A5CC-F334CB2309A8}.Release|Any CPU.Build.0 = Release|Any CPU
{1DD81373-82F9-4872-95C6-888624DB1797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1DD81373-82F9-4872-95C6-888624DB1797}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DD81373-82F9-4872-95C6-888624DB1797}.Debug|Any CPU.Build.0 = Debug|Any CPU {1DD81373-82F9-4872-95C6-888624DB1797}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DD81373-82F9-4872-95C6-888624DB1797}.Release|Any CPU.ActiveCfg = Release|Any CPU {1DD81373-82F9-4872-95C6-888624DB1797}.Release|Any CPU.ActiveCfg = Release|Any CPU