1. 开始或继续一个【学习会话】API 2. 暂停一个【学习会话】API 3.通过sessionId获取一个【学习会话】API
This commit is contained in:
@@ -1,9 +1,54 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
|
||||
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 学习会话控制层
|
||||
*/
|
||||
@RequestMapping("/study-sessions")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class StudySessionController {
|
||||
|
||||
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
||||
|
||||
@PostMapping
|
||||
public void studySessionList() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过sessionId获取一个【学习会话】
|
||||
*/
|
||||
@GetMapping("/{sessionId}")
|
||||
public CommonResult getStudySession(@NotEmpty(message = "sessionId不可为空") @PathVariable String sessionId) throws ErrorParameterException {
|
||||
StudySessionsEntity studySessionsEntity = studySessionsServiceImpl.getOptById(sessionId)
|
||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionId + "]不存在"));
|
||||
StudySessionResponce studySessionResponce = StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
||||
return CommonResult.success(studySessionResponce);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停一个【学习会话】
|
||||
*/
|
||||
@PostMapping("/{taskId}/studay-sessions/pause")
|
||||
public CommonResult pauseStudySession(@PathVariable("sessionId") String sessionId) throws ErrorParameterException {
|
||||
studySessionsServiceImpl.pauseStudySession(sessionId);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
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.service.TasksService;
|
||||
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -29,6 +32,8 @@ public class TaskController {
|
||||
|
||||
private final TasksService tasksService;
|
||||
|
||||
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
||||
|
||||
@PostMapping("/tasks")
|
||||
@Operation(summary = "添加新任务")
|
||||
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) {
|
||||
@@ -61,4 +66,17 @@ public class TaskController {
|
||||
public CommonResult tasksList() {
|
||||
return CommonResult.success(tasksService.taskList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始或继续一个【学习会话】
|
||||
*
|
||||
*/
|
||||
@GetMapping("/{taskId}/studay-sessions/start-or-continue")
|
||||
public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskId不可为空")
|
||||
@PathVariable String taskId) {
|
||||
StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskId);
|
||||
return CommonResult.success(responce);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user