feat:1.优化commonResult 2. 重新初始化数据库结构

This commit is contained in:
2025-06-29 15:30:40 +08:00
parent 794a54c738
commit aa9a278108
10 changed files with 64 additions and 59 deletions
@@ -26,7 +26,7 @@ public class LoginController {
@Operation(summary = "登录API")
@PostMapping("/login")
public CommonResult<Object> login(@RequestBody LoginBody loginBody) throws AppException {
public CommonResult<String> login(@RequestBody LoginBody loginBody) throws AppException {
String userId = userServiceImpl.authenticate(loginBody.getUsername(), loginBody.getPassword());
String token = loginService.login(userId);
//todo 参数传递未加密
@@ -35,7 +35,7 @@ public class LoginController {
@Operation(summary = "退出登录API-功能未完成")
@PostMapping("/loingOut")
public CommonResult loingOut(@RequestBody LoginBody loginBody) throws AppException {
public CommonResult<Void> loingOut(@RequestBody LoginBody loginBody) throws AppException {
//todo loginOut 退出登录API
// loginService.loginOut();
return CommonResult.success("已登出");
@@ -41,7 +41,7 @@ public class StudySessionController {
* 通过sessionNum获取一个【学习会话】
*/
@GetMapping("/{sessionNum}")
public CommonResult getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
public CommonResult<StudySessionResponce> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = studySessionsServiceImpl.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
@@ -53,7 +53,7 @@ public class StudySessionController {
* 暂停一个【学习会话】
*/
@PostMapping("/{sessionNum}/study-sessions/pause")
public CommonResult pauseStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
public CommonResult<Void> pauseStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
studySessionsServiceImpl.pauseStudySession(sessionNum);
return CommonResult.success();
}
@@ -62,16 +62,17 @@ public class StudySessionController {
* 结束一个【学习会话】
*/
@PostMapping("/{sessionNum}/study-sessions/ended")
public CommonResult endedStudySession(@PathVariable("sessionNum") String sessionNum,
@Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException {
studySessionsServiceImpl.endedStudySession(sessionNum,request.getContent());
public CommonResult<Void> endedStudySession(@PathVariable("sessionNum") String sessionNum,
@Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException {
studySessionsServiceImpl.endedStudySession(sessionNum, request.getContent());
return CommonResult.success();
}
/**
* 获取【学习会话】所有的学习残片数据,以列表返回
*/
@GetMapping("/{sessionNum}/all-fragments")
public CommonResult getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
public CommonResult<ArrayList<String>> getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
return CommonResult.success(allFragments);
@@ -1,8 +1,11 @@
package com.guo.learningprogresstracker.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guo.learningprogresstracker.common.Ops;
import com.guo.learningprogresstracker.dto.TaskInfo;
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.dto.request.TaskRequest;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
@@ -27,6 +30,7 @@ import java.rmi.ServerException;
/**
* 任务控制层
*
* @author guo
*/
@RequestMapping("/tasks")
@@ -41,44 +45,43 @@ public class TaskController {
@PostMapping
@Operation(summary = "添加新任务")
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) throws ErrorParameterException {
public CommonResult<String> addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) throws ErrorParameterException {
return CommonResult.success(tasksService.addTask(taskRequest));
}
@Operation(summary = "任务详情API")
@GetMapping("/{taskId}")
public CommonResult getTask(@PathVariable("taskId") String taskId) {
public CommonResult<TaskInfoResponse> getTask(@PathVariable("taskId") String taskId) {
return CommonResult.success(tasksService.getTask(taskId));
}
@PutMapping("/{taskId}")
@Operation(summary = "更新任务详情")
public CommonResult updateTask(@PathVariable("taskId") String taskId,@Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
public CommonResult<Void> updateTask(@PathVariable("taskId") String taskId, @Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
tasksService.updateTask(taskId, updatedTask);
return CommonResult.success();
}
@DeleteMapping("/{taskId}")
@Operation(summary = "删除指定任务")
public CommonResult deleteTask(@PathVariable("taskId") String taskId) throws ServerException {
public CommonResult<Void> deleteTask(@PathVariable("taskId") String taskId) throws ServerException {
tasksService.deleteTask(taskId);
return CommonResult.success();
}
@GetMapping
@Operation(summary = "获取所有任务列表")
public CommonResult tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
public CommonResult<Page<TaskInfo>> tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
return CommonResult.success(tasksService.taskList(pageNum, pageSize));
}
/**
* 开始或继续一个【学习会话】
*
*/
@GetMapping("/{taskNum}/study-sessions/start-or-continue")
public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws NotFindEntitiesException {
public CommonResult<StudySessionResponce> startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws NotFindEntitiesException {
StudySessionResponce response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
return CommonResult.success(response);
@@ -88,8 +91,8 @@ public class TaskController {
* 通过学习任务num获取该任务的未结束会话
*/
@GetMapping("/{taskNum}/not-ended-study-session")
public CommonResult getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws ErrorParameterException {
public CommonResult<StudySessionResponce> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空")
@PathVariable String taskNum) throws ErrorParameterException {
StudySessionResponce response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
return CommonResult.success(response);
}
@@ -28,7 +28,7 @@ public class reportFragmentsController {
* @return
*/
@PostMapping
public CommonResult createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException {
public CommonResult<Void> createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.createFragments(request);
return CommonResult.success();
}