崔向南 | 03d21b9 | 2025-06-05 17:42:23 +0800 | [diff] [blame] | 1 | package bounty.controller; |
| 2 | |
| 3 | import bounty.domain.Bounty; |
| 4 | import bounty.domain.BountySubmission; |
| 5 | import bounty.service.BountyService; |
| 6 | import bounty.service.BountySubmissionService; |
| 7 | import com.baomidou.mybatisplus.core.metadata.IPage; |
| 8 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.http.HttpStatus; |
| 11 | import org.springframework.http.ResponseEntity; |
| 12 | import org.springframework.web.bind.annotation.*; |
| 13 | import java.util.List; |
| 14 | |
| 15 | // 悬赏 Controller 类 |
| 16 | @RestController |
| 17 | @RequestMapping("/bounties") |
| 18 | public 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); |
zhaoyumao | 9eb3e05 | 2025-06-08 00:26:32 +0800 | [diff] [blame] | 40 | System.out.println(bounty); |
崔向南 | 03d21b9 | 2025-06-05 17:42:23 +0800 | [diff] [blame] | 41 | 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 | |