blob: 7c47e1b644e9022cb9301ed892e72dc74edd6de8 [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);
40 if (bounty == null) {
41 return ResponseEntity.notFound().build();
42 } else {
43 return ResponseEntity.ok(bounty);
44 }
45 }
46 // 新增:发布悬赏接口
47 @PostMapping("/publish")
48 public boolean publishBounty(@RequestBody Bounty bounty) {
49 return bountyService.publishBounty(bounty);
50 }
51}
52