From bec6af93879164a393f78b31385eaa50c1df2f99 Mon Sep 17 00:00:00 2001 From: Amadeusz Nowak Date: Sat, 18 May 2024 14:28:04 +0200 Subject: [PATCH 01/11] (#57) update frontend for organizations to work --- .../Organizations/IOrganizationsService.cs | 14 +++-- .../Organizations/OrganizationsService.cs | 38 +++++++++---- .../DTO/OrganizationDetailsDto.cs | 2 - .../src/MiniSpace.Web/DTO/OrganizationDto.cs | 2 - .../Admin/Dialogs/AddOrganizationDialog.razor | 18 ++++-- .../Dialogs/OrganizationDetailsDialog.razor | 5 +- .../Pages/Admin/ManageOrganizations.razor | 55 +++++++------------ .../Pages/Events/EventCreate.razor | 17 +++++- 8 files changed, 83 insertions(+), 68 deletions(-) diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/IOrganizationsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/IOrganizationsService.cs index cefb8d315..9e2f6f145 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/IOrganizationsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/IOrganizationsService.cs @@ -10,13 +10,15 @@ namespace MiniSpace.Web.Areas.Organizations { public interface IOrganizationsService { - Task GetOrganizationAsync(Guid organizationId); - Task GetOrganizationDetailsAsync(Guid organizationId); + Task GetOrganizationAsync(Guid organizationId, Guid rootId); + Task GetOrganizationDetailsAsync(Guid organizationId, Guid rootId); Task> GetOrganizerOrganizationsAsync(Guid organizerId); Task> GetRootOrganizationsAsync(); - Task> GetChildrenOrganizationsAsync(Guid organizationId); - Task> AddOrganization(Guid organizationId, string name, Guid parentId); - Task AddOrganizerToOrganization(Guid organizationId, Guid organizerId); - Task RemoveOrganizerFromOrganization(Guid organizationId, Guid organizerId); + Task> GetChildrenOrganizationsAsync(Guid organizationId, Guid rootId); + Task> GetAllChildrenOrganizationsAsync(Guid organizationId, Guid rootId); + Task> CreateOrganization(Guid organizationId, string name, Guid rootId, Guid parentId); + Task> CreateRootOrganization(Guid organizationId, string name); + Task AddOrganizerToOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId); + Task RemoveOrganizerFromOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId); } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/OrganizationsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/OrganizationsService.cs index f447a01fb..0e53c2249 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/OrganizationsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Organizations/OrganizationsService.cs @@ -18,16 +18,16 @@ public OrganizationsService(IHttpClient httpClient, IIdentityService identitySer _identityService = identityService; } - public Task GetOrganizationAsync(Guid organizationId) + public Task GetOrganizationAsync(Guid organizationId, Guid rootId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); - return _httpClient.GetAsync($"organizations/{organizationId}"); + return _httpClient.GetAsync($"organizations/{organizationId}?rootId={rootId}"); } - public Task GetOrganizationDetailsAsync(Guid organizationId) + public Task GetOrganizationDetailsAsync(Guid organizationId, Guid rootId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); - return _httpClient.GetAsync($"organizations/{organizationId}/details"); + return _httpClient.GetAsync($"organizations/{organizationId}/details?rootId={rootId}"); } public Task> GetOrganizerOrganizationsAsync(Guid organizerId) @@ -42,30 +42,44 @@ public Task> GetRootOrganizationsAsync() return _httpClient.GetAsync>("organizations/root"); } - public Task> GetChildrenOrganizationsAsync(Guid organizationId) + public Task> GetChildrenOrganizationsAsync(Guid organizationId, Guid rootId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); return _httpClient.GetAsync> - ($"organizations/{organizationId}/children?parentId={organizationId}"); + ($"organizations/{organizationId}/children?rootId={rootId}"); } - public Task> AddOrganization(Guid organizationId, string name, Guid parentId) + public Task> GetAllChildrenOrganizationsAsync(Guid organizationId, Guid rootId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); - return _httpClient.PostAsync("organizations", new {organizationId, name, parentId}); + return _httpClient.GetAsync> + ($"organizations/{organizationId}/children/all?rootId={rootId}"); } - public Task AddOrganizerToOrganization(Guid organizationId, Guid organizerId) + public Task> CreateOrganization(Guid organizationId, string name, Guid rootId, Guid parentId) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.PostAsync($"organizations/{organizationId}/children", + new {organizationId, name, rootId, parentId}); + } + + public Task> CreateRootOrganization(Guid organizationId, string name) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.PostAsync("organizations", new {organizationId, name}); + } + + public Task AddOrganizerToOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); return _httpClient.PostAsync($"organizations/{organizationId}/organizer", - new {organizationId, organizerId}); + new {rootOrganizationId, organizationId, organizerId}); } - public Task RemoveOrganizerFromOrganization(Guid organizationId, Guid organizerId) + public Task RemoveOrganizerFromOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); - return _httpClient.DeleteAsync($"organizations/{organizationId}/organizer/{organizerId}"); + return _httpClient.DeleteAsync($"organizations/{organizationId}/organizer/{organizerId}?rootOrganizationId={rootOrganizationId}"); } } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs index dfaa9bd93..5f9b27477 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs @@ -7,8 +7,6 @@ public class OrganizationDetailsDto { public Guid Id { get; set; } public string Name { get; set; } - public Guid ParentId { get; set; } - public bool IsLeaf { get; set; } public IEnumerable Organizers { get; set; } } } \ No newline at end of file diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs index 91138784b..45c4f9c6f 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs @@ -6,7 +6,5 @@ public class OrganizationDto { public Guid Id { get; set; } public string Name { get; set; } - public Guid ParentId { get; set; } - public bool IsLeaf { get; set; } } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor index cb5c3adb4..aa0741c85 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor @@ -1,6 +1,5 @@ @page "/admin/organizations/add" @using Radzen -@using MiniSpace.Web.DTO @using MiniSpace.Web.Areas.Organizations @inject IOrganizationsService OrganizationsService @inject NavigationManager NavigationManager @@ -12,7 +11,7 @@ - + @@ -35,10 +34,12 @@ @code { [Parameter] - public OrganizationDto NewOrganization { get; set; } + public ManageOrganizations.ParentOrganization ParentOrganization { get; set; } [Parameter] public bool IsRootOrganization { get; set; } + private string newOrganizationName { get; set; } + protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -46,8 +47,15 @@ private async void HandleAddingNewOrganization() { - await OrganizationsService.AddOrganization(Guid.Empty, NewOrganization.Name, - IsRootOrganization ? Guid.Empty : NewOrganization.ParentId); + if (IsRootOrganization) + { + await OrganizationsService.CreateRootOrganization(Guid.Empty, newOrganizationName); + } + else + { + await OrganizationsService.CreateOrganization(Guid.Empty, newOrganizationName, + ParentOrganization.RootId, ParentOrganization.Id); + } DialogService.Close(true); } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor index da04a5bc7..f2532389f 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor @@ -59,14 +59,15 @@ @code { [Parameter] - public Guid OrganizationId { get; set; } + public ManageOrganizations.ParentOrganization ParentOrganization { get; set; } public OrganizationDetailsDto OrganizationDetailsDto { get; set; } = new(); private Guid selectedOrganizer; protected override async Task OnInitializedAsync() { - OrganizationDetailsDto = await OrganizationsService.GetOrganizationDetailsAsync(OrganizationId); + OrganizationDetailsDto = await OrganizationsService.GetOrganizationDetailsAsync(ParentOrganization.Id, + ParentOrganization.RootId); await base.OnInitializedAsync(); } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor index 866304685..72ea336e3 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor @@ -24,9 +24,9 @@ else + Click="@(() => OpenAddOrganizationDialog((ParentOrganization)selectedItem, true))" /> + Click="@(() => OpenAddOrganizationDialog((ParentOrganization)selectedItem, false))" /> - + @if (totalRootOrganizations == 0) {

There are not any organizations created.

} - + @@ -61,8 +61,7 @@ else { public Guid Id { get; set; } public string Name { get; set; } - public Guid ParentId { get; set; } - public bool IsLeaf { get; set; } + public Guid RootId { get; set; } public List Children { get; set; } } @@ -74,7 +73,7 @@ else if (IdentityService.IsAuthenticated && IdentityService.GetCurrentUserRole() == "admin") { var tmpOrganizations = await OrganizationsService.GetRootOrganizationsAsync(); - ConvertOrganizationDtoList(tmpOrganizations, rootOrganizations); + ConvertOrganizationDtoList(tmpOrganizations, rootOrganizations, null); totalRootOrganizations = rootOrganizations.Count; } @@ -84,12 +83,12 @@ else private async void OnExpand(TreeExpandEventArgs args) { var parent = (ParentOrganization)args.Value; - var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(parent.Id); - ConvertOrganizationDtoList(childOrganizations, parent.Children); + var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(parent.Id, parent.RootId); + ConvertOrganizationDtoList(childOrganizations, parent.Children, parent.RootId); StateHasChanged(); } - private static void ConvertOrganizationDtoList(IEnumerable input, IList result) + private static void ConvertOrganizationDtoList(IEnumerable input, IList result, Guid? rootId) { result.Clear(); foreach (var organization in input) @@ -98,36 +97,20 @@ else { Id = organization.Id, Name = organization.Name, - ParentId = organization.ParentId, - IsLeaf = organization.IsLeaf, + RootId = rootId ?? organization.Id, Children = new List() }); } } - - private bool HasChildren(object org) - { - var organization = (ParentOrganization)org; - return !organization.IsLeaf; - } private object selectedItem; - private OrganizationDto newOrganization = new(); - - private void OnChange() - { - if (selectedItem is ParentOrganization selectedOrganization) - { - newOrganization.ParentId = selectedOrganization.Id; - } - } - private async Task OpenAddOrganizationDialog(OrganizationDto newOrganization, bool isRootOrganization) + private async Task OpenAddOrganizationDialog(ParentOrganization parentOrganization, bool isRootOrganization) { - await DialogService.OpenAsync($"Add new organization:", + await DialogService.OpenAsync("Add new organization:", new Dictionary() { - { "NewOrganization", newOrganization }, + { "ParentOrganization", parentOrganization }, { "IsRootOrganization", isRootOrganization } }, new DialogOptions() @@ -140,18 +123,18 @@ else { await OnInitializedAsync(); } - else if (selectedItem is ParentOrganization selectedOrganization) + else if (selectedItem is ParentOrganization selectedOrg) { - var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(selectedOrganization.Id); - ConvertOrganizationDtoList(childOrganizations, selectedOrganization.Children); + var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(selectedOrg.Id, selectedOrg.RootId); + ConvertOrganizationDtoList(childOrganizations, selectedOrg.Children, selectedOrg.RootId); StateHasChanged(); } } - private async Task OpenOrganizationDetailsDialog(ParentOrganization organization) + private async Task OpenOrganizationDetailsDialog(ParentOrganization parentOrganization) { - await DialogService.OpenAsync($"Details of the organization:", - new Dictionary() { { "OrganizationId", organization.Id } }, + await DialogService.OpenAsync("Details of the organization:", + new Dictionary() { { "ParentOrganization", parentOrganization } }, new DialogOptions() { Width = "700px", Height = "600px", Resizable = true, Draggable = true, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor index 9ca53f353..9f27f99c7 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor @@ -19,7 +19,13 @@

Loading...

} -@if (pageInitialized && organizerId != Guid.Empty) +@if (pageInitialized && !organizationsFound) +{ +

You have been granted the organizer rights, but have not been added to any organization yet!

+

Therefore, you cannot create any event.

+} + +@if (pageInitialized && organizationsFound && organizerId != Guid.Empty) { @@ -152,6 +158,7 @@ @code { private Guid organizerId; private bool pageInitialized = false; + private bool organizationsFound = false; private AddEventModel addEventModel = new() { @@ -201,8 +208,12 @@ organizerId = IdentityService.GetCurrentUserId(); organizations = await OrganizationsService.GetOrganizerOrganizationsAsync(organizerId); - addEventModel.OrganizerId = organizerId; - addEventModel.OrganizationId = organizations.First().Id; + if (organizations.Any()) + { + organizationsFound = true; + addEventModel.OrganizerId = organizerId; + addEventModel.OrganizationId = organizations.First().Id; + } } pageInitialized = true; From 56a5149bbbece9ad7dd9d0448c9768f436d20705 Mon Sep 17 00:00:00 2001 From: Amadeusz Nowak Date: Sat, 18 May 2024 16:08:04 +0200 Subject: [PATCH 02/11] (#57) provide option for admin to add organizers and remove them from organization --- .../Areas/Events/EventsService.cs | 10 +-- .../Areas/Events/IEventsService.cs | 6 +- .../{AddEventModel.cs => CreateEventModel.cs} | 3 +- .../Models/Organizations/OrganizationModel.cs | 13 +++ .../Models/Organizations/OrganizerModel.cs | 20 +++++ .../Admin/Dialogs/AddOrganizationDialog.razor | 3 +- .../Dialogs/OrganizationDetailsDialog.razor | 80 +++++++++++++++++-- .../Pages/Admin/ManageOrganizations.razor | 45 ++++++----- .../Pages/Events/EventCreate.razor | 60 +++++++------- 9 files changed, 173 insertions(+), 67 deletions(-) rename MiniSpace.Web/src/MiniSpace.Web/Models/Events/{AddEventModel.cs => CreateEventModel.cs} (90%) create mode 100644 MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizationModel.cs create mode 100644 MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizerModel.cs diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs index 28b671b5f..f62abda19 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs @@ -34,14 +34,14 @@ public Task>> GetStudentEventsAsync(Guid } public Task> AddEventAsync(Guid eventId, string name, Guid organizerId, Guid organizationId, - string startDate, string endDate, string buildingName, string street, string buildingNumber, - string apartmentNumber, string city, string zipCode, string description, int capacity, decimal fee, - string category, string publishDate) + Guid rootOrganizationId, string startDate, string endDate, string buildingName, string street, + string buildingNumber, string apartmentNumber, string city, string zipCode, string description, + int capacity, decimal fee, string category, string publishDate) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); return _httpClient.PostAsync("events", new {eventId, name, organizerId, organizationId, - startDate, endDate, buildingName, street, buildingNumber, apartmentNumber, city, zipCode, description, - capacity, fee, category, publishDate}); + rootOrganizationId, startDate, endDate, buildingName, street, buildingNumber, apartmentNumber, city, + zipCode, description, capacity, fee, category, publishDate}); } public Task> UpdateEventAsync(Guid eventId, string name, Guid organizerId, string startDate, string endDate, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs index 777401816..a40abae3b 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs @@ -14,9 +14,9 @@ public interface IEventsService Task>> GetStudentEventsAsync(Guid studentId, string engagementType, int page, int numberOfResults); Task> AddEventAsync(Guid eventId, string name, Guid organizerId, Guid organizationId, - string startDate, string endDate, string buildingName, string street, string buildingNumber, - string apartmentNumber, string city, string zipCode, string description, int capacity, decimal fee, - string category, string publishDate); + Guid rootOrganizationId, string startDate, string endDate, string buildingName, string street, + string buildingNumber, string apartmentNumber, string city, string zipCode, string description, + int capacity, decimal fee, string category, string publishDate); Task> UpdateEventAsync(Guid eventId, string name, Guid organizerId, string startDate, string endDate, string buildingName, string street, string buildingNumber, string apartmentNumber, string city, string zipCode, string description, int capacity, decimal fee, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/AddEventModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs similarity index 90% rename from MiniSpace.Web/src/MiniSpace.Web/Models/Events/AddEventModel.cs rename to MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs index 8e79c5b13..3212fb829 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/AddEventModel.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs @@ -2,12 +2,13 @@ namespace MiniSpace.Web.Models.Events { - public class AddEventModel + public class CreateEventModel { public Guid EventId { get; set; } public string Name { get; set; } public Guid OrganizerId { get; set; } public Guid OrganizationId { get; set; } + public Guid RootOrganizationId { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public string BuildingName { get; set; } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizationModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizationModel.cs new file mode 100644 index 000000000..624f6bf7d --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizationModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace MiniSpace.Web.Models.Organizations +{ + public class OrganizationModel + { + public Guid Id { get; set; } + public string Name { get; set; } + public Guid RootId { get; set; } + public List Children { get; set; } + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizerModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizerModel.cs new file mode 100644 index 000000000..52d263364 --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Organizations/OrganizerModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace MiniSpace.Web.Models.Organizations +{ + public class OrganizerModel + { + public Guid Id { get; set; } + public string Email { get; set; } + public string Name { get; set; } + public bool WasBelonging { get; set; } + + public OrganizerModel(Guid id, string email, string name) + { + Id = id; + Email = email; + Name = name; + } + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor index aa0741c85..c1e954dcd 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/AddOrganizationDialog.razor @@ -1,6 +1,7 @@ @page "/admin/organizations/add" @using Radzen @using MiniSpace.Web.Areas.Organizations +@using MiniSpace.Web.Models.Organizations @inject IOrganizationsService OrganizationsService @inject NavigationManager NavigationManager @inject Radzen.DialogService DialogService @@ -34,7 +35,7 @@ @code { [Parameter] - public ManageOrganizations.ParentOrganization ParentOrganization { get; set; } + public OrganizationModel ParentOrganization { get; set; } [Parameter] public bool IsRootOrganization { get; set; } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor index f2532389f..d24733334 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/Dialogs/OrganizationDetailsDialog.razor @@ -2,6 +2,7 @@ @using Radzen @using MiniSpace.Web.DTO @using MiniSpace.Web.Areas.Organizations +@using MiniSpace.Web.Models.Organizations @inject IOrganizationsService OrganizationsService @inject NavigationManager NavigationManager @inject Radzen.DialogService DialogService @@ -45,13 +46,26 @@
- + + + Organizers not belonging: + + + Organizers belonging: + + + + @@ -59,15 +73,67 @@ @code { [Parameter] - public ManageOrganizations.ParentOrganization ParentOrganization { get; set; } + public OrganizationModel Organization { get; set; } + [Parameter] + public IEnumerable Organizers { get; set; } + + private OrganizationDetailsDto OrganizationDetailsDto { get; set; } = new(); - public OrganizationDetailsDto OrganizationDetailsDto { get; set; } = new(); - private Guid selectedOrganizer; + private IEnumerable notBelongingOrganizers = []; + private IEnumerable belongingOrganizers = []; protected override async Task OnInitializedAsync() { - OrganizationDetailsDto = await OrganizationsService.GetOrganizationDetailsAsync(ParentOrganization.Id, - ParentOrganization.RootId); await base.OnInitializedAsync(); + OrganizationDetailsDto = await OrganizationsService.GetOrganizationDetailsAsync(Organization.Id, + Organization.RootId); + + HashSet belongingGuids = OrganizationDetailsDto.Organizers.ToHashSet(); + List notBelongingTmp = new(); + List belongingTmp = new(); + + foreach (var organizer in Organizers) + { + if (belongingGuids.Contains(organizer.Id)) + { + organizer.WasBelonging = true; + belongingTmp.Add(organizer); + } + else + { + organizer.WasBelonging = false; + notBelongingTmp.Add(organizer); + } + } + + notBelongingOrganizers = notBelongingTmp; + belongingOrganizers = belongingTmp; + } + + private async void HandleSubmitting() + { + if (belongingOrganizers != null) + { + foreach (var organizer in belongingOrganizers) + { + if (!organizer.WasBelonging) + { + await OrganizationsService.AddOrganizerToOrganization(Organization.RootId, Organization.Id, organizer.Id); + } + } + } + + if (notBelongingOrganizers != null) + { + foreach (var organizer in notBelongingOrganizers) + { + if (organizer.WasBelonging) + { + await OrganizationsService.RemoveOrganizerFromOrganization(Organization.RootId, Organization.Id, organizer.Id); + } + } + } + + DialogService.Close(true); } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor index 72ea336e3..4b01d5b9e 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor @@ -2,6 +2,7 @@ @using MiniSpace.Web.Areas.Students @using MiniSpace.Web.DTO @using MiniSpace.Web.Areas.Organizations +@using MiniSpace.Web.Models.Organizations @using MiniSpace.Web.Pages.Admin.Dialogs @using Radzen @using DialogOptions = Radzen.DialogOptions @@ -9,6 +10,7 @@ @inject DialogService DialogService @inject IIdentityService IdentityService @inject IOrganizationsService OrganizationsService +@inject IStudentsService StudentsService @inject NavigationManager NavigationManager

Manage organizations

@@ -24,15 +26,15 @@ else + Click="@(() => OpenAddOrganizationDialog(selectedItem as OrganizationModel, true))" /> + Click="@(() => OpenAddOrganizationDialog(selectedItem as OrganizationModel, false))" /> + Click="@(() => OpenOrganizationDetailsDialog(selectedItem as OrganizationModel, organizers))" /> @@ -56,17 +58,11 @@ else @code { private bool pageInitialized = false; - - public class ParentOrganization - { - public Guid Id { get; set; } - public string Name { get; set; } - public Guid RootId { get; set; } - public List Children { get; set; } - } private int totalRootOrganizations = 0; - private List rootOrganizations = new(); + private List rootOrganizations = new(); + + private IEnumerable organizers; protected override async Task OnInitializedAsync() { @@ -78,34 +74,39 @@ else } pageInitialized = true; + + var paginatedResponse = await StudentsService.GetStudentsAsync(); + organizers = paginatedResponse.Results + .Where(o => o.IsOrganizer) + .Select(s => new OrganizerModel(s.Id, s.Email, $"{s.FirstName} {s.LastName}")); } private async void OnExpand(TreeExpandEventArgs args) { - var parent = (ParentOrganization)args.Value; + var parent = (OrganizationModel)args.Value; var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(parent.Id, parent.RootId); ConvertOrganizationDtoList(childOrganizations, parent.Children, parent.RootId); StateHasChanged(); } - private static void ConvertOrganizationDtoList(IEnumerable input, IList result, Guid? rootId) + private static void ConvertOrganizationDtoList(IEnumerable input, IList result, Guid? rootId) { result.Clear(); foreach (var organization in input) { - result.Add(new ParentOrganization() + result.Add(new OrganizationModel() { Id = organization.Id, Name = organization.Name, RootId = rootId ?? organization.Id, - Children = new List() + Children = new List() }); } } private object selectedItem; - private async Task OpenAddOrganizationDialog(ParentOrganization parentOrganization, bool isRootOrganization) + private async Task OpenAddOrganizationDialog(OrganizationModel parentOrganization, bool isRootOrganization) { await DialogService.OpenAsync("Add new organization:", new Dictionary() @@ -123,7 +124,7 @@ else { await OnInitializedAsync(); } - else if (selectedItem is ParentOrganization selectedOrg) + else if (selectedItem is OrganizationModel selectedOrg) { var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(selectedOrg.Id, selectedOrg.RootId); ConvertOrganizationDtoList(childOrganizations, selectedOrg.Children, selectedOrg.RootId); @@ -131,10 +132,14 @@ else } } - private async Task OpenOrganizationDetailsDialog(ParentOrganization parentOrganization) + private async Task OpenOrganizationDetailsDialog(OrganizationModel Organization, IEnumerable organizers) { await DialogService.OpenAsync("Details of the organization:", - new Dictionary() { { "ParentOrganization", parentOrganization } }, + new Dictionary() + { + { "Organization", Organization }, + { "Organizers", organizers } + }, new DialogOptions() { Width = "700px", Height = "600px", Resizable = true, Draggable = true, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor index 9f27f99c7..2a2a6cb2d 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor @@ -31,48 +31,48 @@ Shade="Shade.Lighter"> @errorMessage - + - + - - + - + - + - + - @@ -80,30 +80,30 @@ - + - - + - + - + - + @@ -118,10 +118,10 @@ @if (publishInfo == 2) { - } @@ -135,7 +135,7 @@ - + Date: Sat, 18 May 2024 19:05:58 +0200 Subject: [PATCH 03/11] (#155) fix issue with rootId --- .../Dto/OrganizationDetailsDto.cs | 4 +++- .../Dto/OrganizationDto.cs | 4 +++- .../Mongo/Documents/Extensions.cs | 8 +++++--- .../Queries/Handlers/GetChildrenOrganizationsHandler.cs | 2 +- .../Queries/Handlers/GetOrganizationDetailsHandler.cs | 2 +- .../Mongo/Queries/Handlers/GetOrganizationHandler.cs | 2 +- .../Queries/Handlers/GetOrganizerOrganizationsHandler.cs | 6 +++--- .../Mongo/Queries/Handlers/GetRootOrganizationsHandler.cs | 2 +- .../Extensions.cs | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-) diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDetailsDto.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDetailsDto.cs index 2c7d353bd..509a1ea18 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDetailsDto.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDetailsDto.cs @@ -7,6 +7,7 @@ public class OrganizationDetailsDto { public Guid Id { get; set; } public string Name { get; set; } + public Guid RootId { get; set; } public IEnumerable Organizers { get; set; } public OrganizationDetailsDto() @@ -14,10 +15,11 @@ public OrganizationDetailsDto() } - public OrganizationDetailsDto(Organization organization) + public OrganizationDetailsDto(Organization organization, Guid rootId) { Id = organization.Id; Name = organization.Name; + RootId = rootId; Organizers = organization.Organizers.Select(o => o.Id); } } diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs index fc71ebfea..8c14653b6 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Application/Dto/OrganizationDto.cs @@ -6,16 +6,18 @@ public class OrganizationDto { public Guid Id { get; set; } public string Name { get; set; } + public Guid RootId { get; set; } public OrganizationDto() { } - public OrganizationDto (Organization organization) + public OrganizationDto (Organization organization, Guid rootId) { Id = organization.Id; Name = organization.Name; + RootId = rootId; } } } diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs index 343da89eb..05676fbd8 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/Extensions.cs @@ -17,18 +17,20 @@ public static OrganizationDocument AsDocument(this Organization entity) SubOrganizations = entity.SubOrganizations.Select(o => o.AsDocument()) }; - public static OrganizationDto AsDto(this OrganizationDocument document) + public static OrganizationDto AsDto(this OrganizationDocument document, Guid rootId) => new OrganizationDto() { Id = document.Id, - Name = document.Name + Name = document.Name, + RootId = rootId }; - public static OrganizationDetailsDto AsDetailsDto(this OrganizationDocument document) + public static OrganizationDetailsDto AsDetailsDto(this OrganizationDocument document, Guid rootId) => new OrganizationDetailsDto() { Id = document.Id, Name = document.Name, + RootId = rootId, Organizers = document.Organizers.Select(x => x.Id) }; diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetChildrenOrganizationsHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetChildrenOrganizationsHandler.cs index e8406e010..486ecff5e 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetChildrenOrganizationsHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetChildrenOrganizationsHandler.cs @@ -24,7 +24,7 @@ public async Task> HandleAsync(GetChildrenOrganizat var parent = root.AsEntity().GetSubOrganization(query.OrganizationId); return parent == null ? Enumerable.Empty() - : parent.SubOrganizations.Select(o => new OrganizationDto(o)); + : parent.SubOrganizations.Select(o => new OrganizationDto(o, root.Id)); } } } \ No newline at end of file diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationDetailsHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationDetailsHandler.cs index f420f0238..64ffcdb74 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationDetailsHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationDetailsHandler.cs @@ -20,7 +20,7 @@ public async Task HandleAsync(GetOrganizationDetails que { var root = await _repository.GetAsync(o => o.Id == query.RootId); var organization = root?.AsEntity().GetSubOrganization(query.OrganizationId); - return organization == null ? null : new OrganizationDetailsDto(organization); + return organization == null ? null : new OrganizationDetailsDto(organization, root.Id); } } } \ No newline at end of file diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationHandler.cs index c01bbd2e9..698b1db23 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizationHandler.cs @@ -19,7 +19,7 @@ public async Task HandleAsync(GetOrganization query, Cancellati { var root = await _repository.GetAsync(o => o.Id == query.RootId); var organization = root?.AsEntity().GetSubOrganization(query.OrganizationId); - return organization == null ? null : new OrganizationDto(organization); + return organization == null ? null : new OrganizationDto(organization, root.Id); } } } \ No newline at end of file diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizerOrganizationsHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizerOrganizationsHandler.cs index 16977a82c..78e29d923 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizerOrganizationsHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetOrganizerOrganizationsHandler.cs @@ -28,14 +28,14 @@ public async Task> HandleAsync(GetOrganizerOrganiza } var roots = (await _repository.FindAsync(o => true)).Select(o =>o.AsEntity()); - var organizerOrganizations = new List(); + var organizerOrganizations = new List(); foreach (var root in roots) { var organizations = Organization.FindOrganizations(query.OrganizerId, root); - organizerOrganizations.AddRange(organizations); + organizerOrganizations.AddRange(organizations.Select(o => new OrganizationDto(o, root.Id))); } - return organizerOrganizations.Select(o => new OrganizationDto(o)); + return organizerOrganizations; } } } \ No newline at end of file diff --git a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetRootOrganizationsHandler.cs b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetRootOrganizationsHandler.cs index 87f1ab43e..4376e5f64 100644 --- a/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetRootOrganizationsHandler.cs +++ b/MiniSpace.Services.Organizations/src/MiniSpace.Services.Organizations.Infrastructure/Mongo/Queries/Handlers/GetRootOrganizationsHandler.cs @@ -16,6 +16,6 @@ public GetRootOrganizationsHandler(IMongoRepository } public async Task> HandleAsync(GetRootOrganizations query, CancellationToken cancellationToken) - => (await _repository.FindAsync(o => true)).Select(o =>o.AsDto()); + => (await _repository.FindAsync(o => true)).Select(o =>o.AsDto(o.Id)); } } \ No newline at end of file diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs index 062c8c8cc..bd15140a4 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs @@ -70,7 +70,7 @@ public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder) .AddMetrics() .AddJaeger() .AddHandlersLogging() - .AddMongoRepository("students") + .AddMongoRepository("studentsUpdated") .AddWebApiSwaggerDocs() .AddCertificateAuthentication() .AddSecurity(); From c97805bcda938d613ff4f15de33491cf210e6324 Mon Sep 17 00:00:00 2001 From: Amadeusz Nowak Date: Sat, 18 May 2024 20:01:36 +0200 Subject: [PATCH 04/11] (#57) fix choosing an organization during creating new event --- .../Extensions.cs | 2 +- .../src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs | 1 + .../src/MiniSpace.Web/DTO/OrganizationDto.cs | 1 + .../MiniSpace.Web/Models/Events/CreateEventModel.cs | 4 ++-- .../Pages/Admin/ManageOrganizations.razor | 13 ++++++++----- .../MiniSpace.Web/Pages/Events/EventCreate.razor | 10 +++++----- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs index bd15140a4..062c8c8cc 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Infrastructure/Extensions.cs @@ -70,7 +70,7 @@ public static IConveyBuilder AddInfrastructure(this IConveyBuilder builder) .AddMetrics() .AddJaeger() .AddHandlersLogging() - .AddMongoRepository("studentsUpdated") + .AddMongoRepository("students") .AddWebApiSwaggerDocs() .AddCertificateAuthentication() .AddSecurity(); diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs index 5f9b27477..e8afa161b 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs @@ -7,6 +7,7 @@ public class OrganizationDetailsDto { public Guid Id { get; set; } public string Name { get; set; } + public Guid RootId { get; set; } public IEnumerable Organizers { get; set; } } } \ No newline at end of file diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs index 45c4f9c6f..8526582fa 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs @@ -6,5 +6,6 @@ public class OrganizationDto { public Guid Id { get; set; } public string Name { get; set; } + public Guid RootId { get; set; } } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs index 3212fb829..cf6129ab6 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs @@ -1,4 +1,5 @@ using System; +using MiniSpace.Web.DTO; namespace MiniSpace.Web.Models.Events { @@ -7,8 +8,7 @@ public class CreateEventModel public Guid EventId { get; set; } public string Name { get; set; } public Guid OrganizerId { get; set; } - public Guid OrganizationId { get; set; } - public Guid RootOrganizationId { get; set; } + public OrganizationDto Organization { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public string BuildingName { get; set; } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor index 4b01d5b9e..a6534db91 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor @@ -74,11 +74,14 @@ else } pageInitialized = true; - - var paginatedResponse = await StudentsService.GetStudentsAsync(); - organizers = paginatedResponse.Results - .Where(o => o.IsOrganizer) - .Select(s => new OrganizerModel(s.Id, s.Email, $"{s.FirstName} {s.LastName}")); + + if (IdentityService.IsAuthenticated && IdentityService.GetCurrentUserRole() == "admin") + { + var paginatedResponse = await StudentsService.GetStudentsAsync(); + organizers = paginatedResponse.Results + .Where(o => o.IsOrganizer) + .Select(s => new OrganizerModel(s.Id, s.Email, $"{s.FirstName} {s.LastName}")); + } } private async void OnExpand(TreeExpandEventArgs args) diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor index 2a2a6cb2d..bb1dec9ad 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventCreate.razor @@ -72,8 +72,8 @@ Text="Capacity should be between 1 and 1000" /> - + @@ -207,12 +207,12 @@ { organizerId = IdentityService.GetCurrentUserId(); organizations = await OrganizationsService.GetOrganizerOrganizationsAsync(organizerId); - + if (organizations.Any()) { organizationsFound = true; _createEventModel.OrganizerId = organizerId; - _createEventModel.OrganizationId = organizations.First().Id; + _createEventModel.Organization = organizations.First(); } } @@ -222,7 +222,7 @@ private async Task HandleCreateEvent() { var response = await EventsService.AddEventAsync(Guid.Empty, _createEventModel.Name, - _createEventModel.OrganizerId, _createEventModel.OrganizationId, _createEventModel.RootOrganizationId, + _createEventModel.OrganizerId, _createEventModel.Organization.Id, _createEventModel.Organization.RootId, _createEventModel.StartDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), _createEventModel.EndDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), _createEventModel.BuildingName, _createEventModel.Street, _createEventModel.BuildingNumber, From 6bbb470a17b21582ae50a9b9575563ccf6906a43 Mon Sep 17 00:00:00 2001 From: Amadeusz Nowak Date: Sat, 18 May 2024 21:48:45 +0200 Subject: [PATCH 05/11] (#57) add option of selection organization to search events in subtree --- .../Areas/Events/EventsService.cs | 9 +-- .../Areas/Events/IEventsService.cs | 4 +- .../MiniSpace.Web/Data/Events/SearchEvents.cs | 9 ++- .../Models/Events/SearchEventsModel.cs | 2 + .../Pages/Admin/ManageOrganizations.razor | 5 +- .../Events/Dialogs/EventsOrganizeDialog.razor | 4 +- .../Events/Dialogs/EventsSearchDialog.razor | 68 ++++++++++++++++++- .../Pages/Events/EventsOrganize.razor | 2 +- .../Pages/Events/EventsSearch.razor | 16 +++-- 9 files changed, 95 insertions(+), 24 deletions(-) diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs index f62abda19..adfd03736 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs @@ -90,12 +90,13 @@ public Task RateEventAsync(Guid eventId, int rating, Guid studentId) return _httpClient.PostAsync($"events/{eventId}/rate", new {eventId, rating, studentId}); } - public Task>>> SearchEventsAsync(string name, - string organizer, string category, string state, IEnumerable friends, string friendsEngagementType, - string dateFrom, string dateTo, PageableDto pageable) + public Task>>> SearchEventsAsync(string name, string organizer, + Guid organizationId, Guid rootOrganizationId, string category, string state, IEnumerable friends, + string friendsEngagementType, string dateFrom, string dateTo, PageableDto pageable) { return _httpClient.PostAsync>>("events/search", - new (name, organizer, category, state, friends, friendsEngagementType, dateFrom, dateTo, pageable)); + new (name, organizer, organizationId, rootOrganizationId, category, state, friends, + friendsEngagementType, dateFrom, dateTo, pageable)); } public Task>>> SearchOrganizerEventsAsync(Guid organizerId, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs index a40abae3b..000bfb59f 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs @@ -28,8 +28,8 @@ Task> UpdateEventAsync(Guid eventId, string name, Guid orga Task CancelInterestInEventAsync(Guid eventId, Guid studentId); Task RateEventAsync(Guid eventId, int rating, Guid studentId); Task>>> SearchEventsAsync(string name, string organizer, - string category, string state, IEnumerable friends, string friendsEngagementType, string dateFrom, - string dateTo, PageableDto pageable); + Guid organizationId, Guid rootOrganizationId, string category, string state, IEnumerable friends, + string friendsEngagementType, string dateFrom, string dateTo, PageableDto pageable); Task>>> SearchOrganizerEventsAsync(Guid organizerId, string name, string state, string dateFrom, string dateTo, PageableDto pageable); Task GetEventParticipants(Guid eventId); diff --git a/MiniSpace.Web/src/MiniSpace.Web/Data/Events/SearchEvents.cs b/MiniSpace.Web/src/MiniSpace.Web/Data/Events/SearchEvents.cs index ad9d1916e..4cc8511bc 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Data/Events/SearchEvents.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Data/Events/SearchEvents.cs @@ -8,6 +8,8 @@ public class SearchEvents { public string Name { get; set; } public string Organizer { get; set; } + public Guid OrganizationId { get; set; } + public Guid RootOrganizationId { get; set; } public string Category { get; set; } public string State { get; set; } public IEnumerable Friends { get; set; } @@ -16,11 +18,14 @@ public class SearchEvents public string DateTo { get; set; } public PageableDto Pageable { get; set; } - public SearchEvents(string name, string organizer, string category, string state, IEnumerable friends, - string friendsEngagementType, string dateFrom, string dateTo, PageableDto pageable) + public SearchEvents(string name, string organizer, Guid organizationId, Guid rootOrganizationId, + string category, string state, IEnumerable friends, string friendsEngagementType, + string dateFrom, string dateTo, PageableDto pageable) { Name = name; Organizer = organizer; + OrganizationId = organizationId; + RootOrganizationId = rootOrganizationId; Category = category; State = state; Friends = friends; diff --git a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/SearchEventsModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/SearchEventsModel.cs index a4e187217..727644eae 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/SearchEventsModel.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/SearchEventsModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using MiniSpace.Web.DTO.Wrappers; +using MiniSpace.Web.Models.Organizations; namespace MiniSpace.Web.Models.Events { @@ -8,6 +9,7 @@ public class SearchEventsModel { public string Name { get; set; } public string Organizer { get; set; } + public OrganizationModel Organization { get; set; } public string Category { get; set; } public string State { get; set; } public IEnumerable Friends { get; set; } diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor index a6534db91..e9fd1ecf3 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Admin/ManageOrganizations.razor @@ -61,7 +61,8 @@ else private int totalRootOrganizations = 0; private List rootOrganizations = new(); - + private object selectedItem; + private IEnumerable organizers; protected override async Task OnInitializedAsync() @@ -107,8 +108,6 @@ else } } - private object selectedItem; - private async Task OpenAddOrganizationDialog(OrganizationModel parentOrganization, bool isRootOrganization) { await DialogService.OpenAsync("Add new organization:", diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Dialogs/EventsOrganizeDialog.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Dialogs/EventsOrganizeDialog.razor index 9fa8fd28a..00b19b144 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Dialogs/EventsOrganizeDialog.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Dialogs/EventsOrganizeDialog.razor @@ -44,10 +44,10 @@ ShowHeader="true" ButtonGap="12px" ButtonJustifyContent="JustifyContent.Center" ButtonStyle="@ButtonStyle.Secondary" ButtonSize="@ButtonSize.Medium" ButtonVariant="Variant.Outlined"> - Not selected parameters: +

Not selected parameters:

- Sorting parameters (order important): +

Sorting parameters (order important):