67 lines
1.4 KiB
Java
Executable File
67 lines
1.4 KiB
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 of CourseService which can get(Course By Name, All Courses, Courses
|
|
* Ammount ), save, delete course.
|
|
*/
|
|
|
|
@Service
|
|
public class CourseService {
|
|
@Autowired
|
|
private CourseRepository repo;
|
|
|
|
/**
|
|
* getCourseByName
|
|
*
|
|
* @param name name of course to be found
|
|
* @return Course By Name
|
|
*/
|
|
public Optional<Course> getCourseByName(String name) {
|
|
return this.repo.findByName(name);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return all courses from db
|
|
*/
|
|
public List<Course> getAllCourses() {
|
|
return this.repo.findAll();
|
|
}
|
|
|
|
/**
|
|
* save to db
|
|
*
|
|
* @param course which course you would like to save
|
|
* @return Course instance with id from db
|
|
*/
|
|
public Course save(Course course) {
|
|
this.repo.save(course);
|
|
return course;
|
|
}
|
|
|
|
/**
|
|
* delete course from db
|
|
*
|
|
* @param course which course you would like to delete
|
|
*/
|
|
public void delete(Course course) {
|
|
this.repo.delete(course);
|
|
}
|
|
|
|
/**
|
|
* @return ammount of courses in db
|
|
*/
|
|
public int getCoursesAmmount() {
|
|
return (int) this.repo.count();
|
|
}
|
|
}
|