added cursus/course interactions
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
|
||||
@Service
|
||||
public class CourseService {
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
public CourseService(CourseRepository courseRepo) {
|
||||
this.courseRepo = courseRepo;
|
||||
}
|
||||
|
||||
public void save(Course course){
|
||||
courseRepo.save(course);
|
||||
}
|
||||
|
||||
public Course findById(long id){
|
||||
return courseRepo.findById(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusCourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CursusCourseService {
|
||||
|
||||
private final CursusCourseRepository cursusCourseRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
private final CursusRepository cursusRepo;
|
||||
|
||||
public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) {
|
||||
this.cursusCourseRepo = cursusCourseRepo;
|
||||
this.courseRepo = courseRepo;
|
||||
this.cursusRepo = cursusRepo;
|
||||
}
|
||||
|
||||
public void save(CursusCourse cursusCourse){
|
||||
cursusCourseRepo.save(cursusCourse);
|
||||
}
|
||||
|
||||
public Iterable<CursusCourse> findAll(){
|
||||
return cursusCourseRepo.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> getDepthCursus(Cursus cursus){
|
||||
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
ArrayList<Course> courses = new ArrayList<>();
|
||||
for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){
|
||||
courses.add(c);
|
||||
}
|
||||
toReturn.put("courses",courses);
|
||||
toReturn.put("cursusId",cursus.getCursusId());
|
||||
toReturn.put("year",cursus.getYear());
|
||||
toReturn.put("option",cursus.getOption());
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public Iterable<Map<String, Object>> getAllDepthCursus(){
|
||||
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){
|
||||
toReturn.add(getDepthCursus(cursus));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CursusService {
|
||||
|
||||
|
||||
private final CursusRepository cursusRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){
|
||||
this.cursusRepo = cursusRepo;
|
||||
this.courseRepo = courseRepo;
|
||||
}
|
||||
|
||||
|
||||
public void save(Cursus cursus){
|
||||
cursusRepo.save(cursus);
|
||||
}
|
||||
|
||||
public Cursus findById(long id){
|
||||
return cursusRepo.findById(id);
|
||||
}
|
||||
|
||||
public Iterable<Cursus> findAll(){
|
||||
return cursusRepo.findAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user