[xingyu.guo] feat: 【创建学习残片】API

This commit is contained in:
guo
2024-09-22 10:21:54 +08:00
parent bbecc86df1
commit da6a25996d
6 changed files with 99 additions and 5 deletions
@@ -1,7 +1,12 @@
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.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.mapStruct.FragmentsConvert;
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
import org.springframework.stereotype.Service;
@@ -15,6 +20,22 @@ import org.springframework.stereotype.Service;
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
implements StudyReportFragmentsService{
private final StudySessionsServiceImpl studySessionsServiceImpl;
public StudyReportFragmentsServiceImpl(StudySessionsServiceImpl studySessionsServiceImpl) {
this.studySessionsServiceImpl = studySessionsServiceImpl;
}
@Override
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
if (studySessionsServiceImpl.exists(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum,entity.getSessionNum()))) {
this.save(entity);
}else {
throw new NotFindEntitiesException(String.format("未能找到学习会话sessionNum[%s]",entity.getSessionNum()));
}
}
}