Spaces:
Sleeping
Sleeping
| package com.krishna.controller; | |
| import com.krishna.service.LikeService; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.web.bind.annotation.*; | |
| import java.util.UUID; | |
| public class LikeController { | |
| private LikeService likeService; | |
| public ResponseEntity<String> toggleLike( | |
| UUID userId, | |
| Long postId | |
| ) { | |
| boolean liked = likeService.toggleLike(userId, postId); | |
| return ResponseEntity.ok(liked ? "Post liked successfully" : "Post unliked"); | |
| } | |
| public Long getLikeCount( Long postId) { | |
| return likeService.getLikeCount(postId); | |
| } | |
| public ResponseEntity<Boolean> checkIfUserLikedPost( | |
| UUID userId, | |
| Long postId | |
| ) { | |
| boolean liked = likeService.hasUserLikedPost(userId, postId); | |
| return ResponseEntity.ok(liked); | |
| } | |
| } |