-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathLikeController.java
More file actions
29 lines (24 loc) · 1 KB
/
LikeController.java
File metadata and controls
29 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.example.devSns.controller;
import com.example.devSns.dto.LikeResponse;
import com.example.devSns.dto.LikeToggleRequest;
import com.example.devSns.service.LikeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@RequestMapping("/likes")
public class LikeController {
private final LikeService LikeService;
@PostMapping("/toggle")
public ResponseEntity<LikeResponse> toggleLike(@RequestBody LikeToggleRequest request){
LikeService.toggleLike(request.getMemberId(), request.getPostId());
long count = LikeService.getLikeCount(request.getPostId());
return ResponseEntity.ok(new LikeResponse(request.getPostId(),count,true));
}
@GetMapping("/count/{postId}")
public ResponseEntity<Long> getLikeCount(@PathVariable Long postId){
long count = LikeService.getLikeCount(postId);
return ResponseEntity.ok(count);
}
}