Ver Fonte

完成提交题解时获取用户ID

westt há 1 ano atrás
pai
commit
38d904c242

+ 5 - 5
src/main/java/com/example/onlinejudge/controller/QuestionSubmitController.java

@@ -1,6 +1,7 @@
 package com.example.onlinejudge.controller;
 
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 import com.example.onlinejudge.model.VO.QuestionSubmitVO;
@@ -51,11 +52,10 @@ public class QuestionSubmitController {
         if (questionSubmitAddRequest == null || questionSubmitAddRequest.getQuestionId() <= 0) {
             return new Result(ResultCode.PARAM_IS_INVALID.getCode(),ResultCode.PARAM_IS_INVALID.getMessage());
         }
-        // TODO: 获取登录id
-//        final User loginUser = userService.getLoginUser(request);
-//        long questionSubmitId = questionSubmitService.doQuestionSubmit(questionSubmitAddRequest, loginUser);
-//        return Result.success(questionSubmitId);
-        return null;
+        // TODO: 获取登录id DONE
+        long logInId = StpUtil.getLoginIdAsLong();
+        long questionSubmitId = questionSubmitService.doQuestionSubmit(questionSubmitAddRequest, logInId);
+        return Result.success(questionSubmitId);
     }
 
     /**

+ 2 - 2
src/main/java/com/example/onlinejudge/service/QuestionSubmitService.java

@@ -16,10 +16,10 @@ public interface QuestionSubmitService extends IService<QuestionSubmit> {
      * 题目提交
      *
      * @param questionSubmitAddRequest 题目提交信息
-     * @param loginUser
+     * @param loginUserId
      * @return
      */
-    long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, User loginUser);
+    long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, Long loginUserId);
 
     /**
      * 获取查询条件

+ 3 - 3
src/main/java/com/example/onlinejudge/service/impl/QuestionSubmitServiceImpl.java

@@ -52,7 +52,7 @@ public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper,
      * @return
      */
     @Override
-    public long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, User loginUser) {
+    public long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, Long loginUserId) {
         // 校验编程语言是否合法
         String language = questionSubmitAddRequest.getLanguage();
         QuestionSubmitLanguageEnum languageEnum = QuestionSubmitLanguageEnum.getEnumByValue(language);
@@ -66,10 +66,10 @@ public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper,
             throw new BusinessException(ResultCode.NOT_FOUND_ERROR);
         }
         // 是否已提交题目
-        long userId = loginUser.getId();
+
         // 每个用户串行提交题目
         QuestionSubmit questionSubmit = new QuestionSubmit();
-        questionSubmit.setUserId(userId);
+        questionSubmit.setUserId(loginUserId);
         questionSubmit.setQuestionId(questionId);
         questionSubmit.setCode(questionSubmitAddRequest.getCode());
         questionSubmit.setLanguage(language);