46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package com.bao.dating.controller;
|
|
|
|
import com.bao.dating.common.Result;
|
|
import com.bao.dating.common.ResultCode;
|
|
import com.bao.dating.service.PostLikeService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/posts")
|
|
public class PostLikeController {
|
|
|
|
@Autowired
|
|
private PostLikeService postLikeService;
|
|
|
|
/**
|
|
* 点赞接口
|
|
* @param postId
|
|
* @param body
|
|
* @return
|
|
*/
|
|
@PostMapping("/{postId}/likes")
|
|
public Result<?> likePost(@PathVariable Long postId, @RequestBody Map<String, Long> body){
|
|
// 从请求体中取出 user_id
|
|
Long userId = body.get("user_id");
|
|
if (userId ==null){
|
|
return Result.error(ResultCode.PARAM_ERROR);
|
|
}
|
|
return postLikeService.likePost(postId,userId);
|
|
}
|
|
|
|
/**
|
|
* 取消点赞接口
|
|
* @param postId
|
|
* @param body
|
|
*/
|
|
@DeleteMapping("/{postId}/likes")
|
|
public void unlike(@PathVariable Long postId, @RequestBody Map<String, Long> body){
|
|
// 从请求体中获取 user_id
|
|
Long userId = body.get("user_id");
|
|
postLikeService.unlike(postId,userId);
|
|
}
|
|
}
|