This commit is contained in:
Userok 2024-11-01 10:49:39 +03:00
parent faeb43b8c2
commit 10d049c46b
6 changed files with 84 additions and 52 deletions

View File

@ -40,10 +40,7 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException(); throw new NotImplementedException();
} }
public List<GroupLocalEntity> GetAllGroup() public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
{
throw new NotImplementedException();
}
public bool RemoveGroupById(int groupID) public bool RemoveGroupById(int groupID)
{ {
@ -59,5 +56,30 @@ namespace Zurnal.Data.Repository
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AddGroupFromRegex(System.Text.RegularExpressions.Group group)
{
throw new NotImplementedException();
}
System.Text.RegularExpressions.Group IGroupRepository.GetGroupById(int id)
{
throw new NotImplementedException();
}
IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.GetAllGroups()
{
throw new NotImplementedException();
}
public void UpdateGroup(System.Text.RegularExpressions.Group group)
{
throw new NotImplementedException();
}
public void DeleteGroup(int id)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -1,4 +1,4 @@
using Zurnal.domain.Models; using Zurnal.RemaDateBase.DateDao;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Zurnal.Data.Repository; using Zurnal.Data.Repository;
using Group = System.Text.RegularExpressions.Group; using Group = System.Text.RegularExpressions.Group;
@ -6,17 +6,19 @@ using Group = System.Text.RegularExpressions.Group;
namespace Zurnal.Date.Repository namespace Zurnal.Date.Repository
{ {
internal interface IGroupRepository internal interface IGroupRepository
{ {
List<GroupLocalEntity> GetAllGroup(); List<GroupDao> AllGroup { get; }
bool RemoveGroupById(int groupID);
bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); IEnumerable<Group> AllGroups();
bool AddGroup(GroupLocalEntity newGroup); bool RemoveGroupById(int groupID);
void AddGroupFromRegex(Group group); bool UpdateGroupById(int groupID, GroupDao updatedGroup);
Group GetGroupById(int id); bool AddGroup(GroupDao newGroup);
IEnumerable<Group> GetAllGroups(); void AddGroupFromRegex(Group group);
void UpdateGroup(Group group); GroupDao GetGroupById(int id);
void DeleteGroup(int id); IEnumerable<GroupDao> GetAllGroups();
} void UpdateGroup(GroupDao group);
void DeleteGroup(int id);
}
internal class ServiceConfiguration internal class ServiceConfiguration
{ {

View File

@ -68,10 +68,7 @@ namespace Zurnal.Data.Repository
throw new NotImplementedException(); throw new NotImplementedException();
} }
public List<GroupLocalEntity> GetAllGroup() public List<GroupLocalEntity> AllGroup => throw new NotImplementedException();
{
throw new NotImplementedException();
}
internal UserUseCase.UserLocalEntity? UpdateUser(UserUseCase.UserLocalEntity userLocalEntity) internal UserUseCase.UserLocalEntity? UpdateUser(UserUseCase.UserLocalEntity userLocalEntity)
{ {

View File

@ -1,14 +1,25 @@
namespace Zurnal.domain.Models using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.domain.Models
{ {
public class Group public class Group
{ {
public required int Id { get; set; } public required int Id { get; set; }
public required string Name { get; set; } public required string Name { get; set; }
public static implicit operator Group(GroupLocalEntity v) public static implicit operator Group?(GroupLocalEntity? v)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public static implicit operator Guid(Group v)
{
throw new NotImplementedException();
}
public static implicit operator Group?(GroupDao? v)
{
throw new NotImplementedException();
}
} }
} }

View File

@ -2,6 +2,8 @@
{ {
public class User public class User
{ {
internal int Id;
public required string FIO { get; set; } public required string FIO { get; set; }
public Guid Guid { get; set; } public Guid Guid { get; set; }

View File

@ -1,7 +1,7 @@
using Zurnal.Data.Repository; using Zurnal.Data.Repository;
using Zurnal.Date.Repository; using Zurnal.Date.Repository;
using Zurnal.domain.Models; using Zurnal.domain.Models;
using Zurnal.RemaDateBase.DateDao;
namespace Zurnal.Domain.UseCase namespace Zurnal.Domain.UseCase
{ {
@ -15,20 +15,15 @@ namespace Zurnal.Domain.UseCase
_repositoryUserImpl = repositoryImpl; _repositoryUserImpl = repositoryImpl;
RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl))); RepositoryGroupImpl = (IGroupRepository?)(repositoryGroupImpl ?? throw new ArgumentNullException(nameof(repositoryGroupImpl)));
} }
private object NewMethod()
{
return RepositoryGroupImpl.GetAllGroup()
.Select(it => new Group { Id = it.Id, Name = it.Name });
}
public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList() public List<User> GetAllUsers() => _repositoryUserImpl.GetAllUsersList()
.Join(RepositoryGroupImpl.GetAllGroup(), .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 User { FIO = user.FIO,
Guid = user.Guid, Guid = user.Guid,
Group = new Group { Id = group.Id, Name = group.Name } } Group = new Group { Id = group.Id, Name = group.GroupName } }
).ToList(); ).ToList();
public bool RemoveUserByGuid(Guid userGuid) public bool RemoveUserByGuid(Guid userGuid)
@ -36,37 +31,40 @@ namespace Zurnal.Domain.UseCase
return _repositoryUserImpl.RemoveUserByGuid(userGuid); return _repositoryUserImpl.RemoveUserByGuid(userGuid);
} }
public User UpdateUser(User user, Guid id) public User UpdateUser(User user, Group id)
{ {
UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = id, Guid = user.Guid }; UserLocalEntity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = id, Guid = user.Guid };
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.ToString()); Group? group = GetAllGroups().FirstOrDefault(it =>
if (group == null) throw new Exception("Group not found.");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
}
private static UserLocalEntity GetUserLocalEntity(UserLocalEntity userLocalEntity)
{ {
return userLocalEntity; bool v = it.Id == result.GroupID.ToString();
return v;
});
if (group == null) throw new Exception("Группа не обновлена.");
return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
} }
private List<Group> GetAllGroups()
{
return new List<Group>();
}
public User FindUserByGuid(Guid userGuid) public User 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("User not found."); if (user == null) throw new Exception("Пользователь не найден.");
var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID); var group = RepositoryGroupImpl.AllGroup.FirstOrDefault(g => g.Id == user.GroupID);
return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; return new User { FIO = user.FIO, Guid = user.Guid, Group = group };
} }
public List<Group> GetAllGroup() public List<Group> AllGroup => new List<Group>();
{ List<GroupDao> IGroupRepository.AllGroup => throw new NotImplementedException();
return new List<Group>();
}
List<GroupLocalEntity> IGroupRepository.GetAllGroup() IEnumerable<System.Text.RegularExpressions.Group> IGroupRepository.AllGroups()
{ {
throw new NotImplementedException(); return (IEnumerable<System.Text.RegularExpressions.Group>)((IGroupRepository)_repositoryUserImpl).GetAllGroups();
} }
public bool RemoveGroupById(int groupID) public bool RemoveGroupById(int groupID)
@ -74,12 +72,12 @@ namespace Zurnal.Domain.UseCase
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup) public bool UpdateGroupById(int groupID, GroupDao updatedGroup)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public bool AddGroup(GroupLocalEntity newGroup) public bool AddGroup(GroupDao newGroup)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -89,17 +87,17 @@ namespace Zurnal.Domain.UseCase
throw new NotImplementedException(); throw new NotImplementedException();
} }
public System.Text.RegularExpressions.Group GetGroupById(int id) public GroupDao GetGroupById(int id)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IEnumerable<System.Text.RegularExpressions.Group> 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();
} }