From f320157b36be173823339b0909d50849f39f1982 Mon Sep 17 00:00:00 2001 From: Suanna01 Date: Sun, 30 Jul 2023 16:23:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20Feat=20#57=20:=20[=EA=B0=80?= =?UTF-8?q?=EA=B3=84=EB=B6=80=20=EA=B3=B5=EC=9C=A0]=20=EA=B3=B5=EA=B0=90?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SharingSympathyController.java | 23 +++++++++++++ .../repository/SharingSympathyRepository.java | 14 ++++---- .../service/SharingSympathyService.java | 33 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingSympathyController.java create mode 100644 src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingSympathyService.java diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingSympathyController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingSympathyController.java new file mode 100644 index 0000000..59faa36 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingSympathyController.java @@ -0,0 +1,23 @@ +package com.umc.DongnaeFriend.domain.account.sharing.controller; + + +import com.umc.DongnaeFriend.domain.account.sharing.service.SharingSympathyService; +import lombok.RequiredArgsConstructor; +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.RestController; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/account-books/sharing/likes") +public class SharingSympathyController { + private final SharingSympathyService sharingSympathyService; + + // 게시글 공감하기 + @PostMapping("/{accountBookId}") + public String postSympathy(@PathVariable("accountBookId") Long accountBookId) { + sharingSympathyService.newSympathy(accountBookId); + return ""; + } +} diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java index f559723..28ba5c4 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java @@ -1,13 +1,15 @@ 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.SharingSympathy; +import com.umc.DongnaeFriend.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface SharingSympathyRepository extends JpaRepository { - - int countAllBySharingBoardId(Long sharing_board_id); - int countAllByUserId(Long userId); - List findByUser_Id(long user_id); + @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); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingSympathyService.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingSympathyService.java new file mode 100644 index 0000000..9b9bbc9 --- /dev/null +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/SharingSympathyService.java @@ -0,0 +1,33 @@ +package com.umc.DongnaeFriend.domain.account.sharing.service; + +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingBoard; +import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy; +import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingSympathyRepository; +import com.umc.DongnaeFriend.domain.user.entity.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class SharingSympathyService { + private final SharingSympathyRepository sharingSympathyRepository; + + public String newSympathy(Long accountBookId){ + // !임시! 유저 가져오기 + User user = sharingSympathyRepository.findByUserId(1L); + + // 게시판 가져오기 + SharingBoard sharingBoard = sharingSympathyRepository.findBySharingBoardId(accountBookId); + + // 공감 데이터 저장하기 + SharingSympathy sharingSympathy = SharingSympathy.builder() + .sharingBoard(sharingBoard) + .user(user) + .build(); + + sharingSympathyRepository.save(sharingSympathy); + + return "[가계부 공유] 공감 성공"; + } + +} From e2ce8d5893008ae0bf00938deb1d528383173259 Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Mon, 31 Jul 2023 14:18:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:white=5Fcheck=5Fmark:=20Feat=20#57=20:=20[?= =?UTF-8?q?=EA=B0=80=EA=B3=84=EB=B6=80=20=EA=B3=B5=EC=9C=A0]=20=EA=B3=B5?= =?UTF-8?q?=EA=B0=90=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sharing/controller/SharingCommentLikeController.java | 2 +- .../sharing/repository/SharingSympathyRepository.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java index 3cd7b64..6ff981c 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/controller/SharingCommentLikeController.java @@ -7,7 +7,7 @@ @RequiredArgsConstructor @RestController -@RequestMapping("/account-books/sharing/likes") +@RequestMapping("/account-books/sharing/comments/likes") public class SharingCommentLikeController { private final SharingCommentLikeService sharingCommentLikeService; diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java index 28ba5c4..e08eb8c 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/repository/SharingSympathyRepository.java @@ -7,9 +7,15 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; + public interface SharingSympathyRepository extends JpaRepository { @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); + + int countAllBySharingBoardId(Long sharing_board_id); + int countAllByUserId(Long userId); + List findByUser_Id(long user_id); }