|
@@ -1,6 +1,5 @@
|
|
package com.example.onlinejudge.controller;
|
|
package com.example.onlinejudge.controller;
|
|
|
|
|
|
-import com.alibaba.druid.wall.violation.ErrorCode;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
|
import com.example.onlinejudge.common.DeleteRequest;
|
|
import com.example.onlinejudge.common.DeleteRequest;
|
|
@@ -10,11 +9,12 @@ import com.example.onlinejudge.exception.BusinessException;
|
|
import com.example.onlinejudge.model.VO.QuestionVO;
|
|
import com.example.onlinejudge.model.VO.QuestionVO;
|
|
import com.example.onlinejudge.model.dto.question.*;
|
|
import com.example.onlinejudge.model.dto.question.*;
|
|
import com.example.onlinejudge.model.entity.Question;
|
|
import com.example.onlinejudge.model.entity.Question;
|
|
-import com.example.onlinejudge.model.entity.result.Result;
|
|
|
|
-import com.example.onlinejudge.model.entity.result.ResultCode;
|
|
|
|
|
|
+import com.example.onlinejudge.common.result.Result;
|
|
|
|
+import com.example.onlinejudge.common.result.ResultCode;
|
|
import com.example.onlinejudge.service.QuestionService;
|
|
import com.example.onlinejudge.service.QuestionService;
|
|
import com.example.onlinejudge.service.UserService;
|
|
import com.example.onlinejudge.service.UserService;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -24,8 +24,10 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+@Api(tags = "对题目进行增删改查")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/question")
|
|
@RequestMapping("/question")
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -41,15 +43,8 @@ public class QuestionController {
|
|
|
|
|
|
// region 增删改查
|
|
// region 增删改查
|
|
|
|
|
|
- /**
|
|
|
|
- * 创建题目
|
|
|
|
- *
|
|
|
|
- * @param questionAddRequest
|
|
|
|
- * @param request
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
- public Result<Long> addQuestion(@RequestBody QuestionAddRequest questionAddRequest, HttpServletRequest request) {
|
|
|
|
|
|
+ public Result<Long> addQuestion(@RequestBody QuestionAddRequest questionAddRequest) {
|
|
if (questionAddRequest == null) {
|
|
if (questionAddRequest == null) {
|
|
return Result.error(ResultCode.PARAM_IS_BLANK);
|
|
return Result.error(ResultCode.PARAM_IS_BLANK);
|
|
}
|
|
}
|
|
@@ -68,9 +63,10 @@ public class QuestionController {
|
|
question.setJudgeConfig(GSON.toJson(judgeConfig));
|
|
question.setJudgeConfig(GSON.toJson(judgeConfig));
|
|
}
|
|
}
|
|
questionService.validQuestion(question, true);
|
|
questionService.validQuestion(question, true);
|
|
- //TODO:记录谁创建了这个题目 Done
|
|
|
|
Long loginUserId = userService.getLoginUserId();
|
|
Long loginUserId = userService.getLoginUserId();
|
|
question.setUserId(loginUserId);
|
|
question.setUserId(loginUserId);
|
|
|
|
+ question.setUpdateTime(new Date());
|
|
|
|
+ question.setCreateTime(new Date());
|
|
boolean result = questionService.save(question);
|
|
boolean result = questionService.save(question);
|
|
if(!result){
|
|
if(!result){
|
|
return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
@@ -80,15 +76,9 @@ public class QuestionController {
|
|
return Result.success(newQuestionId);
|
|
return Result.success(newQuestionId);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 删除
|
|
|
|
- *
|
|
|
|
- * @param deleteRequest
|
|
|
|
- * @param request
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
|
|
+
|
|
@PostMapping("/delete")
|
|
@PostMapping("/delete")
|
|
- public Result<Boolean> deleteQuestion(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
|
|
|
|
|
|
+ public Result<Boolean> deleteQuestion(@RequestBody DeleteRequest deleteRequest) {
|
|
if (deleteRequest == null || deleteRequest.getId() <= 0) {
|
|
if (deleteRequest == null || deleteRequest.getId() <= 0) {
|
|
return Result.error(ResultCode.PARAM_IS_BLANK);
|
|
return Result.error(ResultCode.PARAM_IS_BLANK);
|
|
}
|
|
}
|
|
@@ -98,9 +88,7 @@ public class QuestionController {
|
|
if(oldQuestion == null){
|
|
if(oldQuestion == null){
|
|
return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
}
|
|
}
|
|
- //ThrowUtils.throwIf(oldQuestion == null, ErrorCode.NOT_FOUND_ERROR);
|
|
|
|
- // 仅本人或管理员可删除
|
|
|
|
- //TODO:判断是否是管理员 DONE
|
|
|
|
|
|
+
|
|
if (userService.isAdmin(userService.getLoginUserId())) {
|
|
if (userService.isAdmin(userService.getLoginUserId())) {
|
|
return Result.error(ResultCode.PERMISSION_DENIED);
|
|
return Result.error(ResultCode.PERMISSION_DENIED);
|
|
}
|
|
}
|
|
@@ -135,9 +123,6 @@ public class QuestionController {
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "根据id获取题目(封装类)")
|
|
@ApiOperation(value = "根据id获取题目(封装类)")
|
|
- @ApiImplicitParams({
|
|
|
|
- @ApiImplicitParam(name = "id", value = "题目id", required = true, dataType = "long"),
|
|
|
|
- })
|
|
|
|
@GetMapping("/get/vo")
|
|
@GetMapping("/get/vo")
|
|
public Result<QuestionVO> getQuestionVOById(long id, HttpServletRequest request) {
|
|
public Result<QuestionVO> getQuestionVOById(long id, HttpServletRequest request) {
|
|
if (id <= 0) {
|
|
if (id <= 0) {
|
|
@@ -152,9 +137,6 @@ public class QuestionController {
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "分页获取题目列表(封装类)")
|
|
@ApiOperation(value = "分页获取题目列表(封装类)")
|
|
- @ApiImplicitParams(
|
|
|
|
- @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
|
|
|
|
- )
|
|
|
|
@PostMapping("/list/page/vo")
|
|
@PostMapping("/list/page/vo")
|
|
public Result<Page<QuestionVO>> listQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
public Result<Page<QuestionVO>> listQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
HttpServletRequest request) {
|
|
HttpServletRequest request) {
|
|
@@ -171,9 +153,6 @@ public class QuestionController {
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "分页获取当前用户创建的题目列表(封装类)")
|
|
@ApiOperation(value = "分页获取当前用户创建的题目列表(封装类)")
|
|
- @ApiImplicitParams(
|
|
|
|
- @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
|
|
|
|
- )
|
|
|
|
@PostMapping("/my/list/page/vo")
|
|
@PostMapping("/my/list/page/vo")
|
|
public Result<Page<QuestionVO>> listMyQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
public Result<Page<QuestionVO>> listMyQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
HttpServletRequest request) {
|
|
HttpServletRequest request) {
|
|
@@ -194,9 +173,6 @@ public class QuestionController {
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "分页获取题目列表(仅管理员)")
|
|
@ApiOperation(value = "分页获取题目列表(仅管理员)")
|
|
- @ApiImplicitParams(
|
|
|
|
- @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
|
|
|
|
- )
|
|
|
|
@PostMapping("/list/page")
|
|
@PostMapping("/list/page")
|
|
public Result<Page<Question>> listQuestionByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
public Result<Page<Question>> listQuestionByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
|
|
HttpServletRequest request) {
|
|
HttpServletRequest request) {
|