diff --git a/Zurnal/Date/Repository/UserRepositoryImpl.cs b/Zurnal/Date/Repository/UserRepositoryImpl.cs index 86b2cef..22f288c 100644 --- a/Zurnal/Date/Repository/UserRepositoryImpl.cs +++ b/Zurnal/Date/Repository/UserRepositoryImpl.cs @@ -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 AllGroup => throw new NotImplementedException(); + public IEnumerable 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 IGroupRepository.GetAllGroups() + IEnumerable 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 AllGroup => throw new NotImplementedException(); + + List IGroupRepository.AllGroup => throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Zurnal/Domain/UseCase/GroupUseCase.cs b/Zurnal/Domain/UseCase/GroupUseCase.cs index 6f90712..76ed704 100644 --- a/Zurnal/Domain/UseCase/GroupUseCase.cs +++ b/Zurnal/Domain/UseCase/GroupUseCase.cs @@ -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 GetAllGroups() => _repositoryGroupImpl.GetAllGroups() - .Select(it => new Group { Id = it.Id, Name = it.Name }).ToList(); + public List AllGroup => throw new NotImplementedException(); + + + public List 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 AllGroups() + { + throw new NotImplementedException(); + } + + public bool RemoveGroupById(int groupID) + { + throw new NotImplementedException(); + } + + public bool UpdateGroupById(int groupID, GroupDao updatedGroup) + { + throw new NotImplementedException(); + } + + IEnumerable 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 IGroupRepository.AllGroups() + { + throw new NotImplementedException(); + } + + bool IGroupRepository.AddGroup(GroupDao newGroup) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Zurnal/Domain/UseCase/UserUseCase.cs b/Zurnal/Domain/UseCase/UserUseCase.cs index 6369f49..961e748 100644 --- a/Zurnal/Domain/UseCase/UserUseCase.cs +++ b/Zurnal/Domain/UseCase/UserUseCase.cs @@ -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,45 +15,57 @@ namespace Zurnal.Domain.UseCase RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl))); } - public List GetAllUsers() => _repositoryUserImpl.GetAllUsersList() + public List 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 } } - ).ToList(); + 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) { 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 GetAllGroups() + public IEnumerable GetAllGroups() { - return RepositoryGroupImpl.AllGroup.Select(g => new Group { Id = g.Id, Name = g.GroupName }).ToList(); + return RepositoryGroupImpl.AllGroup; } - public User 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 }; - } + public UserDao FindUserByGuid(Guid userGuid) +{ + var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid); + if (user == null) + { + Console.WriteLine("Пользователь не найден."); + return null; + } + + 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 AllGroup => new List(); + public List AllGroup => RepositoryGroupImpl.AllGroup.ToList(); List IGroupRepository.AllGroup => throw new NotImplementedException(); IEnumerable IGroupRepository.AllGroups() diff --git a/Zurnal/RemaDateBase/DateDao/GroupDao.cs b/Zurnal/RemaDateBase/DateDao/GroupDao.cs index 336c9fd..ba8baa2 100644 --- a/Zurnal/RemaDateBase/DateDao/GroupDao.cs +++ b/Zurnal/RemaDateBase/DateDao/GroupDao.cs @@ -1,4 +1,5 @@ -namespace Zurnal.RemaDateBase.DateDao + +namespace Zurnal.RemaDateBase.DateDao { public class GroupDao {