mjh 4 лет назад
Родитель
Сommit
3dbebb4e77

+ 15 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/Impl/CoderService.java

@@ -56,4 +56,19 @@ public class CoderService implements SubsystemService {
         }
         System.out.println(result);
     }
+
+    public JSONObject getAllExams(int page, int limit){
+        String uri = "https://coder-server.seec.seecoder.cn/api/exam";
+        String token = httpService.getToken();
+        List<NameValuePair> params = new ArrayList<>();
+        params.add(new BasicNameValuePair("page", String.valueOf(page)));
+        params.add(new BasicNameValuePair("limit", String.valueOf(limit)));
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, params, token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSON.parseObject(result);
+    }
 }

+ 22 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/CoderController.java

@@ -0,0 +1,22 @@
+package cn.seecoder.seecoderportalserver.web.rest;
+
+import cn.seecoder.seecoderportalserver.service.Impl.CoderService;
+import cn.seecoder.seecoderportalserver.utility.OkResponse;
+import com.alibaba.fastjson.JSONObject;
+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;
+
+@RestController
+@RequestMapping("/api/coder")
+public class CoderController {
+    private final CoderService coderService;
+
+    public CoderController(CoderService coderService) {this.coderService = coderService;}
+
+    @GetMapping("/exams")
+    public OkResponse<JSONObject> getAllExams(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit){
+        return OkResponse.of(coderService.getAllExams(page, limit));
+    }
+}

+ 4 - 3
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/EvalController.java

@@ -5,6 +5,7 @@ import cn.seecoder.seecoderportalserver.utility.OkResponse;
 import com.alibaba.fastjson.JSONObject;
 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;
 
 @RestController
@@ -14,8 +15,8 @@ public class EvalController {
 
     public EvalController(EvalService evalService) {this.evalService = evalService;}
 
-    @GetMapping
-    public OkResponse<JSONObject> getAllExams() {
-        return OkResponse.of((JSONObject) evalService.getAllExams(100, 1).get("result"));
+    @GetMapping("/exams")
+    public OkResponse<JSONObject> getAllExams(@RequestParam(defaultValue = "100") int pageSize, @RequestParam(defaultValue = "1") int pageNum) {
+        return OkResponse.of((JSONObject) evalService.getAllExams(pageSize, pageNum).get("result"));
     }
 }