80 lines
3.4 KiB
Java
80 lines
3.4 KiB
Java
package com.guo.learningprogresstracker.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest;
|
|
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.Valid;
|
|
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.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* 学习会话控制层
|
|
*/
|
|
@RequestMapping("/study-sessions")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@Validated
|
|
public class StudySessionController {
|
|
|
|
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
|
|
|
@PostMapping
|
|
public void studySessionList() {
|
|
|
|
}
|
|
|
|
/**
|
|
* 通过sessionNum获取一个【学习会话】
|
|
*/
|
|
@GetMapping("/{sessionNum}")
|
|
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 + "]不存在"));
|
|
StudySessionResponce studySessionResponce = StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
|
return CommonResult.success(studySessionResponce);
|
|
}
|
|
|
|
/**
|
|
* 暂停一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/pause")
|
|
public CommonResult pauseStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
|
|
studySessionsServiceImpl.pauseStudySession(sessionNum);
|
|
return CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 结束一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/ended")
|
|
public CommonResult 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 {
|
|
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
|
|
return CommonResult.success(allFragments);
|
|
|
|
}
|
|
}
|