refactor: 回忆改用独立存储与请求响应 DTO,服务按域拆包

This commit is contained in:
2026-11-20 09:38:16 +08:00
parent 5ff692b768
commit 4b65eb57b1
280 changed files with 8774 additions and 4364 deletions
@@ -0,0 +1,94 @@
package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.dto.request.AssignOwnershipRequest;
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
import com.guo.learningprogresstracker.dto.response.ReportFragmentResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.service.impl.StudyReportFragmentsServiceImpl;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 知识碎片控制层(归属-01 起同时承载「内容归属」的调整动作)。
*/
@RequestMapping("/report-fragments")
@RestController
@Validated
@RequiredArgsConstructor
public class ReportFragmentsController {
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
/**
* 创建知识碎片(记录上下文为当前学习会话,内容归属默认取该会话所属任务)
*/
@PostMapping
public CommonResult<Void> createFragments(@Valid @RequestBody CreateFragmentsRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.createFragments(request);
return CommonResult.success();
}
/**
* 修改知识碎片正文与内容归属(记录上下文不可变)
*/
@PutMapping("/{id}")
public CommonResult<Void> updateFragments(@PathVariable Integer id, @RequestBody UpdateFragmentsRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.updateFragments(id, request);
return CommonResult.success();
}
/**
* 调整内容归属;body 传 {"ownerTaskNum": "TASK-xxx"},传空字符串表示清空归属(回到待归类)
*/
@PutMapping("/{id}/ownership")
public CommonResult<Void> assignOwnership(
@PathVariable Integer id, @Valid @RequestBody AssignOwnershipRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.assignOwnership(id, request.getOwnerTaskNum());
return CommonResult.success();
}
/**
* 删除知识碎片(软删除)
*/
@DeleteMapping("/{id}")
public CommonResult<Void> deleteFragment(@PathVariable Integer id) throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.deleteFragment(id);
return CommonResult.success();
}
/**
* 获取指定会话产生的所有知识碎片(记录上下文为会话)
*/
@GetMapping("/session/{sessionNum}")
public CommonResult<List<ReportFragmentResponse>> getFragmentsBySession(@PathVariable String sessionNum) {
List<ReportFragmentResponse> fragments =
studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum).stream()
.map(ReportFragmentResponse::of)
.toList();
return CommonResult.success(fragments);
}
/**
* 待归类内容:还没有确定内容归属的碎片
*/
@GetMapping("/pending-ownership")
public CommonResult<List<ReportFragmentResponse>> getPendingOwnershipFragments() {
return CommonResult.success(studyReportFragmentsServiceImpl.getPendingOwnershipFragments().stream()
.map(ReportFragmentResponse::of)
.toList());
}
}