-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/#101/게시글 댓글 #107
Merged
The head ref may contain hidden characters: "feat/#101/\uAC8C\uC2DC\uAE00-\uB313\uAE00"
Merged
Feat/#101/게시글 댓글 #107
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
19dac56
refactor: userSpaceDao를 이용하여 UserSpace 객체 호출
arkchive efaed6b
refactor: targetId 타입 변경
arkchive bb39591
feat: 게시글 전체 댓글 조회 dto 생성
arkchive e101cc4
feat: 댓글 오류 추가
arkchive 2b69fb4
feat: PostException 삭제
arkchive ac17ed2
refactor: PostComment -> Comment 이름 변경
arkchive 31d36f0
feat: 댓글 관련 좋아요 로직 생성 및 게시글 관련 좋아요 로직 수정
arkchive 64cad8e
feat: 빌더 생성 및 오타 수정
arkchive e0eacb5
feat: 특정 게시글 댓글 조회 api 개발
arkchive da5dfab
refactor: comment 이름 변경으로 인한 빌더 오류 수정
arkchive 72d862b
feat: LikeDao 분리
arkchive fce6af4
feat: 댓글 생성 dto 생성
arkchive 62aab18
feat: Comment 빌더 생성
arkchive 62e7cdb
feat: LikeDao 분리로 인한 수정
arkchive 345c3c5
feat: 게시글 상세 조회 시 댓글 리스트 반환 변경
arkchive 6b5a957
feat: 댓글 생성 api 개발
arkchive a08a71c
feat: pull origin develop
arkchive 0b21e97
refactor: 댓글 생성 시 댓글 아이디 반환되도록 리팩토링
arkchive df4c27a
Merge branch 'develop' of https://github.com/KUIT-Space/KUIT_Space_Ba…
arkchive 22a44a6
feat: 대댓글 유효성 검사
arkchive c2fc113
refactor: 오류 수정
arkchive 1f153f0
feat: 댓글 좋아요 api 개발
arkchive 7ae8c7a
feat: 변수명 수정
arkchive 669ce2d
refactor: 유효성 검사 로직 수정
arkchive 6db690a
feat: 게시글, 댓글 유효성 검사 추가
arkchive be0a751
refactor: 댓글 유효성 검사 로직 수정 (isReply 삭제)
arkchive 0757242
Merge branch 'develop' of https://github.com/KUIT-Space/KUIT_Space_Ba…
arkchive a3c8cd8
refactor: validateUserInSpace 로직 삭제
arkchive 796a94c
Merge branch 'develop' of https://github.com/KUIT-Space/KUIT_Space_Ba…
arkchive 084ab94
feat: @CheckUserSpace(required = false)추가
arkchive 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
54 changes: 54 additions & 0 deletions
54
src/main/java/space/space_spring/controller/CommentController.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,54 @@ | ||
package space.space_spring.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
import space.space_spring.argumentResolver.jwtLogin.JwtLoginAuth; | ||
import space.space_spring.dto.comment.request.CreateCommentRequest; | ||
import space.space_spring.dto.comment.response.ReadCommentsResponse; | ||
import space.space_spring.response.BaseResponse; | ||
import space.space_spring.service.CommentService; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/space/{spaceId}/board/post/{postId}/comment") | ||
@Slf4j | ||
public class CommentController { | ||
private final CommentService commentService; | ||
|
||
// 댓글 조회 | ||
@GetMapping | ||
public BaseResponse<List<ReadCommentsResponse>> getComments( | ||
@JwtLoginAuth Long userId, | ||
@PathVariable Long spaceId, | ||
@PathVariable Long postId | ||
) { | ||
// TODO 1: 유저가 스페이스에 속하는 지 검증 | ||
commentService.validateUserInSpace(userId, spaceId); | ||
|
||
// TODO 2: 특정 게시글의 댓글 리스트 get | ||
List<ReadCommentsResponse> comments = commentService.getCommentsByPost(postId, userId); | ||
return new BaseResponse<>(comments); | ||
} | ||
|
||
// 댓글 생성 | ||
@PostMapping | ||
public BaseResponse<CreateCommentRequest.Response> createComment( | ||
@JwtLoginAuth Long userId, | ||
@PathVariable Long spaceId, | ||
@PathVariable Long postId, | ||
@RequestBody @Valid CreateCommentRequest.Request createCommentRequest | ||
) { | ||
// TODO 1: 유저가 스페이스에 속하는 지 검증 | ||
commentService.validateUserInSpace(userId, spaceId); | ||
|
||
// TODO 2: 작성한 댓글 저장 및 아이디 반환 | ||
Long commentId = commentService.createComment(userId, postId, createCommentRequest); | ||
CreateCommentRequest.Response response = CreateCommentRequest.Response.of(commentId); | ||
return new BaseResponse<>(response); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
import space.space_spring.entity.Comment; | ||
import space.space_spring.entity.Post; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface CommentDao extends JpaRepository<Comment, Long> { | ||
// 특정 게시글의 댓글을 가져오는 메서드 | ||
List<Comment> findByPost(Post post); | ||
|
||
// 대댓글 수를 계산하는 메서드 | ||
int countByTargetId(Long targetId); | ||
|
||
// 유저가 특정 댓글을 좋아요 했는지 확인하는 메서드 | ||
@Query("SELECT CASE WHEN COUNT(l) > 0 THEN true ELSE false END " + | ||
"FROM CommentLike l WHERE l.comment.commentId = :commentId AND l.user.userId = :userId") | ||
boolean isUserLikedComment(@Param("commentId") Long commentId, @Param("userId") Long userId); | ||
|
||
} |
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,14 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import space.space_spring.entity.Comment; | ||
import space.space_spring.entity.CommentLike; | ||
import space.space_spring.entity.User; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface CommentLikeDao extends JpaRepository<CommentLike, Long> { | ||
Optional<CommentLike> findByUserAndComment(User user, Comment comment); | ||
} |
6 changes: 2 additions & 4 deletions
6
.../java/space/space_spring/dao/LikeDao.java → ...a/space/space_spring/dao/PostLikeDao.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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package space.space_spring.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import space.space_spring.entity.Post; | ||
import space.space_spring.entity.PostLike; | ||
import space.space_spring.entity.User; | ||
import space.space_spring.entity.*; | ||
|
||
import java.util.Optional; | ||
|
||
public interface LikeDao extends JpaRepository<PostLike, Long> { | ||
public interface PostLikeDao extends JpaRepository<PostLike, Long> { | ||
Optional<PostLike> findByUserAndPost(User user, Post post); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/space/space_spring/dto/comment/request/CreateCommentRequest.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,42 @@ | ||
package space.space_spring.dto.comment.request; | ||
|
||
import com.mongodb.lang.Nullable; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.*; | ||
import space.space_spring.entity.Comment; | ||
import space.space_spring.entity.Post; | ||
import space.space_spring.entity.User; | ||
|
||
|
||
public class CreateCommentRequest { | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Request { | ||
@NotBlank | ||
private String content; | ||
private Long targetId = null; | ||
|
||
@Builder | ||
public Comment toEntity(User user, Post post) { | ||
return Comment.builder() | ||
.user(user) | ||
.post(post) | ||
.content(content) | ||
.targetId(targetId) | ||
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Response { | ||
private Long CommentId; | ||
|
||
public static Response of(Long commentId) { | ||
return new Response(commentId); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/space/space_spring/dto/comment/response/ReadCommentsResponse.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,41 @@ | ||
package space.space_spring.dto.comment.response; | ||
|
||
import lombok.*; | ||
import space.space_spring.entity.Comment; | ||
import space.space_spring.entity.UserSpace; | ||
import space.space_spring.util.post.ConvertCreatedDate; | ||
|
||
@Builder | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReadCommentsResponse { | ||
private Long commentId; | ||
|
||
private String userProfileImg; | ||
private String userName; | ||
|
||
private String content; | ||
private String time; | ||
|
||
private int commentCount; | ||
private int likeCount; | ||
private boolean isLike; | ||
private Long targetId; | ||
|
||
public static ReadCommentsResponse of(Comment comment, UserSpace userSpace, boolean isLike, int commentCount) { | ||
return ReadCommentsResponse.builder() | ||
.commentId(comment.getCommentId()) | ||
.userName(userSpace != null ? userSpace.getUserName() : null) | ||
.userProfileImg(userSpace != null ? userSpace.getUserProfileImg() : null) | ||
.content(comment.getContent()) | ||
.time(ConvertCreatedDate.setCreatedDate(comment.getCreatedAt())) | ||
.commentCount(commentCount) | ||
.likeCount(comment.getLikeCount()) | ||
.isLike(isLike) | ||
.targetId(comment.getTargetId()) | ||
.build(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
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.
UserSpaceValidateIntercpter
와UserSpaceValidateIntercpterURL
보시면 "/space/{spaceId}인 컨트롤러는 Interceptor 적용됩니다!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.
넵 반영했습니다!