blob: 344b56ce811a166099ba3cd8e764d61c5f3201b3 [file] [log] [blame]
223011381c359102025-06-03 15:19:59 +08001package com.example.myproject.controller;
2
3import com.example.myproject.entity.SeedComment;
4import com.example.myproject.service.SeedCommentService;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.web.bind.annotation.*;
7
8import java.util.Map;
9
10@RestController
11@RequestMapping("/echo/seeds")
12public class SeedCommentController {
13
14 @Autowired
15 private SeedCommentService seedCommentService;
16
17 @PostMapping("/{seed_id}/comments")
18 public String publishComment(@PathVariable("seed_id") int seedId,
19 @RequestBody SeedComment seedComment) {
20 // 调用服务类的逻辑处理评论发布
21 return seedCommentService.publishComment(seedId, seedComment);
22 }
23
24 @GetMapping("/{seed_id}/getAllComments")
25 public Map<String, Object> getAllComments(@PathVariable("seed_id") int seedId) {
26 // 调用服务层获取所有评论数据
27 return seedCommentService.getAllCommentsForSeed(seedId);
28 }
29
30 // 点赞切换接口
31 @PutMapping("/{comment_id}/like-toggle")
32 public Map<String, Object> toggleLike(@PathVariable("comment_id") Long commentId,
33 @RequestBody Map<String, Object> request) {
34 Long userId = Long.parseLong(request.get("user_id").toString());
35 return seedCommentService.toggleLike(commentId, userId);
36 }
37
38
39}