From fb640ea2be0e757222c5e03ee804292b0f33d766 Mon Sep 17 00:00:00 2001 From: Amadeusz Nowak Date: Fri, 17 May 2024 02:00:16 +0200 Subject: [PATCH] (#57) update follow events page to handle GetStudentEvents update --- .../Areas/Events/EventsService.cs | 5 +- .../Areas/Events/IEventsService.cs | 3 +- .../MiniSpace.Web/Pages/Events/Events.razor | 96 --------- .../Pages/Events/EventsFollow.razor | 192 ++++++++++++++++++ .../Pages/Events/EventsSearch.razor | 2 - .../src/MiniSpace.Web/Shared/MainLayout.razor | 2 +- 6 files changed, 198 insertions(+), 102 deletions(-) delete mode 100644 MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Events.razor create mode 100644 MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsFollow.razor diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs index ff7b5433b..28b671b5f 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs @@ -25,11 +25,12 @@ public Task GetEventAsync(Guid eventId) return _httpClient.GetAsync($"events/{eventId}"); } - public Task>> GetStudentEventsAsync(Guid studentId, int numberOfResults) + public Task>> GetStudentEventsAsync(Guid studentId, + string engagementType, int page, int numberOfResults) { _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); return _httpClient.GetAsync>>( - $"events/student/{studentId}?numberOfResults={numberOfResults}"); + $"events/student/{studentId}?engagementType={engagementType}&page={page}&numberOfResults={numberOfResults}"); } public Task> AddEventAsync(Guid eventId, string name, Guid organizerId, Guid organizationId, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs index cb99681c2..777401816 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs @@ -11,7 +11,8 @@ namespace MiniSpace.Web.Areas.Events public interface IEventsService { Task GetEventAsync(Guid eventId); - Task>> GetStudentEventsAsync(Guid studentId, int numberOfResults); + 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, diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Events.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Events.razor deleted file mode 100644 index 92b594267..000000000 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/Events.razor +++ /dev/null @@ -1,96 +0,0 @@ -@page "/events" -@using MiniSpace.Web.Areas.Students -@using MiniSpace.Web.DTO -@using MiniSpace.Web.Areas.Events -@using MiniSpace.Web.Components -@using MiniSpace.Web.Pages.Events.Dialogs -@using Radzen -@using DialogOptions = Radzen.DialogOptions -@using DialogService = Radzen.DialogService -@inject DialogService DialogService -@inject IIdentityService IdentityService -@inject IEventsService EventsService -@inject NavigationManager NavigationManager - -

Follow events

- -@if (!pageInitialized) -{ -

Loading...

-} - -@if (pageInitialized && studentId != Guid.Empty) -{ - - - - - @if (totalSignedUpElements == 0) - { -

You haven't been signed up for any event yet.

- } - - - -
- - - @if (totalInterestedElements == 0) - { -

You haven't been interested in any event yet.

- } - - - -
-
-
-
-} - -@code { - private const string dateFormat = "dd/MM/yyyy HH:mm"; - - private Guid studentId; - private bool pageInitialized = false; - - private int numberOfResults = 10; - - int totalSignedUpElements = 0; - IEnumerable signedUpEvents; - - int totalInterestedElements = 0; - IEnumerable interestedEvents; - - protected override async Task OnInitializedAsync() - { - if (IdentityService.IsAuthenticated) - { - studentId = IdentityService.GetCurrentUserId(); - - var tmp = await EventsService.GetStudentEventsAsync(studentId, numberOfResults); - if (tmp != null) - { - signedUpEvents = tmp.Content.Where(ev => ev.IsSignedUp); - totalSignedUpElements = signedUpEvents.Count(); - - interestedEvents = tmp.Content.Where(ev => ev.IsInterested); - totalInterestedElements = interestedEvents.Count(); - } - else - { - signedUpEvents = new List(); - totalSignedUpElements = 0; - - interestedEvents = new List(); - totalInterestedElements = 0; - } - } - - pageInitialized = true; - } -} diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsFollow.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsFollow.razor new file mode 100644 index 000000000..05de994b0 --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsFollow.razor @@ -0,0 +1,192 @@ +@page "/events/follow" +@using MiniSpace.Web.Areas.Students +@using MiniSpace.Web.DTO +@using MiniSpace.Web.Areas.Events +@using MiniSpace.Web.Components +@using MiniSpace.Web.Pages.Events.Dialogs +@using MudBlazor +@using Radzen +@using DialogOptions = Radzen.DialogOptions +@using DialogService = Radzen.DialogService +@using Orientation = Radzen.Orientation +@inject DialogService DialogService +@inject IIdentityService IdentityService +@inject IEventsService EventsService +@inject NavigationManager NavigationManager + +

Follow events

+ +@if (!pageInitialized) +{ +

Loading...

+} + +@if (pageInitialized && studentId != Guid.Empty) +{ + + + + + @if (signedUpTotalElements == 0) + { +

You haven't been signed up for any event yet.

+ } + else + { + + + + + + + + + + + + } +
+ + + @if (interestedInTotalElements == 0) + { +

You haven't been interested in any event yet.

+ } + else + { + + + + + + + + + + + + } +
+
+
+
+} + +@code { + private Guid studentId; + private bool pageInitialized = false; + + int signedUpPageNumber = 1; + int signedUpPageSize = 5; + int signedUpTotalPages = 0; + int signedUpTotalElements = 0; + IEnumerable signedUpEvents; + + int interestedInPageNumber = 1; + int interestedInPageSize = 5; + int interestedInTotalPages = 0; + int interestedInTotalElements = 0; + IEnumerable interestedInEvents; + + protected override async Task OnInitializedAsync() + { + if (IdentityService.IsAuthenticated) + { + studentId = IdentityService.GetCurrentUserId(); + + var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp", + signedUpPageNumber, signedUpPageSize); + if (tmp != null) + { + signedUpTotalPages = tmp.TotalPages; + signedUpTotalElements = tmp.TotalElements; + signedUpEvents = tmp.Content; + } + else + { + signedUpTotalPages = 0; + signedUpTotalElements = 0; + signedUpEvents = new List(); + } + } + + pageInitialized = true; + } + + private async void OnChange(int index) + { + if (!IdentityService.IsAuthenticated) + { + return; + } + + switch (index) + { + case 0: + var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp", + signedUpPageNumber, signedUpPageSize); + if (tmp != null) + { + signedUpTotalPages = tmp.TotalPages; + signedUpTotalElements = tmp.TotalElements; + signedUpEvents = tmp.Content; + } + else + { + signedUpTotalPages = 0; + signedUpTotalElements = 0; + signedUpEvents = new List(); + } + break; + case 1: + tmp = await EventsService.GetStudentEventsAsync(studentId, "InterestedIn", + interestedInPageNumber, interestedInPageSize); + if (tmp != null) + { + interestedInTotalPages = tmp.TotalPages; + interestedInTotalElements = tmp.TotalElements; + interestedInEvents = tmp.Content; + } + else + { + interestedInTotalPages = 0; + interestedInTotalElements = 0; + interestedInEvents = new List(); + } + break; + } + StateHasChanged(); + } + + private async void SignedUpSelectedPageChanged(int pageNumber) + { + signedUpPageNumber = pageNumber; + + var tmp = await EventsService.GetStudentEventsAsync(studentId, "SignedUp", + signedUpPageNumber, signedUpPageSize); + signedUpEvents = tmp.Content; + StateHasChanged(); + } + + private async void InterestedInSelectedPageChanged(int pageNumber) + { + interestedInPageNumber = pageNumber; + + var tmp = await EventsService.GetStudentEventsAsync(studentId, "InterestedIn", + interestedInPageNumber, interestedInPageSize); + interestedInEvents = tmp.Content; + StateHasChanged(); + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsSearch.razor b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsSearch.razor index fdf011728..ec7f167d4 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsSearch.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Pages/Events/EventsSearch.razor @@ -58,8 +58,6 @@ } @code { - private const string dateFormat = "dd/MM/yyyy HH:mm"; - private SearchEventsModel searchEventsModel = new() { Name = "", diff --git a/MiniSpace.Web/src/MiniSpace.Web/Shared/MainLayout.razor b/MiniSpace.Web/src/MiniSpace.Web/Shared/MainLayout.razor index 2dbc18f34..6dfbbb5f6 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Shared/MainLayout.razor +++ b/MiniSpace.Web/src/MiniSpace.Web/Shared/MainLayout.razor @@ -79,7 +79,7 @@ + Click="@(() => NavigationManager.NavigateTo("events/follow"))"/> @if (IdentityService.GetCurrentUserRole() == "organizer")