diff --git a/.DS_Store b/.DS_Store index 013d1a5..7ab2ce5 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Data/LocalData/Entity/User.cs b/Data/LocalData/Entity/User.cs index d7f209f..1d14a68 100644 --- a/Data/LocalData/Entity/User.cs +++ b/Data/LocalData/Entity/User.cs @@ -1,5 +1,5 @@ namespace Demo.Domain.Models{ - public class UserLocalEntity{ + public class UserLocalEntity :IEquatable{ public required string FIO{get; set; } public Guid Guid {get; set; } public required int GroupID{get; set; } diff --git a/Data/Repository/GroupRepositoryImpl.cs b/Data/Repository/GroupRepositoryImpl.cs index 7a8cb9e..282cbba 100644 --- a/Data/Repository/GroupRepositoryImpl.cs +++ b/Data/Repository/GroupRepositoryImpl.cs @@ -1,12 +1,10 @@ using Demo.Domain.Models; - using Demo.Data.LocalData; namespace Demo.Data.Repository { - public class GroupRepositoryImpl + public class GroupRepositoryImpl : IGroupRepository { - // public List GetAllGroups() => LocalStaticData.groups; public GroupRepositoryImpl() { GetAllGroups = LocalStaticData.groups; @@ -14,18 +12,43 @@ namespace Demo.Data.Repository public List GetAllGroups { get; set; } - public void CreateNewGroup(GroupLocalEntity groupLocalEntity) + public List GetAllGroup() { - GetAllGroups.Add(groupLocalEntity); + return GetAllGroups; } - public GroupLocalEntity? UpdateGroup(GroupLocalEntity groupUpdateLocalEntity) + public GroupLocalEntity? CreateGroup(GroupLocalEntity groupCreateLocalEntity) { + + if (GetAllGroups.Any(x => x.ID == groupCreateLocalEntity.ID)) return null; + + GetAllGroups.Add(groupCreateLocalEntity); + return groupCreateLocalEntity; + } + + public GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup) { - int index = GetAllGroups.FindIndex(x => x.ID == groupUpdateLocalEntity.ID); + int index = GetAllGroups.FindIndex(x => x.ID == updatedGroup.ID); if (index == -1) return null; - GetAllGroups[index].Name = groupUpdateLocalEntity.Name; + GetAllGroups[index].Name = updatedGroup.Name; Console.WriteLine($"Обновленный Name: {GetAllGroups[index].Name}"); return GetAllGroups[index]; } + + public bool RemoveGroupById(int groupId) + { + GroupLocalEntity? groupLocal = GetAllGroups + .Where(x => x.ID == groupId).FirstOrDefault(); + if (groupLocal == null) return false; + + return GetAllGroups.Remove(groupLocal); + } + + public GroupLocalEntity? GetGroupById(int groupId) + { + GroupLocalEntity? grouplocal = LocalStaticData.groups.Where(x => x.ID == groupId).FirstOrDefault(); + if (grouplocal == null) return null; + + return grouplocal; + } } } \ No newline at end of file diff --git a/Data/Repository/IGroupRepository.cs b/Data/Repository/IGroupRepository.cs new file mode 100644 index 0000000..0288b8f --- /dev/null +++ b/Data/Repository/IGroupRepository.cs @@ -0,0 +1,13 @@ +using Demo.Domain.Models; + +namespace Demo.Data.Repository +{ + public interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupId); + GroupLocalEntity? UpdateGroup(GroupLocalEntity updatedGroup); + GroupLocalEntity? GetGroupById(int groupId); + GroupLocalEntity? CreateGroup(GroupLocalEntity newGroup); + } +} \ No newline at end of file diff --git a/Data/Repository/IUserRepository.cs b/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..0a6e7f5 --- /dev/null +++ b/Data/Repository/IUserRepository.cs @@ -0,0 +1,12 @@ +using Demo.Domain.Models; + +namespace Demo.Data.Repository +{ + public interface IUserRepository + { + List GetAllUser(); + bool RemoveUserByGuid(Guid userGuid); + UserLocalEntity? UpdateUserById(UserLocalEntity userUpdateLocalEntity); + UserLocalEntity? GetUserById(Guid userGuid); + } +} \ No newline at end of file diff --git a/Data/Repository/UserRepositorylmpl.cs b/Data/Repository/UserRepositorylmpl.cs index ae2438e..3b0bfef 100644 --- a/Data/Repository/UserRepositorylmpl.cs +++ b/Data/Repository/UserRepositorylmpl.cs @@ -12,6 +12,10 @@ namespace Demo.Data.Repository public List GetAllUsers { get; set; } + public List GeAllUser(){ + return GetAllUsers; + } + public bool RemoveUserByGuid(Guid userGuid) { UserLocalEntity? userLocal = GetAllUsers diff --git a/Domain/.DS_Store b/Domain/.DS_Store new file mode 100644 index 0000000..ff1bb63 Binary files /dev/null and b/Domain/.DS_Store differ diff --git a/Domain/UseCase/GroupUseCase.cs b/Domain/UseCase/GroupUseCase.cs index 790bf6c..9840676 100644 --- a/Domain/UseCase/GroupUseCase.cs +++ b/Domain/UseCase/GroupUseCase.cs @@ -5,20 +5,20 @@ namespace Demo.Domain.UseCase { public class GroupUseCase { - private GroupRepositoryImpl _repositoryGroupImpl; - private UserRepositoryImpl _repositoryUserImpl; - public GroupUseCase(GroupRepositoryImpl repositoryGroupImpl, UserRepositoryImpl repositoryUserImpl) + private readonly IUserRepository _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; + public GroupUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl) { _repositoryGroupImpl = repositoryGroupImpl; _repositoryUserImpl = repositoryUserImpl; } - public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups + public List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group{ID = it.ID, Name = it.Name}).ToList(); public bool CreateNewGroup(Group group){ GroupLocalEntity? groupLocalEntity = new GroupLocalEntity{ID = group.ID, Name = group.Name}; - _repositoryGroupImpl.CreateNewGroup(groupLocalEntity); + _repositoryGroupImpl.CreateGroup(groupLocalEntity); if (groupLocalEntity != null) return false; return true; } @@ -41,5 +41,17 @@ namespace Demo.Domain.UseCase Name = result.Name }; } + + public bool RemoveUserByGuid(Guid userGuid) { + return _repositoryUserImpl.RemoveUserByGuid(userGuid); + } + + public Group GetGroupById(int groupID) + { + GroupLocalEntity? groupLocalEntity = _repositoryGroupImpl.GetGroupById(groupID); + if (groupLocalEntity == null) throw new Exception("bello"); + return new Group{ + ID = groupID, Name = groupLocalEntity.Name}; + } } } \ No newline at end of file diff --git a/Domain/UseCase/IGroupUseCase.cs b/Domain/UseCase/IGroupUseCase.cs new file mode 100644 index 0000000..03daa67 --- /dev/null +++ b/Domain/UseCase/IGroupUseCase.cs @@ -0,0 +1,13 @@ +using Demo.Domain.Models; + +namespace Demo.Domain.UseCase +{ + public interface IGroupUseCase + { + List GetAllGroups(); + bool RemoveUserByGuid(Guid userGuid); + Group UpdateGroup(Group group); + GroupLocalEntity GetGroupById(int groupId); + bool CreateGroup(Group group); + } +} \ No newline at end of file diff --git a/Domain/UseCase/IUserUseCase.cs b/Domain/UseCase/IUserUseCase.cs new file mode 100644 index 0000000..98f2b15 --- /dev/null +++ b/Domain/UseCase/IUserUseCase.cs @@ -0,0 +1,12 @@ +using Demo.Domain.Models; + +namespace Demo.Domain.UseCase +{ + public interface IUserUseCase + { + List GetAllUsers(); + bool RemoveUserByGuid(Guid userGuid); + User UpdateUser(User user); + User GetUserByGuid(Guid userGuid); + } +} \ No newline at end of file diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index 7cac52e..b0fdb5e 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -5,20 +5,20 @@ namespace Demo.Domain.UseCase { public class UserUseCase { - private GroupRepositoryImpl _repositoryGroupImpl; - private UserRepositoryImpl _repositoryUserImpl; + private readonly IUserRepository _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; - public UserUseCase(GroupRepositoryImpl repositoryGroupImpl, UserRepositoryImpl repositoryUserImpl) + public UserUseCase(IGroupRepository repositoryGroupImpl, IUserRepository repositoryUserImpl) { _repositoryGroupImpl = repositoryGroupImpl; _repositoryUserImpl = repositoryUserImpl; } - private List GetAllGroups() => _repositoryGroupImpl.GetAllGroups + private List GetAllGroups() => _repositoryGroupImpl.GetAllGroup() .Select(it => new Group{ID = it.ID, Name = it.Name}).ToList(); - public List GetAllUsers() => _repositoryUserImpl.GetAllUsers - .Join(_repositoryGroupImpl.GetAllGroups, + public List GetAllUsers() => _repositoryUserImpl.GetAllUser() + .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.ID, (user, group) => new User{ diff --git a/obj/Debug/net8.0/Demo.AssemblyInfo.cs b/obj/Debug/net8.0/Demo.AssemblyInfo.cs index 118f4ae..d2b665f 100644 --- a/obj/Debug/net8.0/Demo.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Demo.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Demo")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d5ff9f45a55af13593d3b8a9b65ecffccf59b0a7")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+26da83afbacb32e0747365acef2fa22c2343aec8")] [assembly: System.Reflection.AssemblyProductAttribute("Demo")] [assembly: System.Reflection.AssemblyTitleAttribute("Demo")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache index 8c24bc0..d9b5ded 100644 --- a/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Demo.AssemblyInfoInputs.cache @@ -1 +1 @@ -5bce74879fd45efe103c6f650dd3b5b74cc20c28f77d21ab4268da5f80b45640 +43ed596f37cf9f6f3388e175e6bccefd2309a85ded3d7b3c846b1dde41f188e3