Skip to content

Commit

Permalink
fix: fix deletePostRealEmoji logic (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji-soo708 authored and CChuYong committed Jan 31, 2024
1 parent 337e52c commit 42960f9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public DefaultResponse deletePostRealEmoji(String postId, String realEmojiId) {
String memberId = authenticationHolder.getUserId();
MemberPost post = memberPostService.getMemberPostById(postId);
MemberPostRealEmoji postRealEmoji = memberPostRealEmojiService
.getMemberPostRealEmojiByRealEmojiIdAndMemberId(realEmojiId, memberId);
.getMemberPostRealEmojiByRealEmojiIdAndMemberIdAndPostId(realEmojiId, memberId, postId);

memberPostRealEmojiService.deletePostRealEmoji(postRealEmoji);
post.removeRealEmoji(postRealEmoji);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public interface MemberPostRealEmojiRepository extends JpaRepository<MemberPostRealEmoji, String> {
boolean existsByPostAndMemberIdAndRealEmoji(MemberPost post, String memberId, MemberRealEmoji emoji);

Optional<MemberPostRealEmoji> findByRealEmojiIdAndMemberId(String realEmojiId, String memberId);
Optional<MemberPostRealEmoji> findByRealEmojiIdAndMemberIdAndPostId(String realEmojiId, String memberId, String postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public boolean isMemberPostRealEmojiExists(MemberPost post, String memberId, Mem
* @return 게시물에 등록된 리얼 이모지
* @throws RegisteredRealEmojiNotFoundException 등록된 리얼 이모지가 없는 경우
*/
public MemberPostRealEmoji getMemberPostRealEmojiByRealEmojiIdAndMemberId(String realEmojiId, String memberId) {
return memberPostRealEmojiRepository.findByRealEmojiIdAndMemberId(realEmojiId, memberId)
public MemberPostRealEmoji getMemberPostRealEmojiByRealEmojiIdAndMemberIdAndPostId(String realEmojiId, String memberId,
String postId) {
return memberPostRealEmojiRepository.findByRealEmojiIdAndMemberIdAndPostId(realEmojiId, memberId, postId)
.orElseThrow(RegisteredRealEmojiNotFoundException::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class MemberPostRealEmojiControllerTest {
when(memberPostService.getMemberPostById(post.getId())).thenReturn(post);

//when
when(memberPostRealEmojiService.getMemberPostRealEmojiByRealEmojiIdAndMemberId("1", memberId))
when(memberPostRealEmojiService.getMemberPostRealEmojiByRealEmojiIdAndMemberIdAndPostId("1", memberId, post.getId()))
.thenThrow(RegisteredRealEmojiNotFoundException.class);

//then
Expand Down

0 comments on commit 42960f9

Please sign in to comment.