[xingyu.guo] feat: 1. 抽取通用url 2. 完成【通过学习任务num获取该任务的未结束会话】API 3. 优化【通过sessionNum获取一个【学习会话】】API名称
This commit is contained in:
+1
-1
@@ -36,7 +36,7 @@ public class StudySessionController {
|
|||||||
* 通过sessionNum获取一个【学习会话】
|
* 通过sessionNum获取一个【学习会话】
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{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)
|
StudySessionsEntity studySessionsEntity = studySessionsServiceImpl.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.guo.learningprogresstracker.common.Ops;
|
|||||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||||
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
import com.guo.learningprogresstracker.service.TasksService;
|
import com.guo.learningprogresstracker.service.TasksService;
|
||||||
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
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.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ import java.rmi.ServerException;
|
|||||||
* 任务控制层
|
* 任务控制层
|
||||||
* @author guo
|
* @author guo
|
||||||
*/
|
*/
|
||||||
|
@RequestMapping("/tasks")
|
||||||
@RestController
|
@RestController
|
||||||
@Validated
|
@Validated
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -36,7 +39,7 @@ public class TaskController {
|
|||||||
|
|
||||||
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
||||||
|
|
||||||
@PostMapping("/tasks")
|
@PostMapping
|
||||||
@Operation(summary = "添加新任务")
|
@Operation(summary = "添加新任务")
|
||||||
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) {
|
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) {
|
||||||
System.out.println("Token: " + StpUtil.getTokenValue());
|
System.out.println("Token: " + StpUtil.getTokenValue());
|
||||||
@@ -44,26 +47,26 @@ public class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "任务详情API-未完成")
|
@Operation(summary = "任务详情API-未完成")
|
||||||
@GetMapping("/tasks/{taskId}")
|
@GetMapping("/{taskId}")
|
||||||
public CommonResult getTask(@PathVariable("taskId") String taskId) {
|
public CommonResult getTask(@PathVariable("taskId") String taskId) {
|
||||||
return CommonResult.success(tasksService.getTask(taskId));
|
return CommonResult.success(tasksService.getTask(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/tasks/{taskId}")
|
@PutMapping("/{taskId}")
|
||||||
@Operation(summary = "更新任务详情")
|
@Operation(summary = "更新任务详情")
|
||||||
public CommonResult updateTask(@PathVariable("taskId") String taskId,@Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
|
public CommonResult updateTask(@PathVariable("taskId") String taskId,@Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
|
||||||
tasksService.updateTask(taskId, updatedTask);
|
tasksService.updateTask(taskId, updatedTask);
|
||||||
return CommonResult.success();
|
return CommonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/tasks/{taskId}")
|
@DeleteMapping("/{taskId}")
|
||||||
@Operation(summary = "删除指定任务")
|
@Operation(summary = "删除指定任务")
|
||||||
public CommonResult deleteTask(@PathVariable("taskId") String taskId) throws ServerException {
|
public CommonResult deleteTask(@PathVariable("taskId") String taskId) throws ServerException {
|
||||||
tasksService.deleteTask(taskId);
|
tasksService.deleteTask(taskId);
|
||||||
return CommonResult.success();
|
return CommonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tasks")
|
@GetMapping
|
||||||
@Operation(summary = "获取所有任务列表")
|
@Operation(summary = "获取所有任务列表")
|
||||||
public CommonResult tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
public CommonResult tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||||
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
@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不可为空")
|
public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
|
||||||
@PathVariable String taskNum) throws NotFindEntitiesException {
|
@PathVariable String taskNum) throws NotFindEntitiesException {
|
||||||
StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
|
StudySessionResponce response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
|
||||||
return CommonResult.success(responce);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.guo.learningprogresstracker.service;
|
package com.guo.learningprogresstracker.service;
|
||||||
|
|
||||||
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author guo
|
* @author guo
|
||||||
@@ -10,4 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
*/
|
*/
|
||||||
public interface StudySessionsService extends IService<StudySessionsEntity> {
|
public interface StudySessionsService extends IService<StudySessionsEntity> {
|
||||||
|
|
||||||
|
StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -61,6 +61,15 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
studySessionsEntity.pausedStudySession();
|
studySessionsEntity.pausedStudySession();
|
||||||
this.updateById(studySessionsEntity);
|
this.updateById(studySessionsEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StudySessionResponce getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
|
||||||
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
|
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||||
|
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()))
|
||||||
|
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话"));
|
||||||
|
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user