a64daacc71
- StudySessionsServiceImpl: 检测 effectiveTime 被清零时返回提示消息 - StudySessionController: 将提示消息通过 CommonResult.success(message) 传给前端
84 lines
3.3 KiB
Java
84 lines
3.3 KiB
Java
package com.guo.learningprogresstracker.controller;
|
|
|
|
import com.google.protobuf.ServiceException;
|
|
import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest;
|
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
|
|
import com.guo.learningprogresstracker.entity.CommonResult;
|
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
|
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.ArrayList;
|
|
import java.time.LocalDateTime;
|
|
|
|
/**
|
|
* 学习会话控制层
|
|
*/
|
|
@RequestMapping("/study-sessions")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@Validated
|
|
public class StudySessionController {
|
|
|
|
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
|
|
|
@PostMapping
|
|
public void studySessionList() {
|
|
|
|
}
|
|
|
|
/**
|
|
* 通过sessionNum获取一个【学习会话】
|
|
*/
|
|
@GetMapping("/{sessionNum}")
|
|
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
|
|
// 通过 service 层获取,包含归属校验
|
|
StudySessionResponse response = studySessionsServiceImpl.getStudySessionBySessionNum(sessionNum);
|
|
return CommonResult.success(response);
|
|
}
|
|
|
|
/**
|
|
* 开始一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/continue")
|
|
public CommonResult<Void> startStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException, ServiceException {
|
|
studySessionsServiceImpl.continueStudySession(sessionNum);
|
|
return CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 暂停一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/pause")
|
|
public CommonResult<Void> pauseStudySession(@PathVariable("sessionNum") String sessionNum,
|
|
@RequestParam(value = "endTime", required = false) LocalDateTime endTime)
|
|
throws ErrorParameterException, ServiceException {
|
|
studySessionsServiceImpl.pauseStudySession(sessionNum, endTime);
|
|
return CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 结束一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/ended")
|
|
public CommonResult<Void> endedStudySession(@PathVariable("sessionNum") String sessionNum,
|
|
@Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException {
|
|
String message = studySessionsServiceImpl.endedStudySession(sessionNum, request.getContent());
|
|
return message != null ? CommonResult.success(message) : CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 获取【学习会话】所有的学习残片数据,以列表返回
|
|
*/
|
|
@GetMapping("/{sessionNum}/all-fragments")
|
|
public CommonResult<ArrayList<String>> getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
|
|
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
|
|
return CommonResult.success(allFragments);
|
|
|
|
}
|
|
}
|