7
7
using MiniSpace . Services . Comments . Application . Services ;
8
8
using MiniSpace . Services . Comments . Core . Entities ;
9
9
using MiniSpace . Services . Comments . Core . Repositories ;
10
+ using MiniSpace . Services . Comments . Application . Services . Clients ;
10
11
11
12
namespace MiniSpace . Services . Comments . Application . Commands . Handlers
12
13
{
@@ -19,6 +20,7 @@ public class UpdateCommentHandler : ICommandHandler<UpdateComment>
19
20
private readonly IAppContext _appContext ;
20
21
private readonly IMessageBroker _messageBroker ;
21
22
private readonly IDateTimeProvider _dateTimeProvider ;
23
+ private readonly IStudentsServiceClient _userServiceClient ;
22
24
23
25
public UpdateCommentHandler (
24
26
IOrganizationEventsCommentRepository organizationEventsCommentRepository ,
@@ -27,7 +29,8 @@ public UpdateCommentHandler(
27
29
IUserPostsCommentRepository userPostsCommentRepository ,
28
30
IAppContext appContext ,
29
31
IMessageBroker messageBroker ,
30
- IDateTimeProvider dateTimeProvider )
32
+ IDateTimeProvider dateTimeProvider ,
33
+ IStudentsServiceClient userServiceClient )
31
34
{
32
35
_organizationEventsCommentRepository = organizationEventsCommentRepository ;
33
36
_organizationPostsCommentRepository = organizationPostsCommentRepository ;
@@ -36,6 +39,7 @@ public UpdateCommentHandler(
36
39
_appContext = appContext ;
37
40
_messageBroker = messageBroker ;
38
41
_dateTimeProvider = dateTimeProvider ;
42
+ _userServiceClient = userServiceClient ;
39
43
}
40
44
41
45
public async Task HandleAsync ( UpdateComment command , CancellationToken cancellationToken = default )
@@ -83,26 +87,31 @@ public async Task HandleAsync(UpdateComment command, CancellationToken cancellat
83
87
case nameof ( CommentContext . OrganizationEvent ) :
84
88
await _organizationEventsCommentRepository . UpdateAsync ( comment ) ;
85
89
break ;
86
-
87
90
case nameof ( CommentContext . OrganizationPost ) :
88
91
await _organizationPostsCommentRepository . UpdateAsync ( comment ) ;
89
92
break ;
90
-
91
93
case nameof ( CommentContext . UserEvent ) :
92
94
await _userEventsCommentRepository . UpdateAsync ( comment ) ;
93
95
break ;
94
-
95
96
case nameof ( CommentContext . UserPost ) :
96
97
await _userPostsCommentRepository . UpdateAsync ( comment ) ;
97
98
break ;
98
99
}
99
100
101
+ var user = await _userServiceClient . GetAsync ( identity . Id ) ;
102
+ if ( user == null )
103
+ {
104
+ throw new UserNotFoundException ( identity . Id ) ;
105
+ }
106
+
100
107
await _messageBroker . PublishAsync ( new CommentUpdated (
101
108
commentId : command . CommentId ,
102
109
userId : identity . Id ,
103
110
commentContext : command . CommentContext ,
104
111
updatedAt : _dateTimeProvider . Now ,
105
- commentContent : command . TextContent
112
+ commentContent : command . TextContent ,
113
+ userName : $ "{ user . FirstName } { user . LastName } ",
114
+ profileImageUrl : user . ProfileImageUrl
106
115
) ) ;
107
116
}
108
117
}
0 commit comments