Skip to content

Commit

Permalink
feat: 뉴스레터 좋아요 생성 및 삭제 기능 추가 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
why-only-english committed Feb 14, 2024
1 parent a93ad32 commit 9000552
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ public SuccessResponse<Message> 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<Message> 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<Message> cancelLike(final @PathVariable Long postId) {
Message message = newsletterPostService.cancelLike(postId);
return new SuccessResponse<>(message);
}

/* SCRAP */
@Operation(summary = "뉴스레터 스크랩 추가", description = "뉴스레터 ID에 해당하는 게시글에 스크랩을 추가합니다.")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class NewsletterPostService {
private final NewsletterScrapRepository newsletterScrapRepository;
private final NewsletterCommonService newsletterCommonService;
private final NewsletterScrapService newsletterScrapService;
private final NewsletterLikeService newsletterLikeService;


// /* -------------------------------------------- 존재 여부 확인 -------------------------------------------- */
Expand Down Expand Up @@ -136,6 +138,20 @@ public List<Newsletter> 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
Expand Down

0 comments on commit 9000552

Please sign in to comment.