Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#389) (#388) udpate feed generation for posts, udpate frineds service #393

Merged
merged 93 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
5cc77c5
(#381) reactions: add update reaction command and udpate reaction com…
SaintAngeLs Aug 20, 2024
1830dba
(#381) reactions: update reaction repository
SaintAngeLs Aug 20, 2024
3ae982b
(#381) reactions: update reactions mongo repository
SaintAngeLs Aug 20, 2024
af83119
(#381) reactions: update api gateway
SaintAngeLs Aug 20, 2024
4626992
(#381) reaction: update the api
SaintAngeLs Aug 20, 2024
543b794
(#381) reactions: update reactions repositories addAsunc methods
SaintAngeLs Aug 21, 2024
4bee62d
(#381) web: update reaction service and postsList razor page
SaintAngeLs Aug 21, 2024
0848110
(#381) reactions: repositoris implemenations
SaintAngeLs Aug 21, 2024
97ea977
(#381) reactions: udpate reactions repositories interfaces
SaintAngeLs Aug 21, 2024
8084044
(#381) reactions: udpate getReatcions query handler
SaintAngeLs Aug 21, 2024
49f0115
(#381) reactions: udpate reactions repository implemetnaitnos
SaintAngeLs Aug 21, 2024
9cd45cc
(#381) reactions: udpate reactions summary dto
SaintAngeLs Aug 21, 2024
266c946
(#381) reactions: udpate getReactionsSummary handler
SaintAngeLs Aug 21, 2024
3ca82b1
(#381) web: update reactions sumamry dto
SaintAngeLs Aug 21, 2024
c1152c8
(#381) web: udpate posts list reaction icons
SaintAngeLs Aug 21, 2024
a8dc3c7
(#381) web: udpate createReactionDto target type dunamically
SaintAngeLs Aug 21, 2024
2376987
(#381) web: posts lists page reactions alignment
SaintAngeLs Aug 21, 2024
6bf0da5
(#381) organizations: add getPaginateUserOrganizations
SaintAngeLs Aug 21, 2024
e61d4af
(#381) organizations: udpate getParnigated user organisations
SaintAngeLs Aug 21, 2024
80f2ed6
(#381) api: update api for getPaginatedUserOrganizations
SaintAngeLs Aug 21, 2024
d377524
(#381) posts: update get post query handler
SaintAngeLs Aug 22, 2024
b8dbd03
(#381) comments: update comments api
SaintAngeLs Aug 22, 2024
ab08f5b
(#381) comments: update infrastructure
SaintAngeLs Aug 22, 2024
73c5d22
(#381) comments: update search comments query
SaintAngeLs Aug 22, 2024
7c893fd
(#381) commests, reactions: update apigateway routes
SaintAngeLs Aug 22, 2024
f380e5d
(#381) web: udpate posts pages
SaintAngeLs Aug 22, 2024
921d71d
(#381) reactions: udpdater reactions core
SaintAngeLs Aug 22, 2024
c9778e0
(#381) reactions update reactions core repositories
SaintAngeLs Aug 22, 2024
0839aa1
(#381) comments: update createReaction command handler
SaintAngeLs Aug 22, 2024
a5ade70
(#381) organizations: update getPaginagtedUserOrganiztions handler
SaintAngeLs Aug 22, 2024
e91adab
(#381) organizations: update getPaginatedUserOrganizations handler
SaintAngeLs Aug 22, 2024
6ab8734
(#381) web: udpate comments service
SaintAngeLs Aug 22, 2024
a8e3dea
(#381) web: udpate my posts page and my posts raozr page
SaintAngeLs Aug 22, 2024
4d03b87
(#381) commetns: update comments repositories
SaintAngeLs Aug 22, 2024
ec2014d
(#381) update create comment handler, update search comments quary
SaintAngeLs Aug 22, 2024
4768d00
Merge remote-tracking branch 'remotes/origin/dev' into organizations_…
SaintAngeLs Aug 23, 2024
42d12af
(#381) web: update posts lists
SaintAngeLs Aug 23, 2024
2652a28
(#381) posts: update studnet service client implementation
SaintAngeLs Aug 23, 2024
fcde590
(#351) posts: update core user comments history repository
SaintAngeLs Aug 23, 2024
bcd028b
(#351) posts: update dtos and service client
SaintAngeLs Aug 23, 2024
85913e1
(#351) posts: udpate media files api
SaintAngeLs Aug 23, 2024
b2d5ed4
(#351) posts: udpate user comment hispty repository
SaintAngeLs Aug 23, 2024
99bf063
(#351) posts: udpate infrastructure extensions
SaintAngeLs Aug 23, 2024
aa702db
(#351) posts: update core comment object
SaintAngeLs Aug 23, 2024
5fb6a2a
(#381) comments: remove comments from organization pots comment repos…
SaintAngeLs Aug 23, 2024
64f86a0
(#351) posts: update external events
SaintAngeLs Aug 23, 2024
d178554
(#351) posts: update user comments history repository add async method
SaintAngeLs Aug 23, 2024
99ef7a2
(#381) posts: implementation of predicion service with the comments t…
SaintAngeLs Aug 23, 2024
21f858f
(#351) posts: add comment created external event handler
SaintAngeLs Aug 23, 2024
5ab0e22
(#351) posts: update posts api to add the get user feed endpoint
SaintAngeLs Aug 23, 2024
e0b8f04
(#381) posts: udpate get user fedd handler browse reques
SaintAngeLs Aug 23, 2024
bcda4a3
(#381) apigateway: update routes for the posts feed
SaintAngeLs Aug 23, 2024
a5e5833
(#381) web: update post card
SaintAngeLs Aug 23, 2024
3151835
(#381) posts: add get user feed endpoint to api
SaintAngeLs Aug 23, 2024
bdcbef3
(#387) web: udpate posts user feed posts
SaintAngeLs Aug 23, 2024
2a71876
(#388) reactions: udpate reaction created evne published, udpate reac…
SaintAngeLs Aug 23, 2024
4d255ff
(#388) reactions: udpate reaction created evne published, udpate reac…
SaintAngeLs Aug 23, 2024
5d7feca
(#388) posts: add reaction core object
SaintAngeLs Aug 23, 2024
0adcdf9
(#388) posts: add IUserReactionsHistory repository interface
SaintAngeLs Aug 23, 2024
c614842
(#388) posts: add message attribute for the external reaction created…
SaintAngeLs Aug 23, 2024
5c107c0
(#388) posts: add reaction created evnet handler
SaintAngeLs Aug 23, 2024
70b4fb7
(#388) posts: arr user reactions history repository
SaintAngeLs Aug 23, 2024
5f8be57
(#388) posts: add IUserReactionsHistory repository
SaintAngeLs Aug 23, 2024
f3348ca
(#388) posts: udpate extensions
SaintAngeLs Aug 23, 2024
db59c56
(#388) reaction: update UpdateReaction command handler and command
SaintAngeLs Aug 23, 2024
a76a943
(#388) posts: update reaction created event
SaintAngeLs Aug 23, 2024
9ed94b4
(#388) web: update home razor page
SaintAngeLs Aug 23, 2024
5f456ab
(#388) comments: update add lickes commands and commands handlers
SaintAngeLs Aug 24, 2024
ea8ce81
(#388) posts: update get user feedback query handler
SaintAngeLs Aug 24, 2024
2da3053
(#388) posts: update the posts list and my posts pages, add the inter…
SaintAngeLs Aug 24, 2024
9e8f9ac
(#388) comments: update comments core domain object for likes
SaintAngeLs Aug 24, 2024
664d38e
(#388) comments: udpate UpdateAsync for each of the comments reposito…
SaintAngeLs Aug 24, 2024
20af333
(#388) comments: update addLike command handler
SaintAngeLs Aug 24, 2024
7b4cecf
(#388) posts: add friends servcie client
SaintAngeLs Aug 24, 2024
e1ccaa5
(#388) posts: add IfrinedsServiceClient and dto
SaintAngeLs Aug 24, 2024
4fa03c8
(#388) posts: udpate posts raroz pages
SaintAngeLs Aug 24, 2024
3e1357c
(#388) posts: udpate prediction model
SaintAngeLs Aug 24, 2024
d3c4075
(#388) posts: update prediction service
SaintAngeLs Aug 24, 2024
9cf9821
(#389) friends: update User class
SaintAngeLs Aug 24, 2024
7227247
(#389) friends: update friends core domain classes
SaintAngeLs Aug 25, 2024
2807142
(#389) friends: update studnet service application
SaintAngeLs Aug 25, 2024
4da18ea
(#389) friends: update inftrastructure
SaintAngeLs Aug 25, 2024
e654a76
(#389) friends: update api
SaintAngeLs Aug 25, 2024
3600225
(#389) friends: update application events
SaintAngeLs Aug 25, 2024
e38b4c1
(#389) friends: udpate command handlers
SaintAngeLs Aug 25, 2024
3145c1c
(#389) friends: udpate dispached endpoints
SaintAngeLs Aug 25, 2024
d106c7b
(#389) web: update frined service
SaintAngeLs Aug 25, 2024
edbb96e
(#389) friends: update repositories implementation
SaintAngeLs Aug 25, 2024
0b84422
(#389) friends: update infrastrucutre
SaintAngeLs Aug 25, 2024
c5a6cea
(#389) web: update imports
SaintAngeLs Aug 25, 2024
41fb743
(#389) web: update friends razor pages
SaintAngeLs Aug 25, 2024
12b13ee
(#390) friends: update blaozr applciation frined service
SaintAngeLs Aug 25, 2024
41f73c7
(#390) friends: update api
SaintAngeLs Aug 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion MiniSpace.APIGateway/src/MiniSpace.APIGateway/ntrada.yml
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ modules:
auth: true

- upstream: /search
method: POST
method: GET
use: downstream
downstream: comments-service/comments/search

Expand All @@ -615,11 +615,21 @@ modules:
downstream: reactions-service/reactions
auth: true

- upstream: /{reactionId}
method: PUT
use: downstream
downstream: reactions-service/reactions/{reactionId}
auth: true
bind:
- reactionId: {reactionId}

- upstream: /{reactionId}
method: DELETE
use: downstream
downstream: reactions-service/reactions/{reactionId}
auth: true
bind:
- reactionId: {reactionId}

- upstream: /
method: GET
Expand Down Expand Up @@ -771,6 +781,14 @@ modules:
downstream: posts-service/posts
auth: true

- upstream: /users/{userId}/feed
method: GET
use: downstream
downstream: posts-service/posts/users/{userId}/feed
bind:
- userId:{userId}
auth: true

- upstream: /search
method: GET
use: downstream
Expand Down Expand Up @@ -798,6 +816,8 @@ modules:
method: GET
use: downstream
downstream: posts-service/posts/{postId}
bind:
- postId:{postId}

- upstream: /
method: GET
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniSpace.Services.Comments.Api", "MiniSpace.Services.Comments.Api.csproj", "{A198F9BC-F912-464E-BBCB-851CFBDD320F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A198F9BC-F912-464E-BBCB-851CFBDD320F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A198F9BC-F912-464E-BBCB-851CFBDD320F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A198F9BC-F912-464E-BBCB-851CFBDD320F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A198F9BC-F912-464E-BBCB-851CFBDD320F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {331542E3-F8A0-4711-AC84-18DD6B0D3896}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using MiniSpace.Services.Comments.Application.Queries;
using MiniSpace.Services.Comments.Application.Services;
using MiniSpace.Services.Comments.Infrastructure;
using MiniSpace.Services.Comments.Core.Wrappers;

namespace MiniSpace.Services.Identity.Api
{
Expand All @@ -34,14 +35,10 @@ public static async Task Main(string[] args)
.Configure(app => app
.UseInfrastructure()
.UseEndpoints(endpoints => endpoints
.Get("", ctx => ctx.Response.WriteAsync(ctx.RequestServices.GetService<AppOptions>().Name))
.Post<SearchComments>("comments/search", async (cmd, ctx) =>
{
var pagedResult = await ctx.RequestServices.GetService<ICommentService>().BrowseCommentsAsync(cmd);
await ctx.Response.WriteJsonAsync(pagedResult);
}))
.Get("", ctx => ctx.Response.WriteAsync(ctx.RequestServices.GetService<AppOptions>().Name)))
SaintAngeLs marked this conversation as resolved.
Show resolved Hide resolved
.UseDispatcherEndpoints(endpoints => endpoints
.Get<GetComment, CommentDto>("comments/{commentID}")
.Get<SearchComments, PagedResponse<CommentDto>>("comments/search")
.Post<CreateComment>("comments")
.Put<UpdateComment>("comments/{commentID}")
.Delete<DeleteComment>("comments/{commentID}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ namespace MiniSpace.Services.Comments.Application.Commands
{
public class AddLike : ICommand
{
public Guid CommentId { get; set; }
public Guid CommentId { get; }
public Guid UserId { get; }
public string CommentContext { get; }

public AddLike(Guid commentId)
public AddLike(Guid commentId, Guid userId, string commentContext)
{
CommentId = commentId;
UserId = userId;
CommentContext = commentContext;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,111 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Convey.CQRS.Commands;
using MiniSpace.Services.Comments.Application.Events;
using MiniSpace.Services.Comments.Application.Exceptions;
using MiniSpace.Services.Comments.Application.Services;
using MiniSpace.Services.Comments.Application.Services.Clients;
using MiniSpace.Services.Comments.Core.Entities;
using MiniSpace.Services.Comments.Core.Repositories;
using MiniSpace.Services.Comments.Core.Exceptions;
using MiniSpace.Services.Comments.Application.Services;
using System.Text.Json;

namespace MiniSpace.Services.Comments.Application.Commands.Handlers
{
public class AddLikeHandler : ICommandHandler<AddLike>
{
private readonly ICommentRepository _commentRepository;
private readonly IAppContext _appContext;
private readonly IOrganizationEventsCommentRepository _organizationEventsCommentRepository;
private readonly IOrganizationPostsCommentRepository _organizationPostsCommentRepository;
private readonly IUserEventsCommentRepository _userEventsCommentRepository;
private readonly IUserPostsCommentRepository _userPostsCommentRepository;
private readonly IMessageBroker _messageBroker;
private readonly IAppContext _appContext;
private readonly IStudentsServiceClient _userServiceClient;

public AddLikeHandler(ICommentRepository commentRepository, IAppContext appContext,
IMessageBroker messageBroker)
public AddLikeHandler(
IOrganizationEventsCommentRepository organizationEventsCommentRepository,
IOrganizationPostsCommentRepository organizationPostsCommentRepository,
IUserEventsCommentRepository userEventsCommentRepository,
IUserPostsCommentRepository userPostsCommentRepository,
IMessageBroker messageBroker,
IAppContext appContext,
IStudentsServiceClient userServiceClient)
{
_commentRepository = commentRepository;
_appContext = appContext;
_organizationEventsCommentRepository = organizationEventsCommentRepository;
_organizationPostsCommentRepository = organizationPostsCommentRepository;
_userEventsCommentRepository = userEventsCommentRepository;
_userPostsCommentRepository = userPostsCommentRepository;
_messageBroker = messageBroker;
_appContext = appContext;
_userServiceClient = userServiceClient;
}

public async Task HandleAsync(AddLike command, CancellationToken cancellationToken = default)
{
var comment = await _commentRepository.GetAsync(command.CommentId);
if (comment is null)
var commandJson = JsonSerializer.Serialize(command, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine($"Received AddLike command: {commandJson}");
var identity = _appContext.Identity;

if (!identity.IsAuthenticated || identity.Id != command.UserId)
{
throw new CommentNotFoundException(command.CommentId);
throw new UnauthorizedCommentAccessException(command.CommentId, identity.Id);
}

var identity = _appContext.Identity;
if (!identity.IsAuthenticated)
var user = await _userServiceClient.GetAsync(command.UserId);
if (user == null)
{
throw new UnauthorizedCommentAccessException(command.CommentId, identity.Id);
throw new UserNotFoundException(command.UserId);
}

if (!Enum.TryParse<CommentContext>(command.CommentContext, true, out var commentContext))
{
throw new InvalidCommentContextEnumException(command.CommentContext);
}

comment.Like(identity.Id);
await _commentRepository.UpdateAsync(comment);
Comment comment = await GetCommentAsync(command.CommentId, commentContext);
if (comment == null)
{
throw new CommentNotFoundException(command.CommentId);
}

comment.Like(command.UserId);
await UpdateCommentAsync(comment, commentContext);

await _messageBroker.PublishAsync(new CommentUpdated(command.CommentId));
}

private async Task<Comment> GetCommentAsync(Guid commentId, CommentContext context)
{
return context switch
{
CommentContext.OrganizationEvent => await _organizationEventsCommentRepository.GetAsync(commentId),
CommentContext.OrganizationPost => await _organizationPostsCommentRepository.GetAsync(commentId),
CommentContext.UserEvent => await _userEventsCommentRepository.GetAsync(commentId),
CommentContext.UserPost => await _userPostsCommentRepository.GetAsync(commentId),
_ => null
};
}

private async Task UpdateCommentAsync(Comment comment, CommentContext context)
{
switch (context)
{
case CommentContext.OrganizationEvent:
await _organizationEventsCommentRepository.UpdateAsync(comment);
break;
case CommentContext.OrganizationPost:
await _organizationPostsCommentRepository.UpdateAsync(comment);
break;
case CommentContext.UserEvent:
await _userEventsCommentRepository.UpdateAsync(comment);
break;
case CommentContext.UserPost:
await _userPostsCommentRepository.UpdateAsync(comment);
break;
default:
throw new InvalidCommentContextEnumException(context.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public CreateCommentHandler(
public async Task HandleAsync(CreateComment command, CancellationToken cancellationToken = default)
{
var identity = _appContext.Identity;

if (identity.IsAuthenticated)
{
Console.WriteLine($"User is authenticated: {identity.Id}");
Console.WriteLine($"User command id is: {command.UserId}");
}
else
{
Console.WriteLine("User is not authenticated.");
}
if (identity.IsAuthenticated && identity.Id != command.UserId)
{
throw new UnauthorizedCommentAccessException(command.ContextId, identity.Id);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Convey.CQRS.Queries;
using MiniSpace.Services.Comments.Application.Dto;
using MiniSpace.Services.Comments.Core.Wrappers;

namespace MiniSpace.Services.Comments.Application.Queries
{
public class SearchComments : IQuery<PagedResponse<CommentDto>>
{
public Guid ContextId { get; set; }
public string CommentContext { get; set; }
public Guid? ParentId { get; set; }
public int Page { get; set; }
public int Size { get; set; }
public string SortBy { get; set; } // Changed to string to handle the incoming JSON properly
public string Direction { get; set; }

// This property will split the SortBy string into an array
public IEnumerable<string> SortByArray =>
string.IsNullOrEmpty(SortBy) ? new List<string> { "CreatedAt" } : SortBy.Split(',');
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace MiniSpace.Services.Comments.Core.Entities
{
public class Comment : AggregateRoot
{
private ISet<Guid> _likes = new HashSet<Guid>();
private ISet<Reply> _replies = new HashSet<Reply>();
private readonly ISet<Guid> _likes = new HashSet<Guid>();
private readonly ISet<Reply> _replies = new HashSet<Reply>();

public Guid ContextId { get; private set; }
public CommentContext CommentContext { get; private set; }
Expand All @@ -22,17 +22,10 @@ public class Comment : AggregateRoot
public int RepliesCount => _replies.Count;
public bool IsDeleted { get; private set; }

public IEnumerable<Guid> Likes
{
get => _likes;
private set => _likes = new HashSet<Guid>(value);
}
// Expose the _likes set as a read-only IEnumerable
public IEnumerable<Guid> Likes => _likes;

public IEnumerable<Reply> Replies
{
get => _replies;
private set => _replies = new HashSet<Reply>(value);
}
public IEnumerable<Reply> Replies => _replies;

public Comment(Guid id, Guid contextId, CommentContext commentContext, Guid userId,
IEnumerable<Guid> likes, Guid parentId, string textContent, DateTime createdAt, DateTime lastUpdatedAt,
Expand All @@ -42,19 +35,19 @@ public Comment(Guid id, Guid contextId, CommentContext commentContext, Guid user
ContextId = contextId;
CommentContext = commentContext;
UserId = userId;
Likes = likes;
_likes = new HashSet<Guid>(likes);
ParentId = parentId;
TextContent = textContent;
CreatedAt = createdAt;
LastUpdatedAt = lastUpdatedAt;
LastReplyAt = lastReplyAt;
Replies = replies;
_replies = new HashSet<Reply>(replies);
IsDeleted = isDeleted;
}

public void Like(Guid userId)
{
if (Likes.Any(id => id == userId))
if (_likes.Contains(userId))
{
throw new UserAlreadyLikesCommentException(userId);
}
Expand All @@ -65,7 +58,7 @@ public void Like(Guid userId)

public void UnLike(Guid userId)
{
if (Likes.All(id => id != userId))
if (!_likes.Contains(userId))
{
throw new UserNotLikeCommentException(userId, Id);
}
Expand Down
Loading
Loading