Merge branch 'feature/fragment-edit' into dev
学习碎片编辑功能:
- 新增碎片更新 API(PUT /report-fragments/{id})
- 新增会话碎片列表查询 API(GET /report-fragments/session/{sessionNum})
- 前端碎片详情页支持内联编辑
- 前端学习会话页展示碎片列表并支持编辑
This commit is contained in:
+24
-6
@@ -1,16 +1,17 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import com.guo.learningprogresstracker.service.impl.StudyReportFragmentsServiceImpl;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学习残片控制层
|
||||
@@ -24,12 +25,29 @@ public class reportFragmentsController {
|
||||
|
||||
/**
|
||||
* 创建学习残片
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@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,
|
||||
@Valid @RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
studyReportFragmentsServiceImpl.updateFragments(id, request);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定会话的所有学习残片
|
||||
*/
|
||||
@GetMapping("/session/{sessionNum}")
|
||||
public CommonResult<List<StudyReportFragmentsEntity>> getFragmentsBySession(@PathVariable String sessionNum) {
|
||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum);
|
||||
return CommonResult.success(fragments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.guo.learningprogresstracker.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
*/
|
||||
@Data
|
||||
public class UpdateFragmentsRequest {
|
||||
/**
|
||||
* 残片内容,学习内容的描述
|
||||
*/
|
||||
@NotBlank(message = "啊?无字天书?")
|
||||
private String content;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.mapStruct;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
@@ -11,4 +12,6 @@ public interface FragmentsConvert {
|
||||
FragmentsConvert MAPPER = Mappers.getMapper(FragmentsConvert.class);
|
||||
|
||||
StudyReportFragmentsEntity toFragmentsEntity(CreateFragmentsRequest request);
|
||||
|
||||
StudyReportFragmentsEntity toFragmentsEntity(UpdateFragmentsRequest request);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
* @description 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service
|
||||
@@ -13,4 +16,8 @@ import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
public interface StudyReportFragmentsService extends IService<StudyReportFragmentsEntity> {
|
||||
|
||||
void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException;
|
||||
|
||||
void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException;
|
||||
|
||||
List<StudyReportFragmentsEntity> getFragmentsBySession(String sessionNum);
|
||||
}
|
||||
|
||||
+22
@@ -3,6 +3,7 @@ package com.guo.learningprogresstracker.service.impl;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
@@ -13,6 +14,8 @@ import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
||||
*/
|
||||
@@ -34,4 +37,23 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
||||
}
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
StudyReportFragmentsEntity existing = this.getById(id);
|
||||
if (existing == null) {
|
||||
throw new NotFindEntitiesException(String.format("未能找到学习残片id[%d]", id));
|
||||
}
|
||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||
entity.setId(id);
|
||||
this.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StudyReportFragmentsEntity> getFragmentsBySession(String sessionNum) {
|
||||
return this.list(
|
||||
Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum)
|
||||
.orderByAsc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user