8
8
import com .wsws .moduleapplication .group .event .GroupCommentLikedEvent ;
9
9
import com .wsws .moduleapplication .group .exception .GroupCommentNotFoundException ;
10
10
import com .wsws .moduleapplication .group .exception .GroupPostNotFoundException ;
11
+ import com .wsws .moduleapplication .group .exception .MemberNotInGroupException ;
11
12
import com .wsws .moduleapplication .group .exception .NotOwnerException ;
12
13
import com .wsws .moduleapplication .usercontext .user .exception .AlreadyLikedException ;
13
14
import com .wsws .moduleapplication .usercontext .user .exception .NotLikedException ;
14
15
import com .wsws .moduledomain .group .GroupComment ;
15
16
import com .wsws .moduledomain .group .GroupPost ;
16
17
import com .wsws .moduledomain .group .repo .GroupCommentRepository ;
18
+ import com .wsws .moduledomain .group .repo .GroupMemberRepository ;
17
19
import com .wsws .moduledomain .group .repo .GroupPostRepository ;
18
20
import com .wsws .moduledomain .feed .like .Like ;
19
21
import com .wsws .moduledomain .feed .like .LikeRepository ;
@@ -37,6 +39,7 @@ public class GroupCommentService {
37
39
private final LikeRepository likeRepository ;
38
40
private final GroupPostRepository groupPostRepository ;
39
41
private final ApplicationEventPublisher eventPublisher ;
42
+ private final GroupMemberRepository groupMemberRepository ;
40
43
41
44
42
45
@@ -45,6 +48,8 @@ public class GroupCommentService {
45
48
public void createGroupComment (CreateGroupCommentRequest request , Long groupPostId , String userId ) {
46
49
GroupPost groupPost = getGroupPost (groupPostId );
47
50
51
+ validateGroupMembership (userId , groupPost .getGroupId ().getValue ());
52
+
48
53
GroupComment groupComment = GroupComment .create (
49
54
null ,
50
55
request .content (),
@@ -165,11 +170,19 @@ private GroupPost getGroupPost(Long groupPostId) {
165
170
.orElseThrow (() -> GroupPostNotFoundException .EXCEPTION );
166
171
}
167
172
173
+
168
174
private GroupComment getGroupComment (Long groupCommentId ) {
169
175
return groupCommentRepository .findById (groupCommentId )
170
176
.orElseThrow (() -> GroupCommentNotFoundException .EXCEPTION );
171
177
}
172
178
179
+ // 그룹 멤버 여부 확인
180
+ private void validateGroupMembership (String userId , Long groupId ) {
181
+ boolean isMember = groupMemberRepository .existsByUserIdAndGroupId (userId , groupId );
182
+ if (!isMember ) {
183
+ throw MemberNotInGroupException .EXCEPTION ; }
184
+ }
185
+
173
186
// 본인 여부 확인
174
187
private void validateUser (GroupComment groupComment , String userId ) {
175
188
if (!groupComment .getUserId ().equals (UserId .of (userId ))) {
@@ -181,4 +194,3 @@ private void validateUser(GroupComment groupComment, String userId) {
181
194
182
195
183
196
184
-
0 commit comments