前端控制器 @author 虎哥 @since 2021-12-22
| 24 | * @since 2021-12-22 |
| 25 | */ |
| 26 | @RestController |
| 27 | @RequestMapping("/blog") |
| 28 | public class BlogController { |
| 29 | |
| 30 | @Resource |
| 31 | private IBlogService blogService; |
| 32 | @Resource |
| 33 | private IUserService userService; |
| 34 | |
| 35 | @PostMapping |
| 36 | public Result saveBlog(@RequestBody Blog blog) { |
| 37 | return blogService.saveBlog(blog); |
| 38 | } |
| 39 | |
| 40 | @PutMapping("/like/{id}") |
| 41 | public Result likeBlog(@PathVariable("id") Long id) { |
| 42 | // 修改点赞数量 |
| 43 | return blogService.updateLike(id); |
| 44 | } |
| 45 | |
| 46 | @GetMapping("/of/me") |
| 47 | public Result queryMyBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) { |
| 48 | // 获取登录用户 |
| 49 | UserDTO user = UserHolder.getUser(); |
| 50 | // 根据用户查询 |
| 51 | Page<Blog> page = blogService.query() |
| 52 | .eq("user_id", user.getId()).page(new Page<>(current, SystemConstants.MAX_PAGE_SIZE)); |
| 53 | // 获取当前页数据 |
| 54 | List<Blog> records = page.getRecords(); |
| 55 | return Result.ok(records); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * 分页查询 |
| 60 | * @param current |
| 61 | * @return |
| 62 | */ |
| 63 | @GetMapping("/hot") |
| 64 | public Result queryHotBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) { |
| 65 | return blogService.queryHotBlog(current); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * 根据id查询 |
| 70 | * @param id |
| 71 | * @return |
| 72 | */ |
| 73 | @GetMapping("/{id}") |
| 74 | public Result queryById(@PathVariable("id") Long id){ |
| 75 | return blogService.queryBlogById(id); |
| 76 | } |
| 77 | |
| 78 | @GetMapping("/likes/{id}") |
| 79 | public Result queryBlogLikes(@PathVariable("id") Long id){ |
| 80 | return blogService.queryBlogLikes(id); |
| 81 | } |
| 82 | |
| 83 | @GetMapping("/of/user") |
nothing calls this directly
no outgoing calls
no test coverage detected