diff --git a/Presence.Api/Controllers/GroupController.cs b/Presence.Api/Controllers/GroupController.cs index 7d48a98..f692ba0 100644 --- a/Presence.Api/Controllers/GroupController.cs +++ b/Presence.Api/Controllers/GroupController.cs @@ -16,18 +16,19 @@ namespace Presence.Api.Controllers _groupService = groupService; } - [HttpGet] - public ActionResult GetAllGroups() + [HttpGet("/group")] + public async Task> GetAllGroups() { var result = _groupService - .GetGroupsWithStudents() + .GetGroupsWithStudents(); + var response = result .Select(group => new GroupResponse { Id = group.Id, Name = group.Name, Users = group.Users.Select(user => new UserResponse { Guid = user.Guid, Name = user.Name - }).Take(10).ToList(), + }).ToList(), }).ToList(); return Ok(new GroupResponse()); } diff --git a/Presence.Desktop/Models/GroupPresenter.cs b/Presence.Desktop/Models/GroupPresenter.cs new file mode 100644 index 0000000..eb8c3be --- /dev/null +++ b/Presence.Desktop/Models/GroupPresenter.cs @@ -0,0 +1,17 @@ +using Avalonia.Controls; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.Models +{ + public class GroupPresenter + { + public int Id { get; set; } + public string Name { get; set; } + public IEnumerable? users { get; set; } = null; + } +} \ No newline at end of file diff --git a/Presence.Desktop/Models/UserPresenter.cs b/Presence.Desktop/Models/UserPresenter.cs new file mode 100644 index 0000000..3a8b4a8 --- /dev/null +++ b/Presence.Desktop/Models/UserPresenter.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Presence.Desktop.Models +{ + public class UserPresenter + { + public Guid Guid { get; set; } + public string Name { get; set; } + public GroupPresenter Group { get; set; } + } +} \ No newline at end of file diff --git a/Presence.Desktop/Presence.Desktop.csproj b/Presence.Desktop/Presence.Desktop.csproj index 92a908c..33feb38 100644 --- a/Presence.Desktop/Presence.Desktop.csproj +++ b/Presence.Desktop/Presence.Desktop.csproj @@ -9,7 +9,6 @@ - diff --git a/Presence.Desktop/ViewModels/MainWindowViewModel.cs b/Presence.Desktop/ViewModels/MainWindowViewModel.cs index f92cbe7..a15d737 100644 --- a/Presence.Desktop/ViewModels/MainWindowViewModel.cs +++ b/Presence.Desktop/ViewModels/MainWindowViewModel.cs @@ -1,15 +1,73 @@ using domain.UseCase; +using DynamicData; +using DynamicData.Binding; +using Presence.Desktop.Models; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reactive.Linq; +using Tmds.DBus.Protocol; namespace Presence.Desktop.ViewModels { public class MainWindowViewModel : ViewModelBase { private readonly IGroupUseCase _groupService; - public MainWindowViewModel(IGroupUseCase groupService) + private List groupPresentersDataSource = new List(); + private ObservableCollection _groups; + public ObservableCollection Groups => _groups; + + public GroupPresenter? SelectedGroupItem { - _groupService = groupService; + get => _selectedGroupItem; + set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); } - public string Greeting { get; } = "Welcome to Avalonia!"; + private GroupPresenter? _selectedGroupItem; + + public ObservableCollection Users { get => _users; } + public ObservableCollection _users; + public MainWindowViewModel(IGroupUseCase groupUseCase) + { + _groupService = groupUseCase; + + foreach (var item in _groupService.GetGroupsWithStudents()) + { + GroupPresenter groupPresenter = new GroupPresenter + { + Id = item.Id, + Name = item.Name, + users = item.Users?.Select(user => new UserPresenter + { + Name = user.Name, + Guid = user.Guid, + Group = new GroupPresenter { Id = item.Id, Name = item.Name } + } + ).ToList() + }; + groupPresentersDataSource.Add(groupPresenter); + } + _groups = new ObservableCollection(groupPresentersDataSource); + + _users = new ObservableCollection(); + + this.WhenAnyValue(vm => vm.SelectedGroupItem) + .Subscribe(_ => SetUsers()); + + } + + private void SetUsers() + { + if (SelectedGroupItem == null) return; + if (SelectedGroupItem.users == null) return; + Users.Clear(); + foreach (var item in SelectedGroupItem.users) + { + Users.Add(item); + } + } } } + diff --git a/Presence.Desktop/Views/MainWindow.axaml b/Presence.Desktop/Views/MainWindow.axaml index a158e7f..d7f4c81 100644 --- a/Presence.Desktop/Views/MainWindow.axaml +++ b/Presence.Desktop/Views/MainWindow.axaml @@ -9,12 +9,40 @@ Icon="/Assets/avalonia-logo.ico" Title="Presence.Desktop"> - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/Repository/IGroupRepository.cs b/data/Repository/IGroupRepository.cs index 5be29fb..5bee0c6 100644 --- a/data/Repository/IGroupRepository.cs +++ b/data/Repository/IGroupRepository.cs @@ -10,6 +10,7 @@ namespace data.Repository public interface IGroupRepository { public IEnumerable getAllGroup(); + public Task> getAllGroupAsync(); public bool addGroup(GroupDAO group); public bool addGroupWithStudents(GroupDAO group, IEnumerable userDAOs); } diff --git a/data/Repository/SQLGroupRepository.cs b/data/Repository/SQLGroupRepository.cs index 2c34b3b..25bcdbb 100644 --- a/data/Repository/SQLGroupRepository.cs +++ b/data/Repository/SQLGroupRepository.cs @@ -59,5 +59,10 @@ namespace data.Repository } return false; } + + public async Task> getAllGroupAsync() + { + return await dbContext.groups.Include(group => group.Users).ToListAsync(); + } } } diff --git a/domain/Entity/GroupEntity.cs b/domain/Entity/GroupEntity.cs index 2bdbe91..7bf6fe6 100644 --- a/domain/Entity/GroupEntity.cs +++ b/domain/Entity/GroupEntity.cs @@ -10,7 +10,7 @@ namespace domain.Entity { public int Id { get; set; } public string Name { get; set; } - public IEnumerable Users { get; set; } = null; + public List Users { get; set; } = null; } } diff --git a/domain/Service/GroupService.cs b/domain/Service/GroupService.cs index 21368cf..d3877d8 100644 --- a/domain/Service/GroupService.cs +++ b/domain/Service/GroupService.cs @@ -52,5 +52,28 @@ namespace domain.Service }).ToList() }).ToList(); } + + public async Task> GetGroupsWithStudentsAsync() + { + var result = await _groupRepository.getAllGroupAsync(); + + return result.Select( + group => new GroupEntity + { + Id = group.Id, + Name = group.Name, + Users = group.Users.Select( + user => new UserEntity + { + Guid = user.Guid, + Name = user.Name, + Group = new GroupEntity + { + Id = group.Id, + Name = group.Name, + } + }).ToList() + }).ToList(); + } } } diff --git a/domain/UseCase/IGroupUseCase.cs b/domain/UseCase/IGroupUseCase.cs index 7e027d8..a0d65dd 100644 --- a/domain/UseCase/IGroupUseCase.cs +++ b/domain/UseCase/IGroupUseCase.cs @@ -11,6 +11,7 @@ namespace domain.UseCase public interface IGroupUseCase { public IEnumerable GetGroupsWithStudents(); + public Task> GetGroupsWithStudentsAsync(); public void AddGroup(AddGroupRequest addGroupRequest); public void AddGroupWithStudents(AddGroupWithStudentsRequest addGroupWithStudents); } diff --git a/semesterWork.sln b/semesterWork.sln index 0ad426e..1f99b92 100644 --- a/semesterWork.sln +++ b/semesterWork.sln @@ -7,7 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_ui", "console_ui\co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{28FE5F1E-5D2B-4750-AE24-A15BB8A5972D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "domain", "domain\domain.csproj", "{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain", "domain\domain.csproj", "{78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Presence.Api", "Presence.Api\Presence.Api.csproj", "{0493354A-C0C0-49FC-A143-28F2268309E2}" + ProjectSection(ProjectDependencies) = postProject + {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63} = {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presence.Desktop", "Presence.Desktop\Presence.Desktop.csproj", "{D646BC7E-8025-4985-AF9B-5E4474AD7F66}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +34,14 @@ Global {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Debug|Any CPU.Build.0 = Debug|Any CPU {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Release|Any CPU.ActiveCfg = Release|Any CPU {78C8AC9B-2B4D-4C71-8469-C6DAE16C9A63}.Release|Any CPU.Build.0 = Release|Any CPU + {0493354A-C0C0-49FC-A143-28F2268309E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0493354A-C0C0-49FC-A143-28F2268309E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0493354A-C0C0-49FC-A143-28F2268309E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0493354A-C0C0-49FC-A143-28F2268309E2}.Release|Any CPU.Build.0 = Release|Any CPU + {D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D646BC7E-8025-4985-AF9B-5E4474AD7F66}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE