Skip to content

Commit

Permalink
Merge pull request #79 from SWM-WeLike2Coding/feat/likeCount
Browse files Browse the repository at this point in the history
feat: 좋아요 추가 삭제 시 현재 좋아요 개수를 반환하도록 구현
  • Loading branch information
kjungw1025 authored Oct 4, 2024
2 parents b79619f + 481d9bc commit 9ab02b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wl2c.elswhereproductservice.domain.like.controller;

import com.wl2c.elswhereproductservice.domain.like.model.dto.response.ResponseLikeCountDto;
import com.wl2c.elswhereproductservice.domain.like.service.LikeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -23,8 +24,9 @@ public class ProductLikeController {
* @param id 상품 id
*/
@PostMapping("/like/{id}")
public void like(HttpServletRequest request, @PathVariable Long id) {
public ResponseLikeCountDto like(HttpServletRequest request, @PathVariable Long id) {
likeService.like(id, parseLong(request.getHeader("requestId")));
return new ResponseLikeCountDto(likeService.getCountOfLikes(id));
}

/**
Expand All @@ -34,8 +36,9 @@ public void like(HttpServletRequest request, @PathVariable Long id) {
* @param id 상품 id
*/
@DeleteMapping("/like/{id}")
public void cancelLike(HttpServletRequest request, @PathVariable Long id) {
public ResponseLikeCountDto cancelLike(HttpServletRequest request, @PathVariable Long id) {
likeService.cancelLike(id, parseLong(request.getHeader("requestId")));
return new ResponseLikeCountDto(likeService.getCountOfLikes(id));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wl2c.elswhereproductservice.domain.like.model.dto.response;

import lombok.Getter;

@Getter
public class ResponseLikeCountDto {

private final int likeCount;

public ResponseLikeCountDto(int likeCount) {
this.likeCount = likeCount;
}
}

0 comments on commit 9ab02b5

Please sign in to comment.