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>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext
where TDbContext : DbContext, IUserManagerDbContext
=> services
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
@ -50,4 +50,4 @@ namespace DigitalData.UserManager.Application
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 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
(
int Id,
string? Name,
bool? AdSync,
bool? Internal,
bool? Active,
string? Comment,
string? ChangedWho
string? Comment
) : BaseUpdateDto();
}

View File

@ -3,7 +3,6 @@
namespace DigitalData.UserManager.Application.DTOs.GroupOfUser
{
public record GroupOfUserUpdateDto(
int Id,
int? UserId,
int? GroupId,
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(
int Id,
string? Name,
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(
int Id,
@ -7,5 +9,5 @@
bool? IsAdmin,
string? Comment,
string? ChangedWho
);
) : IUnique<int>;
}

View File

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

View File

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

View File

@ -18,7 +18,7 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup)
{
var group = _mapper.MapOrThrow<Group>(adGroup);
var group = _mapper.Map<Group>(adGroup);
//set the user
var user = await GetUserAsync();
@ -31,7 +31,7 @@ namespace DigitalData.UserManager.Application.Services
if (createdGroup is null)
return Result.Fail<int>();
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.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
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)
{
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);
}
}

View File

@ -4,14 +4,13 @@ using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Module;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
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)
{
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);
}
}

View File

@ -19,34 +19,34 @@ namespace DigitalData.UserManager.Application.Services
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int 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);
}
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int 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);
}
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int 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);
}
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int 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);
}
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))
return Result.Fail<int>().Message(_localizer[Key.UserAlreadyExists]);
@ -59,7 +59,7 @@ namespace DigitalData.UserManager.Application.Services
if (createdUser is null)
return Result.Fail<int>();
else
return Result.Success(KeyValueOf(createdUser));
return Result.Success(createdUser.Id);
}
public async Task<DataResult<UserReadDto>> ReadByUsernameAsync(string username)
@ -68,7 +68,7 @@ namespace DigitalData.UserManager.Application.Services
if (user is null)
return Result.Fail<UserReadDto>().Message(_localizer[Key.UserNotFoundInLocalDB]);
var userDto = _mapper.MapOrThrow<UserReadDto>(user);
var userDto = _mapper.Map<UserReadDto>(user);
return Result.Success(userDto);
}
}

View File

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

View File

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

View File

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

View File

@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Dom
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalData.UserManager.Application", "DigitalData.UserManager.Application\DigitalData.UserManager.Application.csproj", "{0634853C-C515-48AF-8E27-E5CBF592BCE7}"
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}"
EndProject
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}.Release|Any CPU.ActiveCfg = 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.Build.0 = Debug|Any CPU
{1DD81373-82F9-4872-95C6-888624DB1797}.Release|Any CPU.ActiveCfg = Release|Any CPU