Skip to content

Commit

Permalink
Merge pull request #53 from Zatch-Team/Feature/ViewNearZatch
Browse files Browse the repository at this point in the history
fix: 좋아요/좋아요 취소 API 및 관련 응답 수정 #52
  • Loading branch information
plum-king authored May 15, 2023
2 parents 77dec84 + 56e2372 commit f3e9b73
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,25 @@ public void makeNewZatch(@RequestBody PostZatchReq postZatchReq) {
}

@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = PostZatchLikeRes.class,
@ApiResponse(code = 200, message = "Success", response = PostZatchLikeResDto.class,
examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
})
@PostMapping("/{zatchId}/likes")
@ApiOperation(value = "좋아요", notes = "좋아요")
public PostZatchLikeRes postZatchlike(HttpServletRequest request, @PathVariable("zatchId") Long zatchId) {
Long userId = (Long) request.getAttribute("userId");
Integer likeCount = postService.makeZatchLike(userId, zatchId);
return new PostZatchLikeRes(zatchId, likeCount);
public PostZatchLikeResDto postZatchlike(@PathVariable("zatchId") Long zatchId, @RequestBody PostZatchLikeReqDto postZatchLikeReqDto) {
Integer likeCount = postService.makeZatchLike(postZatchLikeReqDto.getUserId(), zatchId);
return new PostZatchLikeResDto(zatchId, likeCount, Boolean.TRUE); //좋아요 시, True 값
}

@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = PostZatchLikeRes.class,
@ApiResponse(code = 200, message = "Success", response = PostZatchLikeResDto.class,
examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE)))
})
@DeleteMapping("/{zatchId}/dislikes")
@ApiOperation(value = "좋아요 취소", notes = "좋아요 취소")
public PostZatchLikeRes postZatchDislike(HttpServletRequest request, @PathVariable("zatchId") Long zatchId) {
Long userId = (Long) request.getAttribute("userId");
Integer likeCount = postService.makeZatchDisLike(userId, zatchId);
return new PostZatchLikeRes(zatchId, likeCount);
public PostZatchLikeResDto postZatchDislike(@PathVariable("zatchId") Long zatchId, @RequestBody PostZatchLikeReqDto postZatchLikeReqDto) {
Integer likeCount = postService.makeZatchDisLike(postZatchLikeReqDto.getUserId(), zatchId);
return new PostZatchLikeResDto(zatchId, likeCount, Boolean.FALSE); //취소 시, False 값
}

@ApiResponses(value = {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/zatch/zatchserver/dto/PostZatchLikeReqDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.zatch.zatchserver.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class PostZatchLikeReqDto {
private Long userId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

@Getter
@AllArgsConstructor
public class PostZatchLikeRes {
public class PostZatchLikeResDto {
private Long zatchId;
private Integer likeCount;
private Boolean isLiked;
}

0 comments on commit f3e9b73

Please sign in to comment.