-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature: Post 삭제 및 모든 좋아요 기능, 조회수 기능, 투표 기능 구현(#46) #48
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
backend/src/main/java/aimo/backend/domains/like/controller/LikeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package aimo.backend.domains.like.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import aimo.backend.common.dto.DataResponse; | ||
import aimo.backend.domains.like.model.LikeType; | ||
import aimo.backend.domains.like.service.ChildCommentLikeService; | ||
import aimo.backend.domains.like.service.ParentCommentLikeService; | ||
import aimo.backend.domains.like.service.PostLikeService; | ||
import aimo.backend.domains.member.entity.Member; | ||
import aimo.backend.util.memberLoader.MemberLoader; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/") | ||
@RequiredArgsConstructor | ||
public class LikeController { | ||
|
||
private final PostLikeService postLikeService; | ||
private final MemberLoader memberLoader; | ||
private final ChildCommentLikeService childCommentLikeService; | ||
private final ParentCommentLikeService parentCommentLikeService; | ||
|
||
@PostMapping("/{postId}/likes") | ||
public ResponseEntity<DataResponse<Void>> likePost( | ||
@PathVariable Long postId, | ||
@RequestParam("likeType") LikeType likeType | ||
) { | ||
Member member = memberLoader.getMember(); | ||
postLikeService.likePost(member, postId, likeType); | ||
|
||
return ResponseEntity.ok(DataResponse.noContent()); | ||
} | ||
|
||
@PostMapping("/comments/child/{childCommentId}/like") | ||
public ResponseEntity<DataResponse<Void>> likeChildComment( | ||
@PathVariable Long childCommentId, | ||
@RequestParam("likeType") LikeType likeType | ||
) { | ||
Member member = memberLoader.getMember(); | ||
childCommentLikeService.likeChildComment(member, childCommentId, likeType); | ||
|
||
return ResponseEntity.ok(DataResponse.ok()); | ||
} | ||
|
||
@PostMapping("/comments/{parentCommentId}/like") | ||
public ResponseEntity<DataResponse<Void>> likeParentComment( | ||
@PathVariable Long parentCommentId, | ||
@RequestParam("likeType") LikeType likeType | ||
) { | ||
Member member = memberLoader.getMember(); | ||
parentCommentLikeService.likeParentComment(member, parentCommentId, likeType); | ||
|
||
return ResponseEntity.ok(DataResponse.ok()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/aimo/backend/domains/like/model/LikeType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package aimo.backend.domains.like.model; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum LikeType { | ||
LIKE("좋아요"), | ||
CANCEL_LIKE("좋아요 취소") | ||
; | ||
|
||
private final String value; | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/aimo/backend/domains/like/repository/ChildCommentLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package aimo.backend.domains.like.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import aimo.backend.domains.like.entity.ChildCommentLike; | ||
|
||
public interface ChildCommentLikeRepository extends JpaRepository<ChildCommentLike, Long> { | ||
|
||
void deleteByMember_IdAndChildComment_Id(Long id, Long childCommentId); | ||
|
||
boolean existsByChildComment_IdAndMember_Id(Long childCommentId, Long id); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/aimo/backend/domains/like/repository/ParentCommentLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package aimo.backend.domains.like.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import aimo.backend.domains.like.entity.ParentCommentLike; | ||
|
||
public interface ParentCommentLikeRepository extends JpaRepository<ParentCommentLike, Long> { | ||
|
||
void deleteByParentComment_Id(Long id, Long parentCommentId); | ||
|
||
Boolean existsByParentComment_IdAndMember_Id(Long parentCommentId, Long memberId); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/aimo/backend/domains/like/repository/PostLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package aimo.backend.domains.like.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import aimo.backend.domains.like.entity.PostLike; | ||
|
||
public interface PostLikeRepository extends JpaRepository<PostLike, Long> { | ||
|
||
void deleteByMember_IdAndPost_Id(Long id, Long postId); | ||
|
||
boolean existsByPost_IdAndMember_Id(Long postId, Long memberId); | ||
} |
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/aimo/backend/domains/like/service/ChildCommentLikeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package aimo.backend.domains.like.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import aimo.backend.domains.comment.entity.ChildComment; | ||
import aimo.backend.domains.comment.service.ChildCommentService; | ||
import aimo.backend.domains.like.entity.ChildCommentLike; | ||
import aimo.backend.domains.like.model.LikeType; | ||
import aimo.backend.domains.like.repository.ChildCommentLikeRepository; | ||
import aimo.backend.domains.member.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ChildCommentLikeService { | ||
|
||
private final ChildCommentLikeRepository childCommentLikeRepository; | ||
private final ChildCommentService childCommentService; | ||
|
||
public void likeChildComment(Member member, Long childCommentId, LikeType likeType) { | ||
ChildComment childComment = childCommentService.findById(childCommentId); | ||
|
||
if (likeType == LikeType.LIKE) { | ||
// 라이크가 이미 존재하면 무시 | ||
if (childCommentLikeRepository.existsByChildComment_IdAndMember_Id(childCommentId, member.getId())) { | ||
return; | ||
} | ||
|
||
childCommentLikeRepository.save(ChildCommentLike.builder() | ||
.childComment(childComment) | ||
.member(member) | ||
.build()); | ||
} else { | ||
childCommentLikeRepository.deleteByMember_IdAndChildComment_Id(member.getId(), childCommentId); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/aimo/backend/domains/like/service/ParentCommentLikeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package aimo.backend.domains.like.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import aimo.backend.domains.comment.entity.ParentComment; | ||
import aimo.backend.domains.comment.service.ParentCommentService; | ||
import aimo.backend.domains.like.entity.ParentCommentLike; | ||
import aimo.backend.domains.like.model.LikeType; | ||
import aimo.backend.domains.like.repository.ParentCommentLikeRepository; | ||
import aimo.backend.domains.member.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ParentCommentLikeService { | ||
|
||
private final ParentCommentLikeRepository parentCommentLikeRepository; | ||
private final ParentCommentService parentCommentService; | ||
|
||
public void likeParentComment(Member member, Long parentCommentId, LikeType likeType) { | ||
ParentComment parentComment = parentCommentService.findById(parentCommentId); | ||
|
||
if (likeType == LikeType.LIKE) { | ||
// 라이크가 이미 존재하면 무시 | ||
if (parentCommentLikeRepository.existsByParentComment_IdAndMember_Id(parentCommentId, member.getId())) { | ||
return; | ||
} | ||
|
||
parentCommentLikeRepository.save(ParentCommentLike.builder() | ||
.parentComment(parentComment) | ||
.member(member) | ||
.build()); | ||
} else { | ||
parentCommentLikeRepository.deleteByParentComment_Id(member.getId(), parentCommentId); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likeType으로 분리한게 인상적이네요. 기존에 설계한 API를 더 발전시키려는 고민이 묻어나서 보기 좋습니다.