Refaktorisierung der Lokalisierung und DTO-Integration

- Ersetzung von ITranslateService durch IStringLocalizer<X> für verbesserte Lokalisierung.
- Aktualisierung der DTO-Klassen entsprechend der neuesten Core.DTO-Struktur.
- Integration der neuen Klassen Result und DataResult aus Core.DTO für standardisierte Serviceantworten.
This commit is contained in:
Developer 02
2024-05-02 17:36:53 +02:00
parent dbe3743660
commit 0abdbfa705
108 changed files with 1089 additions and 126 deletions

View File

@@ -1,21 +1,21 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.GroupOfUser;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
public class GroupOfUserService : CRUDService<IGroupOfUserRepository, GroupOfUserCreateDto, GroupOfUserReadDto, GroupOfUserUpdateDto, GroupOfUser, int>, IGroupOfUserService
{
public GroupOfUserService(IGroupOfUserRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public GroupOfUserService(IGroupOfUserRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<IServiceMessage> DeleteAsyncByGroupUserId(int groupId, int userId)
public async Task<Result> DeleteAsyncByGroupUserId(int groupId, int userId)
{
var mous = await _repository.ReadByGroupUserIdAsync(groupId, userId);
@@ -24,10 +24,10 @@ namespace DigitalData.UserManager.Application.Services
await _repository.DeleteAsync(mou);
}
return Successful();
return Result.Success();
}
public async Task<IServiceResult<IEnumerable<GroupOfUserReadDto>>> ReadAllAsyncWith(bool user, bool group)
public async Task<DataResult<IEnumerable<GroupOfUserReadDto>>> ReadAllAsyncWith(bool user, bool group)
{
IEnumerable<GroupOfUser> entities;
@@ -49,10 +49,10 @@ namespace DigitalData.UserManager.Application.Services
}
var gouReadDtos = _mapper.MapOrThrow<IEnumerable<GroupOfUserReadDto>>(entities);
return Successful(gouReadDtos);
return Result.Success(gouReadDtos);
}
public async Task<IServiceMessage> HasGroup(string username, string groupname, bool caseSensitive = true)
public async Task<Result> HasGroup(string username, string groupname, bool caseSensitive = true)
{
var gous = await _repository.ReadAllAsyncWithGroupAndUser();
@@ -61,7 +61,7 @@ namespace DigitalData.UserManager.Application.Services
else
gous = gous.Where(gous => gous.User?.Username.ToLower() == username.ToLower() && gous.Group?.Name?.ToLower() == groupname.ToLower());
return CreateMessage(gous.Any());
return gous.Any() ? Result.Success() : Result.Fail();
}
}
}

View File

@@ -1,32 +1,32 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.Group;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
public class GroupService : CRUDService<IGroupRepository, GroupCreateDto, GroupReadDto, GroupUpdateDto, Group, int>, IGroupService
{
public GroupService(IGroupRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public GroupService(IGroupRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<IServiceResult<int>> CreateAsync(DirectoryGroupDto adGroup)
public async Task<DataResult<int>> CreateAsync(DirectoryGroupDto adGroup)
{
var group = _mapper.MapOrThrow<Group>(adGroup);
if (await HasEntity(group.Guid))
return Failed<int>(MessageKey.GroupAlreadyExists.ToString());
return Result.Fail<int>().Message(_localizer[Key.GroupAlreadyExists.ToString()]);
var createdGroup = await _repository.CreateAsync(group);
if (createdGroup is null)
return Failed<int>();
return Result.Fail<int>();
else
return Successful(KeyValueOf(createdGroup));
return Result.Success(KeyValueOf(createdGroup));
}
}
}

View File

@@ -1,21 +1,21 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using DigitalData.Core.DTO;
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, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public ModuleOfUserService(IModuleOfUserRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<IServiceMessage> DeleteAsyncByModuleUserId(int moduleId, int userId)
public async Task<Result> DeleteAsyncByModuleUserId(int moduleId, int userId)
{
var mous = await _repository.ReadByModelUserIdAsync(moduleId, userId);
@@ -24,7 +24,7 @@ namespace DigitalData.UserManager.Application.Services
await _repository.DeleteAsync(mou);
}
return Successful();
return Result.Success();
}
}
}

View File

@@ -1,16 +1,16 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.CultureServices;
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, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public ModuleService(IModuleRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
}

View File

@@ -1,25 +1,25 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.UserRep;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
public class UserRepService : CRUDService<IUserRepRepository, UserRepCreateDto, UserRepReadDto, UserRepUpdateDto, UserRep, int>, IUserRepService
{
public UserRepService(IUserRepRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public UserRepService(IUserRepRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<IServiceResult<IEnumerable<UserRepReadDto>>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null)
public async Task<DataResult<IEnumerable<UserRepReadDto>>> ReadAllAsync(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null)
{
var urs = await _repository.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId);
var urReadDTOs = _mapper.MapOrThrow<IEnumerable<UserRepReadDto>>(urs);
return Successful(urReadDTOs);
return Result.Success(urReadDTOs);
}
}
}

View File

@@ -1,70 +1,70 @@
using AutoMapper;
using DigitalData.Core.Application;
using DigitalData.Core.Contracts.Application;
using DigitalData.Core.Contracts.CultureServices;
using DigitalData.Core.DTO;
using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.DTOs.User;
using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.Extensions.Localization;
namespace DigitalData.UserManager.Application.Services
{
public class UserService : CRUDService<IUserRepository, UserCreateDto, UserReadDto, UserUpdateDto, User, int>, IUserService
{
public UserService(IUserRepository repository, IKeyTranslationService translationService, IMapper mapper) : base(repository, translationService, mapper)
public UserService(IUserRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper) : base(repository, localizer, mapper)
{
}
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int moduleId)
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByModuleIdAsync(int moduleId)
{
var users = await _repository.ReadByModuleIdAsync(moduleId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
return Successful(readDTOs);
return Result.Success(readDTOs);
}
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int groupId)
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadByGroupIdAsync(int groupId)
{
var users = await _repository.ReadByGroupIdAsync(groupId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
return Successful(readDTOs);
return Result.Success(readDTOs);
}
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int moduleId)
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByModuleIdAsync(int moduleId)
{
var users = await _repository.ReadUnassignedByModuleIdAsync(moduleId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
return Successful(readDTOs);
return Result.Success(readDTOs);
}
public async Task<IServiceResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int groupId)
public async Task<DataResult<IEnumerable<UserReadDto>>> ReadUnassignedByGroupIdAsync(int groupId)
{
var users = await _repository.ReadUnassignedByGroupIdAsync(groupId);
IEnumerable<UserReadDto> readDTOs = _mapper.MapOrThrow<IEnumerable<UserReadDto>>(users);
return Successful(readDTOs);
return Result.Success(readDTOs);
}
public async Task<IServiceResult<int>> CreateAsync(UserPrincipalDto upDto)
public async Task<DataResult<int>> CreateAsync(UserPrincipalDto upDto)
{
var user = _mapper.MapOrThrow<User>(upDto);
if (await HasEntity(user.Guid))
return Failed<int>(MessageKey.UserAlreadyExists.ToString());
return Result.Fail<int>().Message(_localizer[Key.UserAlreadyExists]);
var createdUser = await _repository.CreateAsync(user);
if (createdUser is null)
return Failed<int>();
return Result.Fail<int>();
else
return Successful(KeyValueOf(createdUser));
return Result.Success(KeyValueOf(createdUser));
}
public async Task<IServiceResult<UserReadDto>> ReadByUsernameAsync(string username)
public async Task<DataResult<UserReadDto>> ReadByUsernameAsync(string username)
{
var user = await _repository.ReadByUsernameAsync(username);
if (user is null)
return Failed<UserReadDto>(MessageKey.UserNotFoundInLocalDB.ToString());
return Result.Fail<UserReadDto>().Message(_localizer[Key.UserNotFoundInLocalDB]);
var userDto = _mapper.MapOrThrow<UserReadDto>(user);
return Successful(userDto);
return Result.Success(userDto);
}
}
}