37 lines
839 B
Java
Executable File
37 lines
839 B
Java
Executable File
package com.plannaplan.services;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import com.plannaplan.entities.Course;
|
|
import com.plannaplan.repositories.CourseRepository;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
public class CourseService {
|
|
@Autowired
|
|
private CourseRepository repo;
|
|
|
|
public Optional<Course> getCourseByName(String name) {
|
|
return this.repo.findByName(name);
|
|
}
|
|
|
|
public List<Course> getAllCourses() {
|
|
return this.repo.findAll();
|
|
}
|
|
|
|
public Course save(Course course) {
|
|
this.repo.save(course);
|
|
return course;
|
|
}
|
|
|
|
public void delete(Course course) {
|
|
this.repo.delete(course);
|
|
}
|
|
|
|
public int getCoursesAmmount() {
|
|
return (int) this.repo.count();
|
|
}
|
|
} |