blob: 344b56ce811a166099ba3cd8e764d61c5f3201b3 [file] [log] [blame]
package com.example.myproject.controller;
import com.example.myproject.entity.SeedComment;
import com.example.myproject.service.SeedCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/echo/seeds")
public class SeedCommentController {
@Autowired
private SeedCommentService seedCommentService;
@PostMapping("/{seed_id}/comments")
public String publishComment(@PathVariable("seed_id") int seedId,
@RequestBody SeedComment seedComment) {
// 调用服务类的逻辑处理评论发布
return seedCommentService.publishComment(seedId, seedComment);
}
@GetMapping("/{seed_id}/getAllComments")
public Map<String, Object> getAllComments(@PathVariable("seed_id") int seedId) {
// 调用服务层获取所有评论数据
return seedCommentService.getAllCommentsForSeed(seedId);
}
// 点赞切换接口
@PutMapping("/{comment_id}/like-toggle")
public Map<String, Object> toggleLike(@PathVariable("comment_id") Long commentId,
@RequestBody Map<String, Object> request) {
Long userId = Long.parseLong(request.get("user_id").toString());
return seedCommentService.toggleLike(commentId, userId);
}
}