Skip to content

Commit

Permalink
(#30) resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
eggwhat committed May 17, 2024
2 parents cf883bc + 42862e6 commit a7cd536
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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<Guid> 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<Guid> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid> Friends { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MiniSpace.Services.Events.Application.DTO;

namespace MiniSpace.Services.Events.Application.Services.Clients
{
public interface IOrganizationsServiceClient
{
Task<OrganizationDto> GetAsync(Guid id);
Task<OrganizationDto> GetAsync(Guid organizationId, Guid rootId);
Task<IEnumerable<Guid>> GetAllChildrenOrganizations(Guid organizationId, Guid rootId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public interface IEventRepository
Task<bool> ExistsAsync(Guid id);
Task<(IEnumerable<Event> 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<Guid> friends, EventEngagementType? friendsEngagementType,
IEnumerable<string> sortBy, string direction);
Category? category, State? state, IEnumerable<Guid> organizations, IEnumerable<Guid> friends,
EventEngagementType? friendsEngagementType, IEnumerable<string> sortBy, string direction);
Task<(IEnumerable<Event> events, int pageNumber,int pageSize, int totalPages, int totalElements)> BrowseOrganizerEventsAsync(
int pageNumber, int pageSize, string name, Guid organizerId, DateTime dateFrom, DateTime dateTo,
IEnumerable<string> sortBy, string direction, State? state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ public async Task<IEnumerable<Event>> GetAllAsync()

public async Task<(IEnumerable<Event> 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<Guid> friends, EventEngagementType? friendsEngagementType,
IEnumerable<string> sortBy, string direction)
Category? category, State? state, IEnumerable<Guid> organizations, IEnumerable<Guid> friends,
EventEngagementType? friendsEngagementType, IEnumerable<string> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ public static FilterDefinition<EventDocument> AddFriendsFilter (this FilterDefin

return filterDefinition;
}

public static FilterDefinition<EventDocument> AddOrganizationsIdFilter(this FilterDefinition<EventDocument> filterDefinition,
IEnumerable<Guid> organizationsEnumerable)
{
var organizations = organizationsEnumerable.ToList();
if (organizations.Count > 0)
{
filterDefinition &= FilterDefinitionBuilder.In(x => x.Organizer.OrganizationId, organizations);
}

return filterDefinition;
}

public static FilterDefinition<EventDocument> AddEventIdFilter(this FilterDefinition<EventDocument> filterDefinition,
IEnumerable<Guid> eventIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Convey.HTTP;
using MiniSpace.Services.Events.Application.DTO;
Expand All @@ -17,8 +18,11 @@ public OrganizationsServiceClient(IHttpClient httpClient, HttpClientOptions opti
_url = options.Services["organizations"];
}

public Task<OrganizationDto> GetAsync(Guid id)
=> _httpClient.GetAsync<OrganizationDto>($"{_url}/organizations/{id}/details");
public Task<OrganizationDto> GetAsync(Guid organizationId, Guid rootId)
=> _httpClient.GetAsync<OrganizationDto>($"{_url}/organizations/{organizationId}/details?rootId={rootId}");

public Task<IEnumerable<Guid>> GetAllChildrenOrganizations(Guid organizationId, Guid rootId)
=> _httpClient.GetAsync<IEnumerable<Guid>>($"{_url}/organizations/{organizationId}/children/all?rootId={rootId}");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -33,6 +37,7 @@ public async Task<PagedResponse<IEnumerable<EventDto>>> BrowseEventsAsync(Search
Category? category = null;
State? state = null;
EventEngagementType? friendsEngagementType = null;
IEnumerable<Guid> organizations = new List<Guid>();
if(command.DateFrom != string.Empty)
{
dateFrom =_eventValidator.ParseDate(command.DateFrom, "DateFrom");
Expand All @@ -54,11 +59,16 @@ public async Task<PagedResponse<IEnumerable<EventDto>>> 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<Guid>();
}
(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<IEnumerable<EventDto>>(result.events.Select(e => new EventDto(e, identity.Id)),
Expand Down

0 comments on commit a7cd536

Please sign in to comment.