66import com .runtracker .domain .community .dto .PostDetailDTO ;
77import com .runtracker .domain .community .dto .PostListDTO ;
88import com .runtracker .domain .community .dto .RunningMetaDTO ;
9+ import com .runtracker .domain .community .event .PostCreateEvent ;
10+ import com .runtracker .domain .community .event .PostUpdateEvent ;
11+ import com .runtracker .domain .community .event .PostDeleteEvent ;
912import com .runtracker .domain .community .event .PostLikeEvent ;
1013import com .runtracker .domain .community .event .PostCommentEvent ;
1114import com .runtracker .domain .community .entity .Post ;
1720import com .runtracker .domain .community .exception .NoPostsFoundException ;
1821import com .runtracker .domain .community .exception .NoSearchResultsException ;
1922import com .runtracker .domain .community .exception .NotLikedPostException ;
23+ import com .runtracker .domain .community .exception .PhotosRequiredException ;
2024import com .runtracker .domain .community .exception .PostCreationFailedException ;
2125import com .runtracker .domain .community .exception .PostNotFoundException ;
2226import com .runtracker .domain .community .exception .UnauthorizedCommentAccessException ;
@@ -53,6 +57,10 @@ public void createPost(PostDTO postDTO, UserDetailsImpl userDetails) {
5357 Long crewId = userDetails .getCrewMembership ().getCrewId ();
5458 crewAuthorizationUtil .validateCrewMemberAccess (userDetails , crewId );
5559
60+ if (postDTO .getPhotos () == null || postDTO .getPhotos ().isEmpty ()) {
61+ throw new PhotosRequiredException ();
62+ }
63+
5664 try {
5765 Post .PostBuilder postBuilder = Post .builder ()
5866 .memberId (userDetails .getMemberId ())
@@ -71,6 +79,8 @@ public void createPost(PostDTO postDTO, UserDetailsImpl userDetails) {
7179 Post post = postBuilder .build ();
7280
7381 postRepository .save (post );
82+
83+ eventPublisher .publishEvent (new PostCreateEvent (userDetails .getMemberId (), post .getId ()));
7484 } catch (Exception e ) {
7585 throw new PostCreationFailedException ();
7686 }
@@ -104,6 +114,8 @@ public void updatePost(Long postId, PostDTO postDTO, UserDetailsImpl userDetails
104114 postDTO .getMeta ().getAvgSpeed ()
105115 );
106116 }
117+
118+ eventPublisher .publishEvent (new PostUpdateEvent (userDetails .getMemberId (), postId ));
107119 }
108120
109121 @ Transactional
@@ -118,6 +130,8 @@ public void deletePost(Long postId, UserDetailsImpl userDetails) {
118130 }
119131
120132 postRepository .deleteById (postId );
133+
134+ eventPublisher .publishEvent (new PostDeleteEvent (userDetails .getMemberId (), postId ));
121135 }
122136
123137 @ Transactional
0 commit comments