From 86625e946aa8bbe3caf9b226b5095b38c38c9016 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 02:29:49 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix=20:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/co/kr/jurumarble/bookmark/service/BookmarkService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java index be2f1964..478dd924 100644 --- a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java +++ b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java @@ -4,9 +4,7 @@ import co.kr.jurumarble.bookmark.repository.BookmarkRepository; import co.kr.jurumarble.exception.user.UserNotFoundException; import co.kr.jurumarble.exception.vote.VoteNotFoundException; -import co.kr.jurumarble.user.domain.User; import co.kr.jurumarble.user.repository.UserRepository; -import co.kr.jurumarble.vote.domain.Vote; import co.kr.jurumarble.vote.repository.VoteRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; From 91117b7faed8b7193aa169119b42ea595cadf7ce Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 02:32:53 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20de?= =?UTF-8?q?scription=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/jurumarble/bookmark/controller/BookmarkController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/kr/jurumarble/bookmark/controller/BookmarkController.java b/src/main/java/co/kr/jurumarble/bookmark/controller/BookmarkController.java index 2fa937bf..7bd61557 100644 --- a/src/main/java/co/kr/jurumarble/bookmark/controller/BookmarkController.java +++ b/src/main/java/co/kr/jurumarble/bookmark/controller/BookmarkController.java @@ -19,7 +19,7 @@ public class BookmarkController { private final BookmarkService bookmarkService; - @Operation(summary = "투표 북마크", description = "헤더에 토큰 담고, 파라미터에 voteId 보내주시면 됩니다.") + @Operation(summary = "투표 북마크", description = "헤더에 토큰 담고, 파라미터에 voteId 보내주시면 됩니다. 북마크 여부 알아내서 생성, 삭제") @PostMapping("/{voteId}/bookmark") public ResponseEntity bookmarkVote(@PathVariable Long voteId, @RequestAttribute Long userId) { From 9990c477f147449af01e0f41862658647c1cc5f3 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 03:34:23 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refact=20:=20=EC=A4=91=EB=B3=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jurumarble/bookmark/service/BookmarkService.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java index 478dd924..007966e0 100644 --- a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java +++ b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java @@ -23,24 +23,16 @@ public class BookmarkService { @Transactional public void bookmarkVote(Long userId, Long voteId) { - userRepository.findById(userId).orElseThrow(UserNotFoundException::new); voteRepository.findById(voteId).orElseThrow(VoteNotFoundException::new); - - Optional byVoteAndUser = bookmarkRepository.findByUserIdAndVoteId(userId, voteId); - - byVoteAndUser.ifPresentOrElse( - bookmark -> { - //북마크를 눌렀는데 또 눌렀을 경우 북마크 취소 - bookmarkRepository.delete(bookmark); - }, + bookmarkRepository.findByUserIdAndVoteId(userId, voteId).ifPresentOrElse( + bookmarkRepository::delete, // 북마크가 없을 경우 북마크 추가 () -> { Bookmark bookmark = new Bookmark(userId, voteId); bookmarkRepository.save(bookmark); } ); - } public boolean checkBookmarked(Long userId, Long voteId) { From e4e73c85105445e735e57f7d55e882acb6749f17 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 03:34:45 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20cr?= =?UTF-8?q?eate=20=EC=BF=BC=EB=A6=AC=20=EC=83=9D=EC=84=B1,=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=82=A0=EC=A7=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/schema.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 5c2ed22f..dce7d6d9 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -103,9 +103,11 @@ CREATE TABLE drink CREATE TABLE bookmark ( - id BIGINT NOT NULL AUTO_INCREMENT, - user_id BIGINT NOT NULL, - vote_id BIGINT NOT NULL, + id BIGINT NOT NULL AUTO_INCREMENT, + user_id BIGINT NOT NULL, + vote_id BIGINT NOT NULL, + created_date TIMESTAMP DEFAULT NULL, + modified_date TIMESTAMP DEFAULT NULL, PRIMARY KEY (id) ); From 22dd4f2f962c793def142c6c2f8ba4831a1d0636 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 03:35:24 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refact=20:=20=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/co/kr/jurumarble/bookmark/service/BookmarkService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java index 007966e0..7a36d5f1 100644 --- a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java +++ b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java @@ -10,8 +10,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - @RequiredArgsConstructor @Service @Transactional(readOnly = true) From 1b9307ad023afb65172e59a0b3552172f40e5a7d Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 03:51:56 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat=20:=20=EC=88=A0=20=EC=A6=90=EA=B2=BC?= =?UTF-8?q?=EC=96=B4=EC=9A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drink/controller/DrinkController.java | 2 +- .../drink/domain/EnjoyDrinkValidator.java | 20 ------------------- .../drink/service/DrinkService.java | 18 ++++++++++++----- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/co/kr/jurumarble/drink/domain/EnjoyDrinkValidator.java diff --git a/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java b/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java index 22b67b36..f837d64a 100644 --- a/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java +++ b/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java @@ -36,7 +36,7 @@ public ResponseEntity getDrinkData(@PathVariable Long drinkId) .body(drinkData.toControllerResponse()); } - @Operation(summary = "전통주 즐겼어요 추가", description = "요청시 유저 토큰과 바디값을 잘 확인해서 보내주세요.") + @Operation(summary = "전통주 즐겼어요", description = "요청시 유저 토큰과 바디값을 잘 확인해서 보내주세요. 북마크 여부 알아내서 생성, 삭제") @PostMapping("/enjoys") public ResponseEntity enjoyDrink(@RequestAttribute Long userId, @RequestBody EnjoyDrinkRequest request) { drinkService.enjoyDrink(userId, request.toServiceRequest()); diff --git a/src/main/java/co/kr/jurumarble/drink/domain/EnjoyDrinkValidator.java b/src/main/java/co/kr/jurumarble/drink/domain/EnjoyDrinkValidator.java deleted file mode 100644 index 8ec8e6b9..00000000 --- a/src/main/java/co/kr/jurumarble/drink/domain/EnjoyDrinkValidator.java +++ /dev/null @@ -1,20 +0,0 @@ -package co.kr.jurumarble.drink.domain; - -import co.kr.jurumarble.drink.repository.EnjoyDrinkRepository; -import co.kr.jurumarble.exception.drink.AlreadyEnjoyedDrinkException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class EnjoyDrinkValidator { - - private final EnjoyDrinkRepository enjoyDrinkRepository; - - public void checkIsAlreadyEnjoyed(Long userId, Long drinkId) { - enjoyDrinkRepository.findByUserIdAndDrinkId(userId, drinkId) - .ifPresent(enjoyDrink -> { - throw new AlreadyEnjoyedDrinkException(); - }); - } -} diff --git a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java index ef0a0432..6e348746 100644 --- a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java +++ b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java @@ -3,7 +3,6 @@ import co.kr.jurumarble.drink.controller.request.DrinkData; import co.kr.jurumarble.drink.controller.response.GetHotDrinksResponse; import co.kr.jurumarble.drink.controller.response.GetMapInDrinksResponse; -import co.kr.jurumarble.drink.domain.EnjoyDrinkValidator; import co.kr.jurumarble.drink.domain.dto.MapInDrinkData; import co.kr.jurumarble.drink.domain.entity.Drink; import co.kr.jurumarble.drink.domain.entity.EnjoyDrink; @@ -39,7 +38,6 @@ public class DrinkService { private final DrinkRepository drinkRepository; private final EnjoyDrinkRepository enjoyDrinkRepository; - private final EnjoyDrinkValidator enjoyDrinkValidator; private final PageableConverter pageableConverter; private final UserRepository userRepository; @@ -49,10 +47,20 @@ public GetDrinkServiceResponse getDrinkData(Long drinkId) { return new GetDrinkServiceResponse(drink); } + @Transactional public void enjoyDrink(Long userId, EnjoyDrinkServiceRequest request) { - enjoyDrinkValidator.checkIsAlreadyEnjoyed(userId, request.getDrinkId()); - EnjoyDrink enjoyDrink = new EnjoyDrink(userId, request.getDrinkId()); - enjoyDrinkRepository.save(enjoyDrink); + userRepository.findById(userId).orElseThrow(UserNotFoundException::new); + drinkRepository.findById(request.getDrinkId()).orElseThrow(DrinkNotFoundException::new); + enjoyDrinkRepository.findByUserIdAndDrinkId(userId, request.getDrinkId()).ifPresentOrElse( + enjoyDrink -> { + // enjoyDrink가 존재하는 경우 삭제 로직을 추가합니다. + enjoyDrinkRepository.delete(enjoyDrink); + }, + () -> { + EnjoyDrink enjoyDrink = new EnjoyDrink(userId, request.getDrinkId()); + enjoyDrinkRepository.save(enjoyDrink); + } + ); } public List getHotDrinks() { From ad3a47dfbfb0def464277d345d75fc3517bf4c70 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Mon, 11 Sep 2023 13:42:47 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/kr/jurumarble/bookmark/service/BookmarkService.java | 1 - .../java/co/kr/jurumarble/drink/service/DrinkService.java | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java index 7a36d5f1..59e31432 100644 --- a/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java +++ b/src/main/java/co/kr/jurumarble/bookmark/service/BookmarkService.java @@ -25,7 +25,6 @@ public void bookmarkVote(Long userId, Long voteId) { voteRepository.findById(voteId).orElseThrow(VoteNotFoundException::new); bookmarkRepository.findByUserIdAndVoteId(userId, voteId).ifPresentOrElse( bookmarkRepository::delete, - // 북마크가 없을 경우 북마크 추가 () -> { Bookmark bookmark = new Bookmark(userId, voteId); bookmarkRepository.save(bookmark); diff --git a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java index 6e348746..299f9d68 100644 --- a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java +++ b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java @@ -52,10 +52,7 @@ public void enjoyDrink(Long userId, EnjoyDrinkServiceRequest request) { userRepository.findById(userId).orElseThrow(UserNotFoundException::new); drinkRepository.findById(request.getDrinkId()).orElseThrow(DrinkNotFoundException::new); enjoyDrinkRepository.findByUserIdAndDrinkId(userId, request.getDrinkId()).ifPresentOrElse( - enjoyDrink -> { - // enjoyDrink가 존재하는 경우 삭제 로직을 추가합니다. - enjoyDrinkRepository.delete(enjoyDrink); - }, + enjoyDrinkRepository::delete, () -> { EnjoyDrink enjoyDrink = new EnjoyDrink(userId, request.getDrinkId()); enjoyDrinkRepository.save(enjoyDrink);