소스 검색

MOD: modify client api parameters

Zicong Liu 8 년 전
부모
커밋
d2eb307d45

+ 2 - 2
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/application/ApiService.java

@@ -64,7 +64,7 @@ public interface ApiService {
 
     String getWorkersJson(List<Worker> worker);
 
-    String loginClient(String workerStr);
+    String loginClient(Long taskId, Long workerId);
 
-    String getCaseList(String workerStr);
+    String getCaseList(Long taskId, Long workerId);
 }

+ 3 - 33
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/application/impl/ApiServiceImpl.java

@@ -668,28 +668,12 @@ public class ApiServiceImpl implements ApiService {
     }
 
     @Override
-    public String loginClient(String workerStr) {
-        Long taskId = null, workerId;
+    public String loginClient(Long taskId, Long workerId) {
+
         AssignedTask assignedTask = null;
         // decrypt workerStr to get taskId and classMemId
         JSONObject jsonObject = new JSONObject();
 
-        try {
-
-            String decryptedStr = EncryptionUtil.decryptDES(workerStr.trim());
-            String[] infos = decryptedStr.split("_");
-            taskId = Long.valueOf(infos[0]);
-            workerId = Long.valueOf(infos[1]);
-
-        } catch (Exception e) {
-            jsonObject.put("login_success", 0);
-            jsonObject.put("task_time_status", 0);
-            jsonObject.put("task_name", "");
-            jsonObject.put("task_begin_time", "");
-            jsonObject.put("task_end_time", "");
-            jsonObject.put("task_error_message", "考试密码错误(是否多输入了空格?)");
-            return jsonObject.toString();
-        }
         boolean taskFound = false;
 
         try {
@@ -784,21 +768,7 @@ public class ApiServiceImpl implements ApiService {
     }
 
     @Override
-    public String getCaseList(String workerStr) {
-        // decrypt workerStr to get taskId and classMemId
-        String decryptedStr = null;
-        try {
-            decryptedStr = EncryptionUtil.decryptDES(workerStr.trim());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        if (decryptedStr == null){
-            return "{message: \"Decryption Error!\"}";
-        }
-        String[] infos = decryptedStr.trim().split("_");
-        long taskId = Long.valueOf(infos[0]);
-        long workerId = Long.valueOf(infos[1]);
-
+    public String getCaseList(Long taskId, Long workerId) {
         List<AssignedTask> assignedTasks = assignedTaskDao.findByTaskIdAndWorkerId(taskId, workerId);
         if (assignedTasks == null || assignedTasks.size() == 0){
             return "{message: \"No such AssignedTask\"}";

+ 9 - 6
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/ApiLogicImpl.java

@@ -350,13 +350,15 @@ public class ApiLogicImpl implements ApiLogic {
 
     @Override
     public String getCaseList(HttpServletRequest request) {
-        if (request.getParameter("workerStr") == null){
+        if (request.getParameter("taskId") == null || request.getParameter("workerId") == null){
             return missingParameterResponse;
         }
-        String workerStr = request.getParameter("workerStr");
+        Long taskId = Long.parseLong(request.getParameter("taskId"));
+        Long workerId = Long.parseLong(request.getParameter("workerId"));
+
 
         // get download json
-        String caseResult = apiService.getCaseList(workerStr);
+        String caseResult = apiService.getCaseList(taskId, workerId);
 
         String result = generateResponse(HTTP_OK, "", caseResult);
 
@@ -365,13 +367,14 @@ public class ApiLogicImpl implements ApiLogic {
 
     @Override
     public String login(HttpServletRequest request) {
-        if (request.getParameter("workerStr") == null){
+        if (request.getParameter("taskId") == null || request.getParameter("workerId") == null){
             return missingParameterResponse;
         }
-        String workerStr = request.getParameter("workerStr");
+        Long taskId = Long.parseLong(request.getParameter("taskId"));
+        Long workerId = Long.parseLong(request.getParameter("workerId"));
 
         // login the system
-        String loginResult = apiService.loginClient(workerStr);
+        String loginResult = apiService.loginClient(taskId, workerId);
 
         String result = generateResponse(HTTP_OK, "", loginResult);