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.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs index 28b671b5f..adfd03736 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, @@ -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 777401816..000bfb59f 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, @@ -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/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/Areas/Reactions/IReactionsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Reactions/IReactionsService.cs new file mode 100644 index 000000000..88adde6be --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Reactions/IReactionsService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MiniSpace.Web.DTO; +using MiniSpace.Web.DTO.Enums; +using MiniSpace.Web.HttpClients; + +namespace MiniSpace.Web.Areas.Reactions +{ + public interface IReactionsService + { + Task> GetReactions(Guid contentId, ReactionContentType contentType); + Task GetReactionsSummary(Guid contentId, ReactionContentType contentType); + Task> CreateReaction(Guid reactionId, Guid studentId, string reactionType, + Guid contentId, string contentType); + Task DeleteReaction(Guid reactionId); + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/Areas/Reactions/ReactionsService.cs b/MiniSpace.Web/src/MiniSpace.Web/Areas/Reactions/ReactionsService.cs new file mode 100644 index 000000000..4aae4aadd --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/Areas/Reactions/ReactionsService.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using MiniSpace.Web.Areas.Identity; +using MiniSpace.Web.DTO; +using MiniSpace.Web.DTO.Enums; +using MiniSpace.Web.HttpClients; + +namespace MiniSpace.Web.Areas.Reactions +{ + public class ReactionsService : IReactionsService + { + private readonly IHttpClient _httpClient; + private readonly IIdentityService _identityService; + + public ReactionsService(IHttpClient httpClient, IIdentityService identityService) + { + _httpClient = httpClient; + _identityService = identityService; + } + + public Task> GetReactions(Guid contentId, ReactionContentType contentType) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.GetAsync>($"reactions?contentId={contentId}&contentType={contentType}"); + } + + public Task GetReactionsSummary(Guid contentId, ReactionContentType contentType) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.GetAsync($"reactions/summary?contentId={contentId}&contentType={contentType}"); + } + + public Task> CreateReaction(Guid reactionId, Guid studentId, string reactionType, + Guid contentId, string contentType) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.PostAsync("reactions", + new { reactionId, studentId, reactionType, contentId, contentType }); + } + + public Task DeleteReaction(Guid reactionId) + { + _httpClient.SetAccessToken(_identityService.JwtDto.AccessToken); + return _httpClient.DeleteAsync($"reactions/{reactionId}"); + } + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionContentType.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionContentType.cs new file mode 100644 index 000000000..583f4166d --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionContentType.cs @@ -0,0 +1,8 @@ +namespace MiniSpace.Web.DTO.Enums +{ + public enum ReactionContentType + { + Event, + Post + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionType.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionType.cs new file mode 100644 index 000000000..dcc9637de --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/Enums/ReactionType.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace MiniSpace.Web.DTO.Enums +{ + public enum ReactionType + { + LoveIt, + LikeIt, + Wow, + ItWasOkay, + HateIt + } + + public static class ReactionTypeExtensions + { + public static string GetReactionText(ReactionType? reactionType) + { + return reactionType switch + { + ReactionType.LoveIt => "Love it!", + ReactionType.LikeIt => "Like it.", + ReactionType.Wow => "Wow!", + ReactionType.ItWasOkay => "It was okay.", + ReactionType.HateIt => "Hate it!", + _ => "No reactions!" + }; + } + + public static List> GenerateReactionPairs() + => [ + new KeyValuePair("", null), + new KeyValuePair(GetReactionText(ReactionType.LoveIt), ReactionType.LoveIt), + new KeyValuePair(GetReactionText(ReactionType.LikeIt), ReactionType.LikeIt), + new KeyValuePair(GetReactionText(ReactionType.Wow), ReactionType.Wow), + new KeyValuePair(GetReactionText(ReactionType.ItWasOkay), ReactionType.ItWasOkay), + new KeyValuePair(GetReactionText(ReactionType.HateIt), ReactionType.HateIt) + ]; + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs index dfaa9bd93..e8afa161b 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDetailsDto.cs @@ -7,8 +7,7 @@ public class OrganizationDetailsDto { 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 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..8526582fa 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/OrganizationDto.cs @@ -6,7 +6,6 @@ public class OrganizationDto { 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; } } } diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionDto.cs new file mode 100644 index 000000000..910681383 --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionDto.cs @@ -0,0 +1,15 @@ +using System; +using MiniSpace.Web.DTO.Enums; + +namespace MiniSpace.Web.DTO +{ + public class ReactionDto + { + public Guid Id { get; set; } + public Guid StudentId { get; set; } + public string StudentFullName { get; set; } + public Guid ContentId { get; set; } + public ReactionContentType ContentType { get; set; } + public ReactionType Type { get; set; } + } +} diff --git a/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionsSummaryDto.cs b/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionsSummaryDto.cs new file mode 100644 index 000000000..6e3cfbef3 --- /dev/null +++ b/MiniSpace.Web/src/MiniSpace.Web/DTO/ReactionsSummaryDto.cs @@ -0,0 +1,13 @@ +using System; +using MiniSpace.Web.DTO.Enums; + +namespace MiniSpace.Web.DTO +{ + public class ReactionsSummaryDto + { + public int NumberOfReactions { get; set; } + public ReactionType? DominantReaction { get; set; } + public Guid? AuthUserReactionId { get; set; } + public ReactionType? AuthUserReactionType { get; set; } + } +} 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/AddEventModel.cs b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs similarity index 87% rename from MiniSpace.Web/src/MiniSpace.Web/Models/Events/AddEventModel.cs rename to MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs index 8e79c5b13..cf6129ab6 100644 --- a/MiniSpace.Web/src/MiniSpace.Web/Models/Events/AddEventModel.cs +++ b/MiniSpace.Web/src/MiniSpace.Web/Models/Events/CreateEventModel.cs @@ -1,13 +1,14 @@ using System; +using MiniSpace.Web.DTO; 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 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/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/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 cb5c3adb4..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,7 +1,7 @@ @page "/admin/organizations/add" @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 @@ -12,7 +12,7 @@ - + @@ -35,10 +35,12 @@ @code { [Parameter] - public OrganizationDto NewOrganization { get; set; } + public OrganizationModel ParentOrganization { get; set; } [Parameter] public bool IsRootOrganization { get; set; } + private string newOrganizationName { get; set; } + protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -46,8 +48,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..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,14 +73,67 @@ @code { [Parameter] - public Guid OrganizationId { 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(OrganizationId); 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 866304685..e9fd1ecf3 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,26 +26,26 @@ else + Click="@(() => OpenAddOrganizationDialog(selectedItem as OrganizationModel, true))" /> + Click="@(() => OpenAddOrganizationDialog(selectedItem as OrganizationModel, false))" /> + Click="@(() => OpenOrganizationDetailsDialog(selectedItem as OrganizationModel, organizers))" /> - + @if (totalRootOrganizations == 0) {

There are not any organizations created.

} - + @@ -56,78 +58,62 @@ else @code { private bool pageInitialized = false; - - public class ParentOrganization - { - public Guid Id { get; set; } - public string Name { get; set; } - public Guid ParentId { get; set; } - public bool IsLeaf { get; set; } - public List Children { get; set; } - } private int totalRootOrganizations = 0; - private List rootOrganizations = new(); + private List rootOrganizations = new(); + private object selectedItem; + + private IEnumerable organizers; protected override async Task OnInitializedAsync() { if (IdentityService.IsAuthenticated && IdentityService.GetCurrentUserRole() == "admin") { var tmpOrganizations = await OrganizationsService.GetRootOrganizationsAsync(); - ConvertOrganizationDtoList(tmpOrganizations, rootOrganizations); + ConvertOrganizationDtoList(tmpOrganizations, rootOrganizations, null); totalRootOrganizations = rootOrganizations.Count; } pageInitialized = true; + + 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) { - var parent = (ParentOrganization)args.Value; - var childOrganizations = await OrganizationsService.GetChildrenOrganizationsAsync(parent.Id); - ConvertOrganizationDtoList(childOrganizations, parent.Children); + 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) + 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, - ParentId = organization.ParentId, - IsLeaf = organization.IsLeaf, - Children = new List() + 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(OrganizationModel 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 +126,22 @@ else { await OnInitializedAsync(); } - else if (selectedItem is ParentOrganization selectedOrganization) + else if (selectedItem is OrganizationModel 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(OrganizationModel Organization, IEnumerable organizers) { - await DialogService.OpenAsync($"Details of the organization:", - new Dictionary() { { "OrganizationId", organization.Id } }, + await DialogService.OpenAsync("Details of the organization:", + 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/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):