| 1 | package mk.ukim.finki.wp.db.service;
|
|---|
| 2 |
|
|---|
| 3 | import lombok.RequiredArgsConstructor;
|
|---|
| 4 | import mk.ukim.finki.wp.db.entity.Lesson;
|
|---|
| 5 | import mk.ukim.finki.wp.db.entity.ModuleEntity;
|
|---|
| 6 | import mk.ukim.finki.wp.db.repository.LessonRepository;
|
|---|
| 7 | import org.springframework.stereotype.Service;
|
|---|
| 8 |
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | @Service
|
|---|
| 12 | @RequiredArgsConstructor
|
|---|
| 13 | public class LessonService {
|
|---|
| 14 |
|
|---|
| 15 | private final LessonRepository lessonRepository;
|
|---|
| 16 |
|
|---|
| 17 | public List<Lesson> findAllByModule(ModuleEntity moduleEntity) {
|
|---|
| 18 | return lessonRepository.findAllByModuleEntity(moduleEntity);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | public Lesson findById(Integer id) {
|
|---|
| 22 | return lessonRepository.findById(id).get();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | public void addLesson(ModuleEntity moduleEntity, String title, String material) {
|
|---|
| 26 | Lesson lesson = new Lesson();
|
|---|
| 27 | lesson.setModuleEntity(moduleEntity);
|
|---|
| 28 | lesson.setTitle(title);
|
|---|
| 29 | lesson.setMaterial(material);
|
|---|
| 30 | lessonRepository.save(lesson);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public void editLesson(Integer id, String title, String material) {
|
|---|
| 34 | Lesson lesson = lessonRepository.findById(id).get();
|
|---|
| 35 | lesson.setTitle(title);
|
|---|
| 36 | lesson.setMaterial(material);
|
|---|
| 37 | lessonRepository.save(lesson);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | public void deleteLesson(Integer id) {
|
|---|
| 41 | lessonRepository.deleteById(id);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|