-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#18
- Loading branch information
Showing
9 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...ava/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentController.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,45 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.controller; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; | ||
import com.umc.DongnaeFriend.domain.account.sharing.dto.ResSharingCommentList; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/account-books/sharing/comments") | ||
public class SharingCommentController { | ||
private final SharingCommentService sharingCommentService; | ||
|
||
// [가계부 공유] 댓글 등록 | ||
@PostMapping("/{accountBookId}") | ||
public String postComment(@PathVariable("accountBookId") Long accountBookId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { | ||
sharingCommentService.newComment(accountBookId, reqSharingCommentDto); | ||
return ""; | ||
} | ||
|
||
// [가계부 공유] 댓글 수정 | ||
@PutMapping("/{commentId}") | ||
public String putComment(@PathVariable("commentId") Long commentId, @RequestBody ReqSharingCommentDto reqSharingCommentDto) { | ||
sharingCommentService.modifyComment(commentId, reqSharingCommentDto); | ||
return ""; | ||
} | ||
|
||
// [가계부 공유] 댓글 삭제 | ||
@DeleteMapping("/{commentId}") | ||
public String deleteComment(@PathVariable("commentId") Long commentId) { | ||
sharingCommentService.deleteComment(commentId); | ||
return ""; | ||
} | ||
|
||
// [가계부 공유] 댓글 목록 조회 | ||
@GetMapping("") | ||
public ResSharingCommentList getList(@RequestParam Long accountBookId) { | ||
ResSharingCommentList resSharingCommentList = sharingCommentService.getCommentList(accountBookId); | ||
return resSharingCommentList; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.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,20 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.controller; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; | ||
import com.umc.DongnaeFriend.domain.account.sharing.service.SharingCommentLikeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/account-books/sharing/likes") | ||
public class SharingCommentLikeController { | ||
private final SharingCommentLikeService sharingCommentLikeService; | ||
|
||
// [가계부 공유] 댓글 좋아요 | ||
@PostMapping("/{commentId}") | ||
public String postCommentLike(@PathVariable("commentId") Long commentId) { | ||
sharingCommentLikeService.newLike(commentId); | ||
return ""; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ReqSharingCommentDto.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,13 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReqSharingCommentDto { | ||
Long parentCommentId; | ||
String content; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/ResSharingCommentList.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,20 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
public class ResSharingCommentList { | ||
int totalCount; | ||
List<SharingComment> commentList; | ||
|
||
@Builder | ||
public ResSharingCommentList(int totalCount, List<SharingComment> commentList) { | ||
this.totalCount = totalCount; | ||
this.commentList = commentList; | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentLikeRepository.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,16 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingCommentLike; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface SharingCommentLikeRepository extends JpaRepository<SharingCommentLike, Long> { | ||
@Query("SELECT u FROM User u WHERE u.id = :user_id") | ||
User findByUserId(@Param("user_id") Long user_id); | ||
|
||
@Query("SELECT sc FROM SharingComment sc WHERE sc.id = :sharing_comment_id") | ||
SharingComment findByCommentId(@Param("sharing_comment_id") Long sharing_comment_id); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ava/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingCommentRepository.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,20 +1,32 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.repository; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
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 java.util.List; | ||
import java.util.Objects; | ||
|
||
@Repository | ||
public interface SharingCommentRepository extends JpaRepository<SharingComment, Long> { | ||
@Query("SELECT u FROM User u WHERE u.id = :user_id") | ||
User findByUserId(@Param("user_id") Long user_id); | ||
@Query("SELECT sb FROM SharingBoard sb WHERE sb.id = :sharing_board_id") | ||
SharingBoard findBySharingBoardId(@Param("sharing_board_id") Long sharing_board_id); | ||
@Query("SELECT sc FROM SharingComment sc WHERE sc.sharingBoard = :sharingBoard") | ||
List<SharingComment> findAllByBoard(@Param("sharingBoard") SharingBoard sharingBoard); | ||
|
||
|
||
public int countAllBySharingBoardId(Long sharing_board_id); | ||
int countAllByUserId(Long userId); | ||
|
||
@Query(value = "select c from SharingComment c join fetch c.sharingBoard sb " + | ||
"where c.user.id = :userId order by c.createdAt desc") | ||
List<SharingComment> getCommentByUserIdAndBoard(@Param("userId") Long userId); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.../java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentLikeService.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,31 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.service; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingCommentLike; | ||
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentLikeRepository; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class SharingCommentLikeService { | ||
private final SharingCommentLikeRepository sharingCommentLikeRepository; | ||
|
||
public String newLike(Long commentId) { | ||
// !임시! 유저 가져오기 | ||
User user = sharingCommentLikeRepository.findByUserId(1L); | ||
|
||
// 댓글 가져오기 | ||
SharingComment sharingComment = sharingCommentLikeRepository.findByCommentId(commentId); | ||
|
||
SharingCommentLike sharingCommentLike = SharingCommentLike.builder() | ||
.user(user) | ||
.sharingComment(sharingComment) | ||
.build(); | ||
|
||
sharingCommentLikeRepository.save(sharingCommentLike); | ||
|
||
return "가계부 공유 댓글 좋아요 성공"; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
...main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingCommentService.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,101 @@ | ||
package com.umc.DongnaeFriend.domain.account.sharing.service; | ||
|
||
import com.umc.DongnaeFriend.domain.account.sharing.dto.ReqSharingCommentDto; | ||
import com.umc.DongnaeFriend.domain.account.sharing.dto.ResSharingCommentList; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; | ||
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment; | ||
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentRepository; | ||
import com.umc.DongnaeFriend.domain.user.entity.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class SharingCommentService { | ||
private final SharingCommentRepository sharingCommentRepository; | ||
|
||
public String newComment(Long accountBookId, ReqSharingCommentDto reqSharingCommentDto) { | ||
// !임시! 유저 가져오기 | ||
User user = sharingCommentRepository.findByUserId(1L); | ||
|
||
// 게시판 가져오기 | ||
SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId); | ||
|
||
// 대댓글 등록 | ||
if (!(reqSharingCommentDto.getParentCommentId() == null)){ | ||
// 부모 댓글 가져오기 | ||
Optional<SharingComment> parentCommentOptional = sharingCommentRepository.findById(reqSharingCommentDto.getParentCommentId()); | ||
SharingComment parentComment = parentCommentOptional.get(); | ||
|
||
// 댓글 빌드 | ||
SharingComment comment = SharingComment.builder() | ||
.parentComment(parentComment) | ||
.content(reqSharingCommentDto.getContent()) | ||
.isDeleted(false) | ||
.sharingBoard(sharingBoard) | ||
.user(user) | ||
.build(); | ||
|
||
sharingCommentRepository.save(comment); | ||
|
||
return "대댓글 등록 성공"; | ||
|
||
} | ||
|
||
// 댓글 등록 | ||
SharingComment comment = SharingComment.builder() | ||
.content(reqSharingCommentDto.getContent()) | ||
.isDeleted(false) | ||
.sharingBoard(sharingBoard) | ||
.user(user) | ||
.build(); | ||
|
||
sharingCommentRepository.save(comment); | ||
|
||
return "댓글 등록 성공"; | ||
} | ||
|
||
// [가계부 공유] 댓글 수정 | ||
public String modifyComment(Long commentId, ReqSharingCommentDto reqSharingCommentDto) { | ||
// 댓글 찾기 | ||
Optional<SharingComment> sharingCommentOptional = sharingCommentRepository.findById(commentId); | ||
SharingComment sharingComment = sharingCommentOptional.get(); | ||
|
||
sharingComment.modifyComment(reqSharingCommentDto); | ||
|
||
sharingCommentRepository.save(sharingComment); | ||
|
||
return "댓글 수정 성공"; | ||
} | ||
|
||
// [가계부 공유] 댓글 삭제 | ||
public String deleteComment(Long commentId) { | ||
// 댓글 찾기 | ||
Optional<SharingComment> sharingCommentOptional = sharingCommentRepository.findById(commentId); | ||
SharingComment sharingComment = sharingCommentOptional.get(); | ||
|
||
sharingCommentRepository.delete(sharingComment); | ||
|
||
return "댓글 삭제 성공"; | ||
} | ||
|
||
// [가계부 공유] 댓글 목록 조회 | ||
public ResSharingCommentList getCommentList(Long accountBookId) { | ||
// 게시판 가져오기 | ||
SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId); | ||
|
||
List<SharingComment> commentList = sharingCommentRepository.findAllByBoard(sharingBoard); | ||
|
||
ResSharingCommentList resSharingCommentList = ResSharingCommentList.builder() | ||
.totalCount(commentList.size()) | ||
.commentList(sharingCommentRepository.findAllByBoard(sharingBoard)) | ||
.build(); | ||
|
||
return resSharingCommentList; | ||
} | ||
|
||
} |