From 90005528ad7a768280116bcc84a87c1fdf4b227b Mon Sep 17 00:00:00 2001 From: jgmoon <6813821@tukorea.ac.kr> Date: Thu, 15 Feb 2024 01:29:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=89=B4=EC=8A=A4=EB=A0=88=ED=84=B0=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/NewsletterResponseConstant.java | 24 +++++++++++++ .../post/controller/NewsletterController.java | 35 +++++++++++++++++++ .../post/service/NewsletterPostService.java | 16 +++++++++ 3 files changed, 75 insertions(+) diff --git a/src/main/java/com/api/ttoklip/domain/newsletter/main/constant/NewsletterResponseConstant.java b/src/main/java/com/api/ttoklip/domain/newsletter/main/constant/NewsletterResponseConstant.java index 80ef257d..4547f137 100644 --- a/src/main/java/com/api/ttoklip/domain/newsletter/main/constant/NewsletterResponseConstant.java +++ b/src/main/java/com/api/ttoklip/domain/newsletter/main/constant/NewsletterResponseConstant.java @@ -321,6 +321,30 @@ public class NewsletterResponseConstant { } """; + public static final String REGISTER_LIKE = """ + { + "time": "2024-02-13T12:55:35.127794", + "status": 200, + "code": "200", + "message": "요청에 성공하였습니다.", + "result": { + "message": "Newsletter Type의 5번째 좋아요을(를) 생성했습니다." + } + } + """; + + public static final String CANCEL_LIKE = """ + { + "time": "2024-02-13T13:01:49.26421", + "status": 200, + "code": "200", + "message": "요청에 성공하였습니다.", + "result": { + "message": "Newsletter Type의 5번째 좋아요을(를) 삭제했습니다." + } + } + """; + public static final String REGISTER_SCRAP = """ { "time": "2024-02-13T12:55:35.127794", diff --git a/src/main/java/com/api/ttoklip/domain/newsletter/post/controller/NewsletterController.java b/src/main/java/com/api/ttoklip/domain/newsletter/post/controller/NewsletterController.java index 624f1667..30f5f1c6 100644 --- a/src/main/java/com/api/ttoklip/domain/newsletter/post/controller/NewsletterController.java +++ b/src/main/java/com/api/ttoklip/domain/newsletter/post/controller/NewsletterController.java @@ -80,6 +80,41 @@ public SuccessResponse report(final @PathVariable Long postId, return new SuccessResponse<>(message); } + /* LIKE */ + @Operation(summary = "뉴스레터 좋아요 추가", description = "뉴스레터 ID에 해당하는 게시글에 좋아요를 추가합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "좋아요 추가 성공", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = SuccessResponse.class), + examples = @ExampleObject( + name = "SuccessResponse", + value = NewsletterResponseConstant.REGISTER_LIKE, + description = "뉴스레터에 좋아요를 추가했습니다." + )))}) + @PostMapping("/like/{postId}") + public SuccessResponse registerLike(final @PathVariable Long postId) { + Message message = newsletterPostService.registerLike(postId); + return new SuccessResponse<>(message); + } + + @Operation(summary = "뉴스레터 좋아요 취소", description = "뉴스레터 ID에 해당하는 게시글에 좋아요를 취소합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "좋아요 취소 성공", + content = @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = SuccessResponse.class), + examples = @ExampleObject( + name = "SuccessResponse", + value = NewsletterResponseConstant.CANCEL_LIKE, + description = "뉴스레터에 좋아요를 취소했습니다." + )))}) + @DeleteMapping("/like/{postId}") + public SuccessResponse cancelLike(final @PathVariable Long postId) { + Message message = newsletterPostService.cancelLike(postId); + return new SuccessResponse<>(message); + } + /* SCRAP */ @Operation(summary = "뉴스레터 스크랩 추가", description = "뉴스레터 ID에 해당하는 게시글에 스크랩을 추가합니다.") @ApiResponses(value = { diff --git a/src/main/java/com/api/ttoklip/domain/newsletter/post/service/NewsletterPostService.java b/src/main/java/com/api/ttoklip/domain/newsletter/post/service/NewsletterPostService.java index ed6d45e0..121d43f3 100644 --- a/src/main/java/com/api/ttoklip/domain/newsletter/post/service/NewsletterPostService.java +++ b/src/main/java/com/api/ttoklip/domain/newsletter/post/service/NewsletterPostService.java @@ -5,6 +5,7 @@ import com.api.ttoklip.domain.member.domain.Member; import com.api.ttoklip.domain.newsletter.comment.domain.NewsletterComment; import com.api.ttoklip.domain.newsletter.image.service.NewsletterImageService; +import com.api.ttoklip.domain.newsletter.like.service.NewsletterLikeService; import com.api.ttoklip.domain.newsletter.post.domain.Newsletter; import com.api.ttoklip.domain.newsletter.post.dto.request.NewsletterCreateReq; import com.api.ttoklip.domain.newsletter.post.dto.response.NewsletterSingleResponse; @@ -36,6 +37,7 @@ public class NewsletterPostService { private final NewsletterScrapRepository newsletterScrapRepository; private final NewsletterCommonService newsletterCommonService; private final NewsletterScrapService newsletterScrapService; + private final NewsletterLikeService newsletterLikeService; // /* -------------------------------------------- 존재 여부 확인 -------------------------------------------- */ @@ -136,6 +138,20 @@ public List getContentWithPageable(final Pageable pageable) { return newsletterRepository.findAll(pageable).getContent(); } + /* -------------------------------------------- LIKE -------------------------------------------- */ + @Transactional + public Message registerLike(Long postId) { + newsletterLikeService.registerLike(postId); + return Message.likePostSuccess(Newsletter.class, postId); + } + + @Transactional + public Message cancelLike(Long postId) { + newsletterLikeService.cancelLike(postId); + return Message.likePostCancel(Newsletter.class, postId); + } + /* -------------------------------------------- LIKE 끝 -------------------------------------------- */ + /* -------------------------------------------- SCRAP -------------------------------------------- */ @Transactional