Skip to content

Commit

Permalink
Merge pull request #157 from SaintAngeLs/frontend_organizations
Browse files Browse the repository at this point in the history
Frontend organizations and reactions
  • Loading branch information
an2508374 authored May 19, 2024
2 parents 42862e6 + 7c331ff commit 9656552
Show file tree
Hide file tree
Showing 36 changed files with 660 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ public class OrganizationDetailsDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public Guid RootId { get; set; }
public IEnumerable<Guid> Organizers { get; set; }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<IEnumerable<OrganizationDto>> HandleAsync(GetChildrenOrganizat

var parent = root.AsEntity().GetSubOrganization(query.OrganizationId);
return parent == null ? Enumerable.Empty<OrganizationDto>()
: parent.SubOrganizations.Select(o => new OrganizationDto(o));
: parent.SubOrganizations.Select(o => new OrganizationDto(o, root.Id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<OrganizationDetailsDto> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<OrganizationDto> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public async Task<IEnumerable<OrganizationDto>> HandleAsync(GetOrganizerOrganiza
}

var roots = (await _repository.FindAsync(o => true)).Select(o =>o.AsEntity());
var organizerOrganizations = new List<Organization>();
var organizerOrganizations = new List<OrganizationDto>();
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public GetRootOrganizationsHandler(IMongoRepository<OrganizationDocument, Guid>
}

public async Task<IEnumerable<OrganizationDto>> 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));
}
}
19 changes: 10 additions & 9 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid
}

public Task<HttpResponse<object>> 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<object,object>("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<HttpResponse<object>> UpdateEventAsync(Guid eventId, string name, Guid organizerId, string startDate, string endDate,
Expand Down Expand Up @@ -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<HttpResponse<PagedResponseDto<IEnumerable<EventDto>>>> SearchEventsAsync(string name,
string organizer, string category, string state, IEnumerable<Guid> friends, string friendsEngagementType,
string dateFrom, string dateTo, PageableDto pageable)
public Task<HttpResponse<PagedResponseDto<IEnumerable<EventDto>>>> SearchEventsAsync(string name, string organizer,
Guid organizationId, Guid rootOrganizationId, string category, string state, IEnumerable<Guid> friends,
string friendsEngagementType, string dateFrom, string dateTo, PageableDto pageable)
{
return _httpClient.PostAsync<SearchEvents, PagedResponseDto<IEnumerable<EventDto>>>("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<HttpResponse<PagedResponseDto<IEnumerable<EventDto>>>> SearchOrganizerEventsAsync(Guid organizerId,
Expand Down
10 changes: 5 additions & 5 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Events/IEventsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public interface IEventsService
Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid studentId,
string engagementType, int page, int numberOfResults);
Task<HttpResponse<object>> 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<HttpResponse<object>> 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,
Expand All @@ -28,8 +28,8 @@ Task<HttpResponse<object>> UpdateEventAsync(Guid eventId, string name, Guid orga
Task CancelInterestInEventAsync(Guid eventId, Guid studentId);
Task RateEventAsync(Guid eventId, int rating, Guid studentId);
Task<HttpResponse<PagedResponseDto<IEnumerable<EventDto>>>> SearchEventsAsync(string name, string organizer,
string category, string state, IEnumerable<Guid> friends, string friendsEngagementType, string dateFrom,
string dateTo, PageableDto pageable);
Guid organizationId, Guid rootOrganizationId, string category, string state, IEnumerable<Guid> friends,
string friendsEngagementType, string dateFrom, string dateTo, PageableDto pageable);
Task<HttpResponse<PagedResponseDto<IEnumerable<EventDto>>>> SearchOrganizerEventsAsync(Guid organizerId,
string name, string state, string dateFrom, string dateTo, PageableDto pageable);
Task<EventParticipantsDto> GetEventParticipants(Guid eventId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace MiniSpace.Web.Areas.Organizations
{
public interface IOrganizationsService
{
Task<OrganizationDto> GetOrganizationAsync(Guid organizationId);
Task<OrganizationDetailsDto> GetOrganizationDetailsAsync(Guid organizationId);
Task<OrganizationDto> GetOrganizationAsync(Guid organizationId, Guid rootId);
Task<OrganizationDetailsDto> GetOrganizationDetailsAsync(Guid organizationId, Guid rootId);
Task<IEnumerable<OrganizationDto>> GetOrganizerOrganizationsAsync(Guid organizerId);
Task<IEnumerable<OrganizationDto>> GetRootOrganizationsAsync();
Task<IEnumerable<OrganizationDto>> GetChildrenOrganizationsAsync(Guid organizationId);
Task<HttpResponse<object>> AddOrganization(Guid organizationId, string name, Guid parentId);
Task AddOrganizerToOrganization(Guid organizationId, Guid organizerId);
Task RemoveOrganizerFromOrganization(Guid organizationId, Guid organizerId);
Task<IEnumerable<OrganizationDto>> GetChildrenOrganizationsAsync(Guid organizationId, Guid rootId);
Task<IEnumerable<Guid>> GetAllChildrenOrganizationsAsync(Guid organizationId, Guid rootId);
Task<HttpResponse<object>> CreateOrganization(Guid organizationId, string name, Guid rootId, Guid parentId);
Task<HttpResponse<object>> CreateRootOrganization(Guid organizationId, string name);
Task AddOrganizerToOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId);
Task RemoveOrganizerFromOrganization(Guid rootOrganizationId, Guid organizationId, Guid organizerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public OrganizationsService(IHttpClient httpClient, IIdentityService identitySer
_identityService = identityService;
}

public Task<OrganizationDto> GetOrganizationAsync(Guid organizationId)
public Task<OrganizationDto> GetOrganizationAsync(Guid organizationId, Guid rootId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<OrganizationDto>($"organizations/{organizationId}");
return _httpClient.GetAsync<OrganizationDto>($"organizations/{organizationId}?rootId={rootId}");
}

public Task<OrganizationDetailsDto> GetOrganizationDetailsAsync(Guid organizationId)
public Task<OrganizationDetailsDto> GetOrganizationDetailsAsync(Guid organizationId, Guid rootId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<OrganizationDetailsDto>($"organizations/{organizationId}/details");
return _httpClient.GetAsync<OrganizationDetailsDto>($"organizations/{organizationId}/details?rootId={rootId}");
}

public Task<IEnumerable<OrganizationDto>> GetOrganizerOrganizationsAsync(Guid organizerId)
Expand All @@ -42,30 +42,44 @@ public Task<IEnumerable<OrganizationDto>> GetRootOrganizationsAsync()
return _httpClient.GetAsync<IEnumerable<OrganizationDto>>("organizations/root");
}

public Task<IEnumerable<OrganizationDto>> GetChildrenOrganizationsAsync(Guid organizationId)
public Task<IEnumerable<OrganizationDto>> GetChildrenOrganizationsAsync(Guid organizationId, Guid rootId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<IEnumerable<OrganizationDto>>
($"organizations/{organizationId}/children?parentId={organizationId}");
($"organizations/{organizationId}/children?rootId={rootId}");
}

public Task<HttpResponse<object>> AddOrganization(Guid organizationId, string name, Guid parentId)
public Task<IEnumerable<Guid>> GetAllChildrenOrganizationsAsync(Guid organizationId, Guid rootId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync<object, object>("organizations", new {organizationId, name, parentId});
return _httpClient.GetAsync<IEnumerable<Guid>>
($"organizations/{organizationId}/children/all?rootId={rootId}");
}

public Task AddOrganizerToOrganization(Guid organizationId, Guid organizerId)
public Task<HttpResponse<object>> CreateOrganization(Guid organizationId, string name, Guid rootId, Guid parentId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync<object, object>($"organizations/{organizationId}/children",
new {organizationId, name, rootId, parentId});
}

public Task<HttpResponse<object>> CreateRootOrganization(Guid organizationId, string name)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync<object, object>("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}");
}
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<ReactionDto>> GetReactions(Guid contentId, ReactionContentType contentType);
Task<ReactionsSummaryDto> GetReactionsSummary(Guid contentId, ReactionContentType contentType);
Task<HttpResponse<object>> CreateReaction(Guid reactionId, Guid studentId, string reactionType,
Guid contentId, string contentType);
Task DeleteReaction(Guid reactionId);
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<ReactionDto>> GetReactions(Guid contentId, ReactionContentType contentType)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<IEnumerable<ReactionDto>>($"reactions?contentId={contentId}&contentType={contentType}");
}

public Task<ReactionsSummaryDto> GetReactionsSummary(Guid contentId, ReactionContentType contentType)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.GetAsync<ReactionsSummaryDto>($"reactions/summary?contentId={contentId}&contentType={contentType}");
}

public Task<HttpResponse<object>> CreateReaction(Guid reactionId, Guid studentId, string reactionType,
Guid contentId, string contentType)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync<object, object>("reactions",
new { reactionId, studentId, reactionType, contentId, contentType });
}

public Task DeleteReaction(Guid reactionId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.DeleteAsync($"reactions/{reactionId}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MiniSpace.Web.DTO.Enums
{
public enum ReactionContentType
{
Event,
Post
}
}
Loading

0 comments on commit 9656552

Please sign in to comment.