diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/CreateEvent.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/CreateEvent.cs index bcb0ab00a..13fc9bc4b 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/CreateEvent.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/CreateEvent.cs @@ -12,6 +12,7 @@ public class CreateEvent : ICommand public string Name { get; } public Guid OrganizerId { get; } public Guid OrganizationId { get; } + public Guid RootOrganizationId { get; } public string StartDate { get; } public string EndDate { get; } public string BuildingName { get; } @@ -27,15 +28,16 @@ public class CreateEvent : ICommand public string Category { get; } public string PublishDate { get; } - public CreateEvent(Guid eventId, string name, Guid organizerId, Guid organizationId, string startDate, - string endDate, string buildingName, string street, string buildingNumber, string apartmentNumber, - string city, string zipCode, IEnumerable mediaFiles, string description, int capacity, decimal fee, - string category, string publishDate) + public CreateEvent(Guid eventId, string name, Guid organizerId, Guid organizationId, Guid rootOrganizationId, + string startDate, string endDate, string buildingName, string street, string buildingNumber, + string apartmentNumber, string city, string zipCode, IEnumerable mediaFiles, string description, + int capacity, decimal fee, string category, string publishDate) { EventId = eventId; Name = name; OrganizerId = organizerId; OrganizationId = organizationId; + RootOrganizationId = rootOrganizationId; StartDate = startDate; EndDate = endDate; BuildingName = buildingName; diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/Handlers/CreateEventHandler.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/Handlers/CreateEventHandler.cs index 13f82c327..1c7e67580 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/Handlers/CreateEventHandler.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/Handlers/CreateEventHandler.cs @@ -70,7 +70,7 @@ public async Task HandleAsync(CreateEvent command, CancellationToken cancellatio state = State.ToBePublished; } - var organization = await _organizationsServiceClient.GetAsync(command.OrganizationId); + var organization = await _organizationsServiceClient.GetAsync(command.OrganizationId, command.RootOrganizationId); if (organization == null) { throw new OrganizationNotFoundException(command.OrganizationId); @@ -81,8 +81,7 @@ public async Task HandleAsync(CreateEvent command, CancellationToken cancellatio throw new OrganizerDoesNotBelongToOrganizationException(command.OrganizerId, command.OrganizationId); } - var organizer = new Organizer(command.OrganizerId, identity.Name, identity.Email, - command.OrganizerId, organization.Name); + var organizer = new Organizer(command.OrganizerId, identity.Name, identity.Email, command.OrganizationId, organization.Name); var @event = Event.Create(command.EventId, command.Name, command.Description, startDate, endDate, address, command.MediaFiles, command.Capacity, command.Fee, category, state, publishDate, organizer, now); diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/SearchEvents.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/SearchEvents.cs index 96f8ea8fa..6683882bd 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/SearchEvents.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Commands/SearchEvents.cs @@ -9,6 +9,8 @@ public class SearchEvents : ICommand { 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; } diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Services/Clients/IOrganizationsServiceClient.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Services/Clients/IOrganizationsServiceClient.cs index 49d592182..ca0e95aa5 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Services/Clients/IOrganizationsServiceClient.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Application/Services/Clients/IOrganizationsServiceClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using MiniSpace.Services.Events.Application.DTO; @@ -6,6 +7,7 @@ namespace MiniSpace.Services.Events.Application.Services.Clients { public interface IOrganizationsServiceClient { - Task GetAsync(Guid id); + Task GetAsync(Guid organizationId, Guid rootId); + Task> GetAllChildrenOrganizations(Guid organizationId, Guid rootId); } } \ No newline at end of file diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Core/Repositories/IEventRepository.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Core/Repositories/IEventRepository.cs index 915ab0261..d172c4481 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Core/Repositories/IEventRepository.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Core/Repositories/IEventRepository.cs @@ -16,8 +16,8 @@ public interface IEventRepository Task ExistsAsync(Guid id); Task<(IEnumerable events, int pageNumber,int pageSize, int totalPages, int totalElements)> BrowseEventsAsync( int pageNumber, int pageSize, string name, string organizer, DateTime dateFrom, DateTime dateTo, - Category? category, State? state, IEnumerable friends, EventEngagementType? friendsEngagementType, - IEnumerable sortBy, string direction); + Category? category, State? state, IEnumerable organizations, IEnumerable friends, + EventEngagementType? friendsEngagementType, IEnumerable sortBy, string direction); Task<(IEnumerable events, int pageNumber,int pageSize, int totalPages, int totalElements)> BrowseOrganizerEventsAsync( int pageNumber, int pageSize, string name, Guid organizerId, DateTime dateFrom, DateTime dateTo, IEnumerable sortBy, string direction, State? state); diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/EventMongoRepository.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/EventMongoRepository.cs index c508829ee..a6b084d3c 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/EventMongoRepository.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/EventMongoRepository.cs @@ -53,14 +53,15 @@ public async Task> GetAllAsync() public async Task<(IEnumerable events, int pageNumber,int pageSize, int totalPages, int totalElements)> BrowseEventsAsync( int pageNumber, int pageSize, string name, string organizer, DateTime dateFrom, DateTime dateTo, - Category? category, State? state, IEnumerable friends, EventEngagementType? friendsEngagementType, - IEnumerable sortBy, string direction) + Category? category, State? state, IEnumerable organizations, IEnumerable friends, + EventEngagementType? friendsEngagementType, IEnumerable sortBy, string direction) { var filterDefinition = Extensions.ToFilterDefinition(name, dateFrom, dateTo) .AddOrganizerNameFilter(organizer) .AddCategoryFilter(category) .AddRestrictedStateFilter(state) - .AddFriendsFilter(friends, friendsEngagementType); + .AddFriendsFilter(friends, friendsEngagementType) + .AddOrganizationsIdFilter(organizations); var sortDefinition = Extensions.ToSortDefinition(sortBy, direction); var pagedEvents = await BrowseAsync(filterDefinition, sortDefinition, pageNumber, pageSize); diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/Extensions.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/Extensions.cs index 1bb098ac5..8324e2886 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/Extensions.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Mongo/Repositories/Extensions.cs @@ -163,6 +163,18 @@ public static FilterDefinition AddFriendsFilter (this FilterDefin return filterDefinition; } + + public static FilterDefinition AddOrganizationsIdFilter(this FilterDefinition filterDefinition, + IEnumerable organizationsEnumerable) + { + var organizations = organizationsEnumerable.ToList(); + if (organizations.Count > 0) + { + filterDefinition &= FilterDefinitionBuilder.In(x => x.Organizer.OrganizationId, organizations); + } + + return filterDefinition; + } public static FilterDefinition AddEventIdFilter(this FilterDefinition filterDefinition, IEnumerable eventIds) diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/Clients/OrganizationsServiceClient.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/Clients/OrganizationsServiceClient.cs index 60d490d8f..e28ce9688 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/Clients/OrganizationsServiceClient.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/Clients/OrganizationsServiceClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Convey.HTTP; using MiniSpace.Services.Events.Application.DTO; @@ -17,8 +18,11 @@ public OrganizationsServiceClient(IHttpClient httpClient, HttpClientOptions opti _url = options.Services["organizations"]; } - public Task GetAsync(Guid id) - => _httpClient.GetAsync($"{_url}/organizations/{id}/details"); + public Task GetAsync(Guid organizationId, Guid rootId) + => _httpClient.GetAsync($"{_url}/organizations/{organizationId}/details?rootId={rootId}"); + + public Task> GetAllChildrenOrganizations(Guid organizationId, Guid rootId) + => _httpClient.GetAsync>($"{_url}/organizations/{organizationId}/children/all?rootId={rootId}"); } } \ No newline at end of file diff --git a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/EventService.cs b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/EventService.cs index 05aff43b4..8bf6ffa56 100644 --- a/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/EventService.cs +++ b/MiniSpace.Services.Events/src/MiniSpace.Services.Events.Infrastructure/Services/EventService.cs @@ -7,6 +7,7 @@ using MiniSpace.Services.Events.Application.DTO; using MiniSpace.Services.Events.Application.Exceptions; using MiniSpace.Services.Events.Application.Services; +using MiniSpace.Services.Events.Application.Services.Clients; using MiniSpace.Services.Events.Application.Wrappers; using MiniSpace.Services.Events.Core.Entities; using MiniSpace.Services.Events.Core.Repositories; @@ -17,12 +18,15 @@ public class EventService : IEventService { private readonly IEventRepository _eventRepository; private readonly IEventValidator _eventValidator; + private readonly IOrganizationsServiceClient _organizationsServiceClient; private readonly IAppContext _appContext; - public EventService(IEventRepository eventRepository, IEventValidator eventValidator, IAppContext appContext) + public EventService(IEventRepository eventRepository, IEventValidator eventValidator, + IOrganizationsServiceClient organizationsServiceClient, IAppContext appContext) { _eventRepository = eventRepository; _eventValidator = eventValidator; + _organizationsServiceClient = organizationsServiceClient; _appContext = appContext; } @@ -33,6 +37,7 @@ public async Task>> BrowseEventsAsync(Search Category? category = null; State? state = null; EventEngagementType? friendsEngagementType = null; + IEnumerable organizations = new List(); if(command.DateFrom != string.Empty) { dateFrom =_eventValidator.ParseDate(command.DateFrom, "DateFrom"); @@ -54,11 +59,16 @@ public async Task>> BrowseEventsAsync(Search { friendsEngagementType = _eventValidator.ParseEngagementType(command.FriendsEngagementType); } + if (command.OrganizationId != Guid.Empty && command.RootOrganizationId != Guid.Empty) + { + organizations = await _organizationsServiceClient + .GetAllChildrenOrganizations(command.OrganizationId, command.RootOrganizationId) ?? new List(); + } (int pageNumber, int pageSize) = _eventValidator.PageFilter(command.Pageable.Page, command.Pageable.Size); var result = await _eventRepository.BrowseEventsAsync( - pageNumber, pageSize, command.Name, command.Organizer, dateFrom, dateTo, category, state, command.Friends, - friendsEngagementType, command.Pageable.Sort.SortBy, command.Pageable.Sort.Direction); + pageNumber, pageSize, command.Name, command.Organizer, dateFrom, dateTo, category, state, organizations, + command.Friends, friendsEngagementType, command.Pageable.Sort.SortBy, command.Pageable.Sort.Direction); var identity = _appContext.Identity; var pagedEvents = new PagedResponse>(result.events.Select(e => new EventDto(e, identity.Id)),