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.LocalDate;
using Zurnal.Date.Repository; using Zurnal.Date.Repository;
using Zurnal.Domain.UseCase; using Zurnal.Domain.UseCase;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Data.Repository namespace Zurnal.Data.Repository
{ {
@ -68,9 +69,17 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException(); 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(); throw new NotImplementedException();
} }
@ -80,17 +89,17 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException(); throw new NotImplementedException();
} }
System.Text.RegularExpressions.Group IGroupRepository.GetGroupById(int id) GroupDao IGroupRepository.GetGroupById(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.GetAllGroups() IEnumerable<GroupDao> IGroupRepository.GetAllGroups()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void UpdateGroup(System.Text.RegularExpressions.Group group) public void UpdateGroup(GroupDao group)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -99,5 +108,9 @@ namespace Zurnal.Data.Repository
{ {
throw new NotImplementedException(); 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.Data.Repository;
using Zurnal.domain.Models; using Zurnal.Date.Repository;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase namespace Zurnal.Domain.UseCase
{ {
public class GroupUseCase public class GroupUseCase : IGroupRepository
{ {
private UserRepositoryImpl _repositoryUserImpl; private UserRepositoryImpl _repositoryUserImpl;
private GroupRepositoryImpl _repositoryGroupImpl; private GroupRepositoryImpl _repositoryGroupImpl;
public List<Group> GetAllGroups() => _repositoryGroupImpl.GetAllGroups() public List<GroupDao> AllGroup => throw new NotImplementedException();
.Select(it => new Group { Id = it.Id, Name = it.Name }).ToList();
public List<GroupDao> GetAllGroups() => _repositoryGroupImpl.GetAllGroups()
.Select(it => new GroupDao { Id = it.Id, GroupName = it.GroupName }).ToList();
public GroupUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) public GroupUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl)
{ {
@ -16,7 +21,7 @@ namespace Zurnal.Domain.UseCase
_repositoryGroupImpl = repositoryGroupImpl; _repositoryGroupImpl = repositoryGroupImpl;
} }
public void AddGroup(Group group) public void AddGroup(GroupDao group)
{ {
_repositoryGroupImpl.AddGroup(group: group); _repositoryGroupImpl.AddGroup(group: group);
} }
@ -26,5 +31,62 @@ namespace Zurnal.Domain.UseCase
_repositoryGroupImpl.UpdateGroupName(groupId, newName); _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.Data.Repository;
using Zurnal.Date.Repository; using Zurnal.Date.Repository;
using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao; using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase namespace Zurnal.Domain.UseCase
@ -16,45 +15,57 @@ namespace Zurnal.Domain.UseCase
RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl))); RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl)));
} }
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList() public List<UserDao> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
.Join(RepositoryGroupImpl.AllGroup, .Join(RepositoryGroupImpl.AllGroup,
user => user.GroupID, user => user.GroupID,
group => group.Id, group => group.Id,
(user, group) => (user, group) =>
new User { FIO = user.FIO, new UserDao { FIO = user.FIO,
Guid = user.Guid, UserGuid = user.Guid,
Group = new Group { Id = group.Id, Name = group.GroupName } } Group = new GroupDao { Id = group.Id, GroupName = group.GroupName },
).ToList(); GroupID = group.Id }
).ToList();
public bool RemoveUserByGuid(Guid userGuid) public bool RemoveUserByGuid(Guid userGuid)
{ {
return _repositoryUserImpl.RemoveUserByGuid(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); UserLocalEntity? result = _repositoryUserImpl.UpdateUser(userLocalEntity);
if (result == null) throw new Exception("User update failed."); if (result == null) throw new Exception("Пользователь не обновлен.");
Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result.GroupID); GroupDao? group = GetAllGroups().FirstOrDefault(it => it.Id == result.GroupID);
if (group == null) throw new Exception("Group not found."); if (group == null) throw new Exception("Група не нфйдуна.");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; 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); var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid);
if (user == null) throw new Exception("Пользователь не найден."); if (user == null)
var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID); {
return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; 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<Group> AllGroup => new List<Group>(); public List<GroupDao> AllGroup => RepositoryGroupImpl.AllGroup.ToList();
List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException(); List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups() IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups()

View File

@ -1,4 +1,5 @@
namespace Zurnal.RemaDateBase.DateDao 
namespace Zurnal.RemaDateBase.DateDao
{ {
public class GroupDao public class GroupDao
{ {