diff --git a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java index d762513..009c2de 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/StudySessionController.java @@ -36,7 +36,7 @@ public class StudySessionController { * 通过sessionNum获取一个【学习会话】 */ @GetMapping("/{sessionNum}") - public CommonResult getStudySession(@NotEmpty(message = "sessionId不可为空") @PathVariable String sessionNum) throws ErrorParameterException { + public CommonResult 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 + "]不存在")); diff --git a/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java b/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java index 0bd74d8..caf510e 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/TaskController.java @@ -5,6 +5,7 @@ import com.guo.learningprogresstracker.common.Ops; import com.guo.learningprogresstracker.dto.response.StudySessionResponce; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.dto.request.TaskRequest; +import com.guo.learningprogresstracker.exception.ErrorParameterException; import com.guo.learningprogresstracker.exception.NotFindEntitiesException; import com.guo.learningprogresstracker.service.TasksService; import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl; @@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -27,6 +29,7 @@ import java.rmi.ServerException; * 任务控制层 * @author guo */ +@RequestMapping("/tasks") @RestController @Validated @RequiredArgsConstructor @@ -36,7 +39,7 @@ public class TaskController { private final StudySessionsServiceImpl studySessionsServiceImpl; - @PostMapping("/tasks") + @PostMapping @Operation(summary = "添加新任务") public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) { System.out.println("Token: " + StpUtil.getTokenValue()); @@ -44,26 +47,26 @@ public class TaskController { } @Operation(summary = "任务详情API-未完成") - @GetMapping("/tasks/{taskId}") + @GetMapping("/{taskId}") public CommonResult getTask(@PathVariable("taskId") String taskId) { return CommonResult.success(tasksService.getTask(taskId)); } - @PutMapping("/tasks/{taskId}") + @PutMapping("/{taskId}") @Operation(summary = "更新任务详情") public CommonResult updateTask(@PathVariable("taskId") String taskId,@Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) { tasksService.updateTask(taskId, updatedTask); return CommonResult.success(); } - @DeleteMapping("/tasks/{taskId}") + @DeleteMapping("/{taskId}") @Operation(summary = "删除指定任务") public CommonResult deleteTask(@PathVariable("taskId") String taskId) throws ServerException { tasksService.deleteTask(taskId); return CommonResult.success(); } - @GetMapping("/tasks") + @GetMapping @Operation(summary = "获取所有任务列表") public CommonResult tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { @@ -74,12 +77,21 @@ public class TaskController { * 开始或继续一个【学习会话】 * */ - @GetMapping("/{taskNum}/studay-sessions/start-or-continue") + @GetMapping("/{taskNum}/study-sessions/start-or-continue") public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空") @PathVariable String taskNum) throws NotFindEntitiesException { - StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskNum); - return CommonResult.success(responce); + StudySessionResponce response = studySessionsServiceImpl.startOrContinueStudySession(taskNum); + return CommonResult.success(response); } + /** + * 通过学习任务num获取该任务的未结束会话 + */ + @GetMapping("/{taskNum}/not-ended-study-session") + public CommonResult getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空") + @PathVariable String taskNum) throws ErrorParameterException { + StudySessionResponce response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum); + return CommonResult.success(response); + } } diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java index 1cb3af0..8dbcaf3 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudySessionsService.java @@ -1,7 +1,9 @@ package com.guo.learningprogresstracker.service; +import com.guo.learningprogresstracker.dto.response.StudySessionResponce; import com.guo.learningprogresstracker.entity.StudySessionsEntity; import com.baomidou.mybatisplus.extension.service.IService; +import com.guo.learningprogresstracker.exception.ErrorParameterException; /** * @author guo @@ -10,4 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface StudySessionsService extends IService { + StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException; } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java index e696f27..9273d4f 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudySessionsServiceImpl.java @@ -61,6 +61,15 @@ public class StudySessionsServiceImpl extends ServiceImpl new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话")); + return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity); + } }