| 1 | package mk.ukim.finki.wp.db.service;
|
|---|
| 2 |
|
|---|
| 3 | import lombok.RequiredArgsConstructor;
|
|---|
| 4 | import mk.ukim.finki.wp.db.entity.Course;
|
|---|
| 5 | import mk.ukim.finki.wp.db.entity.ModuleEntity;
|
|---|
| 6 | import mk.ukim.finki.wp.db.repository.ModuleRepository;
|
|---|
| 7 | import org.springframework.stereotype.Service;
|
|---|
| 8 |
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | @Service
|
|---|
| 12 | @RequiredArgsConstructor
|
|---|
| 13 | public class ModuleService {
|
|---|
| 14 |
|
|---|
| 15 | private final ModuleRepository moduleRepository;
|
|---|
| 16 |
|
|---|
| 17 | public List<ModuleEntity> findAllByCourse(Course course) {
|
|---|
| 18 | return moduleRepository.findAllByCourse(course);
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | public ModuleEntity findById(Integer id) {
|
|---|
| 22 | return moduleRepository.findById(id).get();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | public void addModule(Course course, String title, String description) {
|
|---|
| 26 | ModuleEntity moduleEntity = new ModuleEntity();
|
|---|
| 27 | moduleEntity.setCourse(course);
|
|---|
| 28 | moduleEntity.setTitle(title);
|
|---|
| 29 | moduleEntity.setDescription(description);
|
|---|
| 30 | moduleRepository.save(moduleEntity);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public void editModule(Integer id, String title, String description) {
|
|---|
| 34 | ModuleEntity moduleEntity = moduleRepository.findById(id).get();
|
|---|
| 35 | moduleEntity.setTitle(title);
|
|---|
| 36 | moduleEntity.setDescription(description);
|
|---|
| 37 | moduleRepository.save(moduleEntity);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | public void deleteModule(Integer id) {
|
|---|
| 41 | moduleRepository.deleteById(id);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|