From 3915e8147b916865d5fad05f014de32e340c32bc Mon Sep 17 00:00:00 2001 From: x ronger Date: Mon, 2 Dec 2019 09:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/api/admin/AdminController.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java diff --git a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java new file mode 100644 index 0000000..a575e96 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java @@ -0,0 +1,63 @@ +package com.rymcu.vertical.web.api.admin; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.rymcu.vertical.core.result.GlobalResult; +import com.rymcu.vertical.core.result.GlobalResultGenerator; +import com.rymcu.vertical.entity.Topic; +import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.service.TopicService; +import com.rymcu.vertical.service.UserService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author ronger + * */ +@RestController +@RequestMapping("/api/v1/admin") +public class AdminController { + + @Resource + private UserService userService; + @Resource + private TopicService topicService; + + @GetMapping("/users") + public GlobalResult users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + PageHelper.startPage(page, rows); + List list = userService.findAll(); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("users", pageInfo.getList()); + Map pagination = new HashMap(3); + pagination.put("pageSize",pageInfo.getPageSize()); + pagination.put("total",pageInfo.getTotal()); + pagination.put("currentPage",pageInfo.getPageNum()); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/topics") + public GlobalResult topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){ + PageHelper.startPage(page, rows); + List list = topicService.findAll(); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("topics", pageInfo.getList()); + Map pagination = new HashMap(3); + pagination.put("pageSize",pageInfo.getPageSize()); + pagination.put("total",pageInfo.getTotal()); + pagination.put("currentPage",pageInfo.getPageNum()); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + +}