From ac0c8401da4b7e21c62352026c9fecef06f27728 Mon Sep 17 00:00:00 2001 From: Userok Date: Fri, 25 Oct 2024 12:20:05 +0300 Subject: [PATCH] Pravki --- Zurnal/Date/Repository/UserRepositoryImpl.cs | 48 ++++++++++-- Zurnal/Domain/UseCase/UserUseCase.cs | 74 ++++++++++++------- .../Interfase/IGroupRepository.cs | 21 +----- .../Interfase/IPresenceRepository.cs | 9 +++ .../RemaDateBase/Interfase/IUserRepository.cs | 10 +++ Zurnal/RemaDateBase/RemoutDateBase.cs | 4 +- .../obj/Debug/net8.0/Zurnal.AssemblyInfo.cs | 11 ++- .../net8.0/Zurnal.AssemblyInfoInputs.cache | 2 +- 8 files changed, 117 insertions(+), 62 deletions(-) create mode 100644 Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs create mode 100644 Zurnal/RemaDateBase/Interfase/IUserRepository.cs diff --git a/Zurnal/Date/Repository/UserRepositoryImpl.cs b/Zurnal/Date/Repository/UserRepositoryImpl.cs index ec63fa9..400966e 100644 --- a/Zurnal/Date/Repository/UserRepositoryImpl.cs +++ b/Zurnal/Date/Repository/UserRepositoryImpl.cs @@ -6,17 +6,16 @@ namespace Zurnal.Data.Repository { public class UserRepositoryImpl : IGroupRepository { - public UserRepositoryImpl() { - GetAllUsers = LocalStaticData.users; - } - + public UserRepositoryImpl() => GetAllUsers = LocalStaticData.users; + public List GetAllUsers { get; set; } public bool RemoveUserByGuid(Guid userGuid) { UserLocalEnity? userLocal = GetAllUsers - .Where(x => x.Guid == userGuid).FirstOrDefault(); + .Where(x => x.Guid == userGuid) + .FirstOrDefault(); if (userLocal == null) return false; return GetAllUsers.Remove(userLocal); @@ -40,10 +39,10 @@ namespace Zurnal.Data.Repository } public List GetAllUsersList() { - return GetAllUsers; + return GetAllUsersList; } - List IGroupRepository.GetAllGroup() + List IGroupRepository.GetAllGroups() { throw new NotImplementedException(); } @@ -67,6 +66,41 @@ namespace Zurnal.Data.Repository { throw new NotImplementedException(); } + + internal object GetAllUsers() + { + throw new NotImplementedException(); + } + + public void AddGroup(System.Text.RegularExpressions.Group group) + { + throw new NotImplementedException(); + } + + public System.Text.RegularExpressions.Group GetGroupById(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAllGroups() + { + throw new NotImplementedException(); + } + + public void UpdateGroup(System.Text.RegularExpressions.Group group) + { + throw new NotImplementedException(); + } + + public void DeleteGroup(int id) + { + throw new NotImplementedException(); + } + + public object GetAllGroup() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Zurnal/Domain/UseCase/UserUseCase.cs b/Zurnal/Domain/UseCase/UserUseCase.cs index 1aca31e..4b46c67 100644 --- a/Zurnal/Domain/UseCase/UserUseCase.cs +++ b/Zurnal/Domain/UseCase/UserUseCase.cs @@ -1,45 +1,63 @@ using Zurnal.Data.Repository; using Zurnal.domain.Models; -using Zurnal.Date.Repository; namespace Zurnal.Domain.UseCase { - public class UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) + public class UserUseCase { - private UserRepositoryImpl _repositoryUserImpl = repositoryImpl; + private readonly UserRepositoryImpl _repositoryUserImpl; + internal IGroupRepository RepositoryGroupImpl { get; } - internal IGroupRepository RepositoryGroupImpl { get; } = (IGroupRepository?)repositoryGroupImpl; + public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) + { + _repositoryUserImpl = repositoryImpl; + RepositoryGroupImpl = repositoryGroupImpl; + } - public List GetAllGroups() => RepositoryGroupImpl.GetAllGroup() - .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public List GetAllUsers() => _repositoryUserImpl.GetAllUsers + public List GetAllGroups() + { + return RepositoryGroupImpl.GetAllGroup() + .Select(it => new Group { Id = it.Id, Name = it.Name }).ToList(); + } + + public List GetAllUsers() => _repositoryUserImpl.GetAllUsers() .Join(RepositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.Id, (user, group) => new User { FIO = user.FIO, Guid = user.Guid, - Group = new Group {Id = group.Id, Name = group.Name } } - ).ToList(); + Group = new Group { Id = group.Id, Name = group.Name } } + ).ToList(); - public bool RemoveUserByGuid(Guid userGuid) { - return _repositoryUserImpl.RemoveUserByGuid(userGuid); + public bool RemoveUserByGuid(Guid userGuid) + { + return _repositoryUserImpl.RemoveUserByGuid(userGuid); } - public User UpdateUser(User user) { - UserLocalEnity userLocalEnity = new UserLocalEnity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; - UserLocalEnity? result = _repositoryUserImpl.UpdateUser(userLocalEnity); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Id == result!.GroupID); - if (group == null) throw new Exception("Группа не найдена"); - return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; + + public User UpdateUser(User user) + { + UserLocalEnity userLocalEntity = new UserLocalEntity { FIO = user.FIO, GroupID = user.Group.Id, Guid = user.Guid }; + 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 }; + } + + public User FindUserByGuid(Guid userGuid) + { + var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid); + if (user == null) throw new Exception("User not found."); + var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID); + return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; + } + } + + internal class UserLocalEntity +{ + public string FIO { get; set; } + public Guid GroupID { get; set; } + public Guid Guid { get; set; } } - - public User FindUserByGuid(Guid userGuid) - { - var user = _repositoryUserImpl.GetAllUsersList().FirstOrDefault(u => u.Guid == userGuid); - if (user == null) throw new Exception("Нет такого пользователя"); - var group = RepositoryGroupImpl.GetAllGroup().FirstOrDefault(g => g.Id == user.GroupID); - return new User { FIO = user.FIO, Guid = user.Guid, Group = group }; - } - } - } \ No newline at end of file +} \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IGroupRepository.cs b/Zurnal/RemaDateBase/Interfase/IGroupRepository.cs index cf87d5d..f637828 100644 --- a/Zurnal/RemaDateBase/Interfase/IGroupRepository.cs +++ b/Zurnal/RemaDateBase/Interfase/IGroupRepository.cs @@ -11,22 +11,7 @@ public interface IGroupRepository void UpdateGroup(Group group); void DeleteGroup(int id); object GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, GroupLocalEntity updatedGroup); } - - public interface IUserRepository - { - void AddUser(User user); - User GetUserById(int id); - IEnumerable GetAllUsers(); - void UpdateUser(User user); - void DeleteUser(int id); - } - - public interface IPresenceRepository - { - void AddPresence(Presence presence); - Presence GetPresenceById(int id); - IEnumerable GetAllPresences(); - void UpdatePresence(Presence presence); - void DeletePresence(int id); - } \ No newline at end of file + \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs new file mode 100644 index 0000000..49240ed --- /dev/null +++ b/Zurnal/RemaDateBase/Interfase/IPresenceRepository.cs @@ -0,0 +1,9 @@ +using Zurnal.domain.Models; +public interface IPresenceRepository +{ + void AddPresence(Presence presence); + Presence GetPresenceById(int id); + IEnumerable GetAllPresences(); + void UpdatePresence(Presence presence); + void DeletePresence(int id); +} \ No newline at end of file diff --git a/Zurnal/RemaDateBase/Interfase/IUserRepository.cs b/Zurnal/RemaDateBase/Interfase/IUserRepository.cs new file mode 100644 index 0000000..23a7f51 --- /dev/null +++ b/Zurnal/RemaDateBase/Interfase/IUserRepository.cs @@ -0,0 +1,10 @@ +using Zurnal.domain.Models; + +public interface IUserRepository +{ + void AddUser(User user); + User GetUserById(int id); + IEnumerable GetAllUsers(); + void UpdateUser(User user); + void DeleteUser(int id); +} \ No newline at end of file diff --git a/Zurnal/RemaDateBase/RemoutDateBase.cs b/Zurnal/RemaDateBase/RemoutDateBase.cs index 88a4695..0591a96 100644 --- a/Zurnal/RemaDateBase/RemoutDateBase.cs +++ b/Zurnal/RemaDateBase/RemoutDateBase.cs @@ -11,7 +11,7 @@ public class RemoteDateBaseContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Username=postgres;Password=123;Database=postgres"); + optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5432;Username=postgres;Password= ;Database=user1"); } protected override void OnModelCreating(ModelBuilder modelBuilder) @@ -30,4 +30,4 @@ public class RemoteDateBaseContext : DbContext presence.LessonNumber }); } -} +} \ No newline at end of file diff --git a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs index eb15329..ac0d0cf 100644 --- a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs +++ b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfo.cs @@ -1,10 +1,9 @@ //------------------------------------------------------------------------------ // -// Этот код создан программой. -// Исполняемая версия:4.0.30319.42000 +// This code was generated by a tool. // -// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае -// повторной генерации кода. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -14,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Zurnal")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3c2a052a46be0d31bde662e889b1125d89b34ddf")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1b2b3fc51b8e6c70458156ed95a4cc212f9e51a9")] [assembly: System.Reflection.AssemblyProductAttribute("Zurnal")] [assembly: System.Reflection.AssemblyTitleAttribute("Zurnal")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache index c86c0e2..323e6ae 100644 --- a/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache +++ b/Zurnal/obj/Debug/net8.0/Zurnal.AssemblyInfoInputs.cache @@ -1 +1 @@ -c93eabaca987d32605ba5a086a447483e47422719e2959ace2200ffe485e77e0 +e6b6f9e54fa4ba82e681a5a3ba9349d7912311711fddca257c129394bd4b3c36