Skip to content

Commit

Permalink
Merge pull request #142 from SaintAngeLs/frontend_posts
Browse files Browse the repository at this point in the history
Frontend issues resolving and adding some functionalities for posts
  • Loading branch information
SaintAngeLs committed May 12, 2024
2 parents 78ea74f + ac04b74 commit b703a35
Show file tree
Hide file tree
Showing 25 changed files with 1,134 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ modules:
- state:{state}
auth: true

- upstream: /{postId}
method: GET
use: downstream
downstream: posts-service/posts/{postId}

- upstream: /
method: GET
use: downstream
Expand Down
5 changes: 5 additions & 0 deletions MiniSpace.APIGateway/src/MiniSpace.APIGateway/ntrada.yml
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ modules:
- state:{state}
auth: true

- upstream: /{postId}
method: GET
use: downstream
downstream: posts-service/posts/{postId}

- upstream: /
method: GET
use: downstream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static async Task Main(string[] args)
.UseInfrastructure()
.UseDispatcherEndpoints(endpoints => endpoints
.Get("", ctx => ctx.Response.WriteAsync(ctx.RequestServices.GetService<AppOptions>().Name))
.Get<GetPost, PostDto>("posts/{postId}")
.Get<GetPosts, IEnumerable<PostDto>>("posts")
.Get<GetOrganizerPosts, IEnumerable<PostDto>>("posts/organizer/{organizerId}")
.Put<UpdatePost>("posts/{postId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Convey.CQRS.Queries;
using MiniSpace.Services.Posts.Application.Dto;

namespace MiniSpace.Services.Posts.Application.Queries
{
public class GetPost : IQuery<PostDto>
{
public Guid PostId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Convey.CQRS.Queries;
using Convey.Persistence.MongoDB;
using MiniSpace.Services.Posts.Application.Dto;
using MiniSpace.Services.Posts.Application.Queries;
using MiniSpace.Services.Posts.Infrastructure.Mongo.Documents;

namespace MiniSpace.Services.Posts.Infrastructure.Mongo.Queries.Handlers
{
public class GetPostHandler : IQueryHandler<GetPost, PostDto>
{
private readonly IMongoRepository<PostDocument, Guid> _repository;

public GetPostHandler(IMongoRepository<PostDocument, Guid> repository)
{
_repository = repository;
}

public async Task<PostDto> HandleAsync(GetPost query, CancellationToken cancellationToken)
{
var post = await _repository.GetAsync(query.PostId);

return post?.AsDto();
}
}
}
10 changes: 10 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Events/EventsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public Task<PagedResponseDto<IEnumerable<EventDto>>> GetStudentEventsAsync(Guid
capacity, fee, category, publishDate});
}

public 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, string category, string publishDate)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PutAsync<object, object>($"events/{eventId}", new {eventId, name, organizerId,
startDate, endDate, buildingName, street, buildingNumber, apartmentNumber, city, zipCode, description,
capacity, fee, category, publishDate});
}

public Task SignUpToEventAsync(Guid eventId, Guid studentId)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public interface IEventsService
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,
string category, string publishDate);
Task SignUpToEventAsync(Guid eventId, Guid studentId);
Task CancelSignUpToEventAsync(Guid eventId, Guid studentId);
Task ShowInterestInEventAsync(Guid eventId, Guid studentId);
Expand Down
8 changes: 5 additions & 3 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Posts/IPostsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using MiniSpace.Web.DTO;
using MiniSpace.Web.HttpClients;

namespace MiniSpace.Web.Areas.Posts
{
public interface IPostsService
{
Task<PostDto> GetPostAsync(Guid postId);
Task ChangePostStateAsync(Guid postId, string state, DateTime publishDate);
Task CreatePostAsync(Guid postId, Guid eventId, Guid studentId, string textContext, string mediaContext,
string state, DateTime publishedDate);
Task<HttpResponse<object>> CreatePostAsync(Guid postId, Guid eventId, Guid organizerId, string textContext,
string mediaContext, string state, DateTime? publishDate);
Task DeletePostAsync(Guid postId);
Task<IEnumerable<PostDto>> GetPostsAsync(Guid eventId);
Task UpdatePostAsync(Guid postId, string textContext, string mediaContext);
Task<HttpResponse<object>> UpdatePostAsync(Guid postId, string textContent, string mediaContent);
}
}
16 changes: 11 additions & 5 deletions MiniSpace.Web/src/MiniSpace.Web/Areas/Posts/PostsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ public PostsService(IHttpClient httpClient, IIdentityService identityService)
_httpClient = httpClient;
_identityService = identityService;
}

public Task<PostDto> GetPostAsync(Guid postId)
{
return _httpClient.GetAsync<PostDto>($"posts/{postId}");
}

public Task ChangePostStateAsync(Guid postId, string state, DateTime publishDate)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PutAsync($"posts/{postId}/state/{state}", new {postId, state, publishDate});
}

public Task CreatePostAsync(Guid postId, Guid eventId, Guid studentId, string textContext, string mediaContext, string state,
DateTime publishedDate)
public Task<HttpResponse<object>> CreatePostAsync(Guid postId, Guid eventId, Guid organizerId, string textContent,
string mediaContext, string state, DateTime? publishDate)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PostAsync("posts", new {postId, eventId, studentId, textContext, mediaContext, state, publishedDate});
return _httpClient.PostAsync<object, object>("posts", new {postId, eventId, organizerId, textContent,
mediaContext, state, publishDate});
}

public Task DeletePostAsync(Guid postId)
Expand All @@ -42,10 +48,10 @@ public Task<IEnumerable<PostDto>> GetPostsAsync(Guid eventId)
return _httpClient.GetAsync<IEnumerable<PostDto>>($"posts?eventId={eventId}");
}

public Task UpdatePostAsync(Guid postId, string textContext, string mediaContext)
public Task<HttpResponse<object>> UpdatePostAsync(Guid postId, string textContent, string mediaContent)
{
_httpClient.SetAccessToken(_identityService.JwtDto.AccessToken);
return _httpClient.PutAsync($"posts/{postId}", new {postId, textContext, mediaContext});
return _httpClient.PutAsync<object, object>($"posts/{postId}", new {postId, textContent, mediaContent});
}
}
}
3 changes: 2 additions & 1 deletion MiniSpace.Web/src/MiniSpace.Web/DTO/PostDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ public class PostDto
{
public Guid Id { get; set; }
public Guid EventId { get; set; }
public Guid StudentId { get; set; }
public Guid OrganizerId { get; set; }
public string TextContent { get; set; }
public string MediaContent { get; set; }
public string State { get; set; }
public DateTime? PublishDate { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public Task PostAsync<T>(string uri, T request)
public Task PutAsync<T>(string uri, T request)
=> TryExecuteAsync(uri, client => client.PutAsync(uri, GetPayload(request)));

public async Task<TResult> PutAsync<TRequest, TResult>(string uri, TRequest request)
public async Task<HttpResponse<TResult>> PutAsync<TRequest, TResult>(string uri, TRequest request)
{
var (success, content) = await TryExecuteAsync(uri, client => client.PutAsync(uri, GetPayload(request)));

return !success ? default : JsonConvert.DeserializeObject<TResult>(content, JsonSerializerSettings);
return !success ? new HttpResponse<TResult>(JsonConvert.DeserializeObject<ErrorMessage>(content, JsonSerializerSettings))
: new HttpResponse<TResult>(JsonConvert.DeserializeObject<TResult>(content, JsonSerializerSettings));
}

public Task DeleteAsync(string uri)
Expand Down
2 changes: 1 addition & 1 deletion MiniSpace.Web/src/MiniSpace.Web/HttpClients/IHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IHttpClient
Task PostAsync<T>(string uri, T request);
Task<HttpResponse<TResult>> PostAsync<TRequest, TResult>(string uri, TRequest request);
Task PutAsync<T>(string uri, T request);
Task<TResult> PutAsync<TRequest, TResult>(string uri, TRequest request);
Task<HttpResponse<TResult>> PutAsync<TRequest, TResult>(string uri, TRequest request);
Task DeleteAsync(string uri);
Task DeleteAsync(string uri, object payload);
}
Expand Down
24 changes: 24 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/Models/Events/UpdateEventModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace MiniSpace.Web.Models.Events
{
public class UpdateEventModel
{
public Guid EventId { get; set; }
public string Name { get; set; }
public Guid OrganizerId { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string BuildingName { get; set; }
public string Street { get; set; }
public string BuildingNumber { get; set; }
public string ApartmentNumber { get; set; }
public string City { get; set; }
public string ZipCode { get; set; }
public string Description { get; set; }
public int Capacity { get; set; }
public decimal Fee { get; set; }
public string Category { get; set; }
public DateTime PublishDate { get; set; }
}
}
15 changes: 15 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/Models/Posts/CreatePostModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace MiniSpace.Web.Models.Posts
{
public class CreatePostModel
{
public Guid PostId { get; set; }
public Guid EventId { get; set; }
public Guid OrganizerId { get; set; }
public string TextContent { get; set; }
public string MediaContent { get; set; }
public string State { get; set; }
public DateTime PublishDate { get; set; }
}
}
11 changes: 11 additions & 0 deletions MiniSpace.Web/src/MiniSpace.Web/Models/Posts/UpdatePostModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace MiniSpace.Web.Models.Posts
{
public class UpdatePostModel
{
public Guid PostId { get; set; }
public string TextContent { get; set; }
public string MediaContent { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
<h3 class="rz-p-12">Loading...</h3>
}
@if (pageInitialized && studentId != Guid.Empty)
@if (pageInitialized && adminId != Guid.Empty)
{
<h4 class="rz-p-8">To manage rights of a student, open details dialog by clicking "Show" button.</h4>

Expand Down Expand Up @@ -58,7 +58,7 @@
private int pageSize = 5;
IEnumerable<int> pageSizeOptions = new int[] { 5, 10, 20, 40};

private Guid studentId;
private Guid adminId;
private bool pageInitialized = false;

private int totalStudents = 0;
Expand All @@ -68,7 +68,7 @@
{
if (IdentityService.IsAuthenticated && IdentityService.GetCurrentUserRole() == "admin")
{
studentId = IdentityService.GetCurrentUserId();
adminId = IdentityService.GetCurrentUserId();

students = await StudentsService.GetStudentsAsync();
totalStudents = students.Count();
Expand Down
Loading

0 comments on commit b703a35

Please sign in to comment.