This commit is contained in:
ublue 2020-09-17 18:44:08 +08:00
parent b870370395
commit 82114ebc49
3 changed files with 36 additions and 0 deletions

View File

@ -5,8 +5,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface ExerciseRepository extends JpaRepository<Exercise, Integer> {
List<Exercise> findByStudentId(int studentId);
Optional<Exercise> findById(int id);
}

View File

@ -1,15 +1,18 @@
package com.codesdream.ase.repository.student;
import com.codesdream.ase.model.parent.Exercise;
import com.codesdream.ase.model.student.Honor;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository
public interface HonorRepository extends JpaRepository<Honor, Integer> {
List<Honor> findByStudentId(int studentId);
List<Honor> findByStudentId(int studentId, Sort sort);
Optional<Honor> findById(int id);
}

View File

@ -112,6 +112,22 @@ public class StaticsService {
return honorRepository.findByStudentId(studentId, Sort.by(Sort.Direction.DESC, "creationDate"));
}
/**
* 获取指定的一条荣誉信息
* @author gzq
* @exception NotFoundException 如果荣誉id不存在则抛出此异常
* @param honorId 荣誉id
* @return 荣誉
*/
public Honor getHonor(int honorId) {
Optional<Honor> h0 = honorRepository.findById(honorId);
if (!h0.isPresent()) {
throw new NotFoundException("No such honor.");
}
return h0.get();
}
/**
* 显示所有公告默认按照公告发布时间排序
* @return 公告列表
@ -132,7 +148,21 @@ public class StaticsService {
}
return exerciseRepository.findByStudentId(studentId);
}
/**
* 获取指定的一条锻炼信息
* @author gzq
* @exception NotFoundException 如果锻炼id不存在则抛出此异常
* @param exerciseId 锻炼id
* @return 锻炼
*/
public Exercise getExercise(int exerciseId) {
Optional<Exercise> e0 = exerciseRepository.findById(exerciseId);
if (!e0.isPresent()) {
throw new NotFoundException("No such exercise.");
}
return e0.get();
}
/**
* 显示学生详细信息
* @exception NotFoundException 如果学生id不存在则抛出此异常