blob: 333887f57516c16953ddb05a4c2fa4daa7fd1e1f [file] [log] [blame]
崔向南03d21b92025-06-05 17:42:23 +08001package bounty.controller;
2
3import bounty.domain.Bounty;
4import bounty.domain.BountySubmission;
5import bounty.service.BountyService;
6import bounty.service.BountySubmissionService;
7import com.baomidou.mybatisplus.core.metadata.IPage;
8import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
9import org.springframework.beans.factory.annotation.Autowired;
10import org.springframework.http.HttpStatus;
11import org.springframework.http.ResponseEntity;
12import org.springframework.web.bind.annotation.*;
13import java.util.List;
14
15// 悬赏 Controller 类
16@RestController
17@RequestMapping("/bounties")
18public class BountyController {
19 @Autowired
20 private BountyService bountyService;
21
22 @PostMapping
23 public ResponseEntity<?> saveBounty(@RequestBody Bounty bounty) {
24 boolean result = bountyService.saveBounty(bounty);
25 if (result) {
26 return ResponseEntity.ok().build();
27 } else {
28 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
29 }
30 }
31 @GetMapping
32 // 导入 List 类
33 public List<Bounty> getBounties() { // 移除分页参数,返回 List 而非 IPage
34 return bountyService.getBounties(); // 调用无分页的 Service 方法
35 }
36
37 @GetMapping("/{id}")
38 public ResponseEntity<Bounty> getBountyById(@PathVariable Long id) {
39 Bounty bounty = bountyService.getBountyById(id);
zhaoyumao9eb3e052025-06-08 00:26:32 +080040 System.out.println(bounty);
崔向南03d21b92025-06-05 17:42:23 +080041 if (bounty == null) {
42 return ResponseEntity.notFound().build();
43 } else {
44 return ResponseEntity.ok(bounty);
45 }
46 }
47 // 新增:发布悬赏接口
48 @PostMapping("/publish")
49 public boolean publishBounty(@RequestBody Bounty bounty) {
50 return bountyService.publishBounty(bounty);
51 }
52}
53