From 8ea8d00df0657a87405ead59386c2695b339093d Mon Sep 17 00:00:00 2001 From: Dasha Date: Wed, 23 Oct 2024 10:06:56 +0300 Subject: [PATCH] a bunch of changes --- Data/Repository/GroupRepositoryImpl.cs | 68 +++++++++-- Data/Repository/IGroupRepository.cs | 17 +++ Data/Repository/IUserRepository.cs | 17 +++ Data/Repository/UserRepositoryImpl.cs | 9 +- Domain/UseCase/GroupUseCase.cs | 10 +- Domain/UseCase/UserUseCase.cs | 9 +- Posechaemost.csproj | 4 + Program.cs | 13 +- obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs | 4 +- .../Posechaemost.AssemblyInfoInputs.cache | 2 +- obj/Debug/net8.0/Posechaemost.assets.cache | Bin 148 -> 1974 bytes ...osechaemost.csproj.AssemblyReference.cache | Bin 0 -> 1104 bytes obj/Posechaemost.csproj.nuget.dgspec.json | 6 + obj/project.assets.json | 115 +++++++++++++++++- obj/project.nuget.cache | 7 +- 15 files changed, 247 insertions(+), 34 deletions(-) create mode 100644 Data/Repository/IGroupRepository.cs create mode 100644 Data/Repository/IUserRepository.cs create mode 100644 obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache diff --git a/Data/Repository/GroupRepositoryImpl.cs b/Data/Repository/GroupRepositoryImpl.cs index cd5ade0..420d951 100644 --- a/Data/Repository/GroupRepositoryImpl.cs +++ b/Data/Repository/GroupRepositoryImpl.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -10,24 +11,69 @@ using Posechaemost.Data.LocalData.Entity; namespace Posechaemost.Data.Repository { - public class GroupRepositoryImpl + public class GroupRepositoryImpl: IGroupRepository { - public List GetAllGroups() => LocalStaticData.groups; - public GroupLocalEntity? UpdateGroup(String name) + + public bool AddGroup(String name, String id) { - GroupLocalEntity? groupLocal = GetAllGroups() - .Where(x => x.Name == name).FirstOrDefault(); - if (groupLocal == null) return null; + GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + // GroupLocalEntity? group = new GroupLocalEntity(); groupLocal.Name = name; + groupLocal.Id = int.Parse(id); + return true; + } + + public List GetAllGroup() + { + throw new NotImplementedException(); + } + + public List GetAllGroups() => LocalStaticData.groups; + + public GroupLocalEntity GetGroupById(int groupID) + { + GroupLocalEntity groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return null; return groupLocal; } - public GroupLocalEntity? AddGroup(String name, String id) + public bool RemoveGroupById(int groupID) { - GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return false; + + return GetAllGroups().Remove(groupLocal); + } + + public bool UpdateGroupById(int groupID, String name) + { + GroupLocalEntity? groupLocal = GetAllGroups() + .Where(x => x.Id == groupID).FirstOrDefault(); + if (groupLocal == null) return false; groupLocal.Name = name; - groupLocal.Id = int.Parse(id); - return groupLocal; + return true; } } -} \ No newline at end of file +} + // { + // public List GetAllGroups() => LocalStaticData.groups; + // public GroupLocalEntity? UpdateGroup(String name) + // { + // GroupLocalEntity? groupLocal = GetAllGroups() + // .Where(x => x.Name == name).FirstOrDefault(); + // if (groupLocal == null) return null; + // groupLocal.Name = name; + // return groupLocal; + // } + + // public GroupLocalEntity? AddGroup(String name, String id) + // { + // GroupLocalEntity? groupLocal = GetAllGroups().FirstOrDefault(); + // // GroupLocalEntity? group = new GroupLocalEntity(name, id); + // groupLocal.Name = name; + // groupLocal.Id = int.Parse(id); + // 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..a905320 --- /dev/null +++ b/Data/Repository/IGroupRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Posechaemost.Data.LocalData.Entity; + +namespace Posechaemost.Data.Repository { + public interface IGroupRepository + { + List GetAllGroup(); + bool RemoveGroupById(int groupID); + bool UpdateGroupById(int groupID, String name); + GroupLocalEntity GetGroupById(int groupID); + bool AddGroup(String name, String id); + } +} \ No newline at end of file diff --git a/Data/Repository/IUserRepository.cs b/Data/Repository/IUserRepository.cs new file mode 100644 index 0000000..434d230 --- /dev/null +++ b/Data/Repository/IUserRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Posechaemost.Data.LocalData.Entity; + +namespace Posechaemost.Data.Repository { + public interface IUserRepository + { + List GetAllUser(); + bool RemoveUserByGuid(Guid userGuid); + UserLocalEntity? GetUserByGuid(Guid userGuid); + UserLocalEntity? UpdateUser(UserLocalEntity userUpdateLocalEnity); + UserLocalEntity? UpdateUserByGuid(Guid userGuid); + } +} \ No newline at end of file diff --git a/Data/Repository/UserRepositoryImpl.cs b/Data/Repository/UserRepositoryImpl.cs index bfd4af8..40ac56d 100644 --- a/Data/Repository/UserRepositoryImpl.cs +++ b/Data/Repository/UserRepositoryImpl.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using Posechaemost.Data.LocalData; @@ -9,12 +8,18 @@ using Posechaemost.Data.LocalData.Entity; namespace Posechaemost.Data.Repository { - public class UserRepositoryImpl + public class UserRepositoryImpl: IUserRepository { public UserRepositoryImpl() { GetAllUsers = LocalStaticData.users; } + + public List GetAllUser() + { + throw new NotImplementedException(); + } + public List GetAllUsers { get; set; } diff --git a/Domain/UseCase/GroupUseCase.cs b/Domain/UseCase/GroupUseCase.cs index 8e1f375..b50305b 100644 --- a/Domain/UseCase/GroupUseCase.cs +++ b/Domain/UseCase/GroupUseCase.cs @@ -21,14 +21,10 @@ namespace Posechaemost.Domain.UseCase public List GetAllGroups() => _repositoryGroupImpl.GetAllGroups() .Select(it => new Group { Id = it.Id, Name = it.Name}).ToList(); - public Group UpdateGroupName(String name, String name1) { - GroupLocalEntity? result = _repositoryGroupImpl.UpdateGroup(name); - if (result == null) throw new Exception(""); - Group? group = GetAllGroups().FirstOrDefault(it => it.Name == result.Name); - if (group == null) throw new Exception(""); - return new Group {Id = group.Id, Name = name1}; + public bool UpdateGroupName(String id, String name1) { + return _repositoryGroupImpl.UpdateGroupById(int.Parse(id), name1); } - public GroupLocalEntity AddGroup(String name, String id) + public bool AddGroup(String name, String id) { return _repositoryGroupImpl.AddGroup(name, id); } diff --git a/Domain/UseCase/UserUseCase.cs b/Domain/UseCase/UserUseCase.cs index e3cd964..e20a852 100644 --- a/Domain/UseCase/UserUseCase.cs +++ b/Domain/UseCase/UserUseCase.cs @@ -11,8 +11,9 @@ namespace Posechaemost.Domain.UseCase { public class UserUseCase { - private UserRepositoryImpl _repositoryUserImpl; - private GroupRepositoryImpl _repositoryGroupImpl; + + private readonly UserRepositoryImpl _repositoryUserImpl; + private readonly IGroupRepository _repositoryGroupImpl; public UserUseCase(UserRepositoryImpl repositoryImpl, GroupRepositoryImpl repositoryGroupImpl) { @@ -20,10 +21,10 @@ namespace Posechaemost.Domain.UseCase _repositoryGroupImpl = repositoryGroupImpl; } - public 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(), + .Join(_repositoryGroupImpl.GetAllGroup(), user => user.GroupID, group => group.Id, (user, group) => diff --git a/Posechaemost.csproj b/Posechaemost.csproj index 2150e37..434708c 100644 --- a/Posechaemost.csproj +++ b/Posechaemost.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/Program.cs b/Program.cs index 733ec2e..29074e5 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,19 @@ using Posechaemost.Data.Repository; using Posechaemost.Domain.UseCase; using Posechaemost.UI; +using Microsoft.Extensions.DependencyInjection; +using System.Text.RegularExpressions; + +IServiceCollection services = new ServiceCollection(); + +services + .AddSingleton() + .AddSingleton(); + +var serviceProvider = services.BuildServiceProvider(); GroupRepositoryImpl groupRepositoryImpl = new GroupRepositoryImpl(); -UserRepositoryImpl userRepositoryImpl = new UserRepositoryImpl(); -UserUseCase userUseCase = new UserUseCase(userRepositoryImpl, groupRepositoryImpl); +UserUseCase userUseCase = serviceProvider.GetService(); GroupUseCase groupUseCase = new GroupUseCase(groupRepositoryImpl); MainMenuUI mainMenuUI = new MainMenuUI(userUseCase, groupUseCase); \ No newline at end of file diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs index 0b70887..ebe20e9 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1305f40f241ce752d3c0a7ec5341b1eafac497d8")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+36a123355e04422229f0afaff5d2c6d503a8419e")] [assembly: System.Reflection.AssemblyProductAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyTitleAttribute("Posechaemost")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache index a0f7286..7218ff6 100644 --- a/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache +++ b/obj/Debug/net8.0/Posechaemost.AssemblyInfoInputs.cache @@ -1 +1 @@ -7a59f60438c72dd05578b09f953c9ba9d3343469014f076958deeba098123188 +c78a5718d92cc56f307f18b87610c16cd6bd4adb899ce2e54039bee5d3d6ceb2 diff --git a/obj/Debug/net8.0/Posechaemost.assets.cache b/obj/Debug/net8.0/Posechaemost.assets.cache index 94de1e1daa8ac65c98c717fa90fc8ae6bdd0f31c..b10d4ef5e1ebca07af93355b95f5c7829415895a 100644 GIT binary patch literal 1974 zcmd5-L2DC16i(}=Nz~T1u_}o79%QD5ih2x2%Tg^tgGXVq`;v~%&MrH%(&(wTg7^!> zi$6d-3H5(?te{@JdG_Xe+f5v#lqCr5gO6cm=goZY+xOmdH#genE0xOE*Y%$Vzuqi; zZ+(0JV?BBruf7|6*xUd8@zu3%@6+cmFRQqzuvr{;XZUs;0UwG~aHg{%Se}UBxfp`s zkqpwO6VH2pJv$Rmf9%OZ zrOp&|W^g1*H1`n1^zHwk$3)-QROD1m&b2ia*S2$vOMDKA67d>>h}RKE8SPmus|+1* zv+QQ(QX@~&l9ly7{Cy;Mqi{WoBmIVR2+FE?!~)_1Vi7^dUp*#q@N=%nNoUtiq)2o! zH@i-6Ryl;-tfBxYkdxLEtCeVxxq6PPbqUv(5lzHJ#0ugP;`Hk61mx;HuHvHtx{Lw2 zb_FL3TiFKK?qT2b!_r0Gbp4({N*%VEH`Dp9u-m>aj=VKxYn`rv*mSDruV?`>@W literal 148 zcmWIWc6a1qU|_JSE|&XK>z>eL{4+Rnldi~hnH-zUy&Wo(C8wBQ)zG*z0jP#pzz9?* it)G#fo2s9lSd^%*msgseTB2W&n4F!Mo?5I=$Q%Gv&>2Gj diff --git a/obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache b/obj/Debug/net8.0/Posechaemost.csproj.AssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..ecd6f6f4a20e71ae26a55e8494c6f996dcfa99fa GIT binary patch literal 1104 zcmZQ$WMW`oU~FX6&&bbB)lW|>O4QfOD@{)=(Jx3$&Q45EE!NM?OfJeV&QB}RORXqL z%`48#&nwnTNi9gtOG(X3uFTBKN=+^S3hGP8Ay2HuMidK`K*0gLXI^oCN#V7ToFMZ{YZ};ZL z*V_iIQGU{ORD$v2ovB>=Cde-K)tYC$>b8iK`0={WM^o>{J!SQtcs_ZzP1X+kqSaRG zU)u5?K4j8e=D&W!#skH+Pemfvt#*rGZrMM#Yotpra6$S_Fz0TTm1Lp^k!cX--LLQL1fTYH3MPVvdeNKxtA=X0mr` zWk`N@YMyOkN|L3yrLl#PWlBn7s+j>Oa6o`@HZ_uhUSd))&{}Y^C= 8.0.1" + ] }, "packageFolders": { "/home/gara/.nuget/packages/": {} @@ -48,6 +151,12 @@ "frameworks": { "net8.0": { "targetAlias": "net8.0", + "dependencies": { + "Microsoft.Extensions.DependencyInjection": { + "target": "Package", + "version": "[8.0.1, )" + } + }, "imports": [ "net461", "net462", diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index cd49dd2..0bb2067 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,8 +1,11 @@ { "version": 2, - "dgSpecHash": "3K0+oSHYQvE=", + "dgSpecHash": "JxuWkwCqUKY=", "success": true, "projectFilePath": "/home/gara/csharp/Posechaemost/Posechaemost.csproj", - "expectedPackageFiles": [], + "expectedPackageFiles": [ + "/home/gara/.nuget/packages/microsoft.extensions.dependencyinjection/8.0.1/microsoft.extensions.dependencyinjection.8.0.1.nupkg.sha512", + "/home/gara/.nuget/packages/microsoft.extensions.dependencyinjection.abstractions/8.0.2/microsoft.extensions.dependencyinjection.abstractions.8.0.2.nupkg.sha512" + ], "logs": [] } \ No newline at end of file