feat: 新增学习数据导出接口
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.ExportResult;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import com.guo.learningprogresstracker.exception.OperationFailedException;
|
||||
import com.guo.learningprogresstracker.service.ExportService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 数据导出控制层(导出-01):把学习报告、知识碎片与任务统计导出为 Markdown / JSON。
|
||||
*/
|
||||
@RequestMapping("/export")
|
||||
@RestController
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
public class ExportController {
|
||||
|
||||
private final ExportService exportService;
|
||||
|
||||
/**
|
||||
* 导出单个学习任务的全部学习记录
|
||||
* @param format markdown(默认)或 json
|
||||
*/
|
||||
@GetMapping("/task/{taskNum}")
|
||||
public CommonResult<ExportResult> exportTask(
|
||||
@PathVariable String taskNum,
|
||||
@RequestParam(defaultValue = "markdown") String format)
|
||||
throws NotFindEntitiesException, OperationFailedException {
|
||||
return CommonResult.success(exportService.exportTask(taskNum, format));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按时间范围导出学习记录(起止日期都可省略,都省略为全部时间)
|
||||
* @param format markdown(默认)或 json
|
||||
*/
|
||||
@GetMapping("/range")
|
||||
public CommonResult<ExportResult> exportRange(
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@RequestParam(defaultValue = "markdown") String format)
|
||||
throws OperationFailedException {
|
||||
return CommonResult.success(exportService.exportRange(startDate, endDate, format));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user