source: src/main/java/mk/ukim/finki/wp/db/service/LessonService.java

Last change on this file was 5ea00d7, checked in by Malek Alavi <malekalavi7@…>, 6 days ago

Initial project upload

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package mk.ukim.finki.wp.db.service;
2
3import lombok.RequiredArgsConstructor;
4import mk.ukim.finki.wp.db.entity.Lesson;
5import mk.ukim.finki.wp.db.entity.ModuleEntity;
6import mk.ukim.finki.wp.db.repository.LessonRepository;
7import org.springframework.stereotype.Service;
8
9import java.util.List;
10
11@Service
12@RequiredArgsConstructor
13public 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}
Note: See TracBrowser for help on using the repository browser.