diff --git a/src/main/java/com/guo/learningprogresstracker/controller/reportFragmentsController.java b/src/main/java/com/guo/learningprogresstracker/controller/reportFragmentsController.java index 7a0f0e7..c39c95e 100644 --- a/src/main/java/com/guo/learningprogresstracker/controller/reportFragmentsController.java +++ b/src/main/java/com/guo/learningprogresstracker/controller/reportFragmentsController.java @@ -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 createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException { studyReportFragmentsServiceImpl.createFragments(request); return CommonResult.success(); } + + /** + * 更新学习残片 + */ + @PutMapping("/{id}") + public CommonResult updateFragments(@PathVariable Integer id, + @Valid @RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException { + studyReportFragmentsServiceImpl.updateFragments(id, request); + return CommonResult.success(); + } + + /** + * 获取指定会话的所有学习残片 + */ + @GetMapping("/session/{sessionNum}") + public CommonResult> getFragmentsBySession(@PathVariable String sessionNum) { + List fragments = studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum); + return CommonResult.success(fragments); + } } diff --git a/src/main/java/com/guo/learningprogresstracker/dto/request/UpdateFragmentsRequest.java b/src/main/java/com/guo/learningprogresstracker/dto/request/UpdateFragmentsRequest.java new file mode 100644 index 0000000..37acce3 --- /dev/null +++ b/src/main/java/com/guo/learningprogresstracker/dto/request/UpdateFragmentsRequest.java @@ -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; +} diff --git a/src/main/java/com/guo/learningprogresstracker/mapStruct/FragmentsConvert.java b/src/main/java/com/guo/learningprogresstracker/mapStruct/FragmentsConvert.java index 896b723..ff4d89f 100644 --- a/src/main/java/com/guo/learningprogresstracker/mapStruct/FragmentsConvert.java +++ b/src/main/java/com/guo/learningprogresstracker/mapStruct/FragmentsConvert.java @@ -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); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/StudyReportFragmentsService.java b/src/main/java/com/guo/learningprogresstracker/service/StudyReportFragmentsService.java index 6e9b5f8..525385b 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/StudyReportFragmentsService.java +++ b/src/main/java/com/guo/learningprogresstracker/service/StudyReportFragmentsService.java @@ -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 { void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException; + + void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException; + + List getFragmentsBySession(String sessionNum); } diff --git a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java index fc64354..5e54fc0 100644 --- a/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java +++ b/src/main/java/com/guo/learningprogresstracker/service/impl/StudyReportFragmentsServiceImpl.java @@ -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 getFragmentsBySession(String sessionNum) { + return this.list( + Wrappers.lambdaQuery(StudyReportFragmentsEntity.class) + .eq(StudyReportFragmentsEntity::getSessionNum, sessionNum) + .orderByAsc(StudyReportFragmentsEntity::getCreatedTime)); + } }