Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 좋아요/좋아요 취소 API 및 관련 응답 수정 #52 #53

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}