This commit is contained in:
Userok 2024-11-02 12:07:18 +03:00
parent fc4f46d1b7
commit 9031163ee8
4 changed files with 120 additions and 33 deletions

View File

@ -2,6 +2,7 @@
using Zurnal.Date.LocalDate;
using Zurnal.Date.Repository;
using Zurnal.Domain.UseCase;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Data.Repository
{
@ -68,9 +69,17 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException();
}
public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
public IEnumerable<System.Text.RegularExpressions.Group> AllGroups()
{
throw new NotImplementedException();
}
internal UserUseCase.UserLocalEntity? UpdateUser(UserUseCase.UserLocalEntity userLocalEntity)
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
public bool AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
@ -80,17 +89,17 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException();
}
System.Text.RegularExpressions.Group IGroupRepository.GetGroupById(int id)
GroupDao IGroupRepository.GetGroupById(int id)
{
throw new NotImplementedException();
}
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.GetAllGroups()
IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
{
throw new NotImplementedException();
}
public void UpdateGroup(System.Text.RegularExpressions.Group group)
public void UpdateGroup(GroupDao group)
{
throw new NotImplementedException();
}
@ -99,5 +108,9 @@ namespace Zurnal.Data.Repository
{
throw new NotImplementedException();
}
public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
}
}

View File

@ -1,14 +1,19 @@
using System.Text.RegularExpressions;
using Zurnal.Data.Repository;
using Zurnal.domain.Models;
using Zurnal.Date.Repository;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase
{
public class GroupUseCase
public class GroupUseCase : IGroupRepository
{
private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl;
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
public List<GroupDao> AllGroup => throw new NotImplementedException();
public List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, GroupName = it.GroupName }).ToList();
public GroupUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{
@ -16,7 +21,7 @@ namespace Zurnal.Domain.UseCase
_repositoryGroupImpl = repositoryGroupImpl;
}
public void AddGroup(Group group)
public void AddGroup(GroupDao group)
{
_repositoryGroupImpl.AddGroup(group: group);
}
@ -26,5 +31,62 @@ namespace Zurnal.Domain.UseCase
_repositoryGroupImpl.UpdateGroupName(groupId, newName);
}
public IEnumerable<GroupDao> AllGroups()
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID)
{
throw new NotImplementedException();
}
public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{
throw new NotImplementedException();
}
IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
{
return _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, GroupName = it.GroupName, Users = it.Users })
.ToList();
}
public void AddGroupFromRegex(System.Text.RegularExpressions.Group group)
{
throw new NotImplementedException();
}
public GroupDao GetGroupById(int id)
{
var group = _repositoryGroupImpl.GetGroupById(id);
if (group == null)
{
throw new KeyNotFoundException($"Группа с ID {id} не найдена.");
}
return group;
}
public void UpdateGroup(GroupDao group)
{
throw new NotImplementedException();
}
public void DeleteGroup(int id)
{
throw new NotImplementedException();
}
IEnumerable<Group> IGroupRepository.AllGroups()
{
throw new NotImplementedException();
}
bool IGroupRepository.AddGroup(GroupDao newGroup)
{
throw new NotImplementedException();
}
}
}

View File

@ -1,6 +1,5 @@
using Zurnal.Data.Repository;
using Zurnal.Date.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase
@ -16,14 +15,15 @@ namespace Zurnal.Domain.UseCase
RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl)));
}
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
.Join(RepositoryGroupImpl.AllGroup,
user => user.GroupID,
group => group.Id,
(user, group) =>
new User { FIO = user.FIO,
Guid = user.Guid,
Group = new Group { Id = group.Id, Name = group.GroupName } }
new UserDao { FIO = user.FIO,
UserGuid = user.Guid,
Group = new GroupDao { Id = group.Id, GroupName = group.GroupName },
GroupID = group.Id }
).ToList();
public bool RemoveUserByGuid(Guid userGuid)
@ -31,30 +31,41 @@ namespace Zurnal.Domain.UseCase
return _repositoryUserImpl.RemoveUserByGuid(userGuid);
}
public User UpdateUser(User user, int groupId)
public UserDao UpdateUser(UserDao user, int groupId)
{
UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = groupId, Guid = user.Guid };
UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = groupId, Guid = user.UserGuid };
UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
if (result == null) throw new Exception("User update failed.");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result.GroupID);
if (group == null) throw new Exception("Group not found.");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
if (result == null) throw new Exception("Пользователь не обновлен.");
GroupDao? group = GetAllGroups().FirstOrDefault(it => it.Id == result.GroupID);
if (group == null) throw new Exception("Група не нфйдуна.");
return new UserDao { FIO = user.FIO, UserGuid = user.UserGuid, Group = group, GroupID = group.Id };
}
private List<Group> GetAllGroups()
public IEnumerable<GroupDao> GetAllGroups()
{
return RepositoryGroupImpl.AllGroup.Select(g => new Group { Id = g.Id, Name = g.GroupName }).ToList();
return RepositoryGroupImpl.AllGroup;
}
public User FindUserByGuid(Guid userGuid)
{
public UserDao FindUserByGuid(Guid userGuid)
{
var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
if (user == null) throw new Exception("Пользователь не найден.");
var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
if (user == null)
{
Console.WriteLine("Пользователь не найден.");
return null;
}
public List<Group> AllGroup => new List<Group>();
GroupDao group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
if (group == null)
{
Console.WriteLine("Группа не найдена.");
return null;
}
return new UserDao { FIO = user.FIO, UserGuid = user.Guid, Group = group, GroupID = group.Id };
}
public List<GroupDao> AllGroup => RepositoryGroupImpl.AllGroup.ToList();
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups()

View File

@ -1,4 +1,5 @@
namespace Zurnal.RemaDateBase.DateDao

namespace Zurnal.RemaDateBase.DateDao
{
public class GroupDao
{