1 | package project.educatum.web;
|
---|
2 |
|
---|
3 | import org.springframework.stereotype.Controller;
|
---|
4 | import org.springframework.ui.Model;
|
---|
5 | import org.springframework.web.bind.annotation.*;
|
---|
6 | import project.educatum.model.Teacher;
|
---|
7 | import project.educatum.model.Subject;
|
---|
8 | import project.educatum.model.Student;
|
---|
9 | import project.educatum.service.*;
|
---|
10 |
|
---|
11 | import java.util.ArrayList;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | @Controller
|
---|
15 | @RequestMapping(path = "/admin", method = {RequestMethod.POST, RequestMethod.DELETE, RequestMethod.GET})
|
---|
16 | public class AdminController {
|
---|
17 |
|
---|
18 | private final TeacherService teacherService;
|
---|
19 | private final SubjectService subjectService;
|
---|
20 | private final TeacherSubjectService teacherSubjectService;
|
---|
21 | private final StudentService studentService;
|
---|
22 | private final PaymentService paymentService;
|
---|
23 | private final TeacherStudentService teacherStudentService;
|
---|
24 | private final EmailService emailService;
|
---|
25 |
|
---|
26 | public AdminController(TeacherService teacherService, SubjectService subjectService, TeacherSubjectService teacherSubjectService, StudentService studentService, PaymentService paymentService, TeacherStudentService teacherStudentService, EmailService emailService) {
|
---|
27 | this.teacherService = teacherService;
|
---|
28 | this.subjectService = subjectService;
|
---|
29 | this.teacherSubjectService = teacherSubjectService;
|
---|
30 | this.studentService = studentService;
|
---|
31 | this.paymentService = paymentService;
|
---|
32 | this.teacherStudentService = teacherStudentService;
|
---|
33 | this.emailService = emailService;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @GetMapping("/allTeachers")
|
---|
37 | public String getAllTeachers(@RequestParam(required = false) String ime, Model model) {
|
---|
38 | List<Teacher> teachers = new ArrayList<>();
|
---|
39 | if (ime == null) {
|
---|
40 | teachers = teacherService.findAll();
|
---|
41 | } else {
|
---|
42 | teachers = teacherService.findAllByNameLike(ime);
|
---|
43 | }
|
---|
44 |
|
---|
45 | model.addAttribute("teachers", teachers);
|
---|
46 | return "teachersAdmin";
|
---|
47 | }
|
---|
48 |
|
---|
49 | @GetMapping("/allSubjects")
|
---|
50 | public String getAllSubjects(@RequestParam(required = false) String ime, Model model) {
|
---|
51 | List<Subject> subjects;
|
---|
52 | if (ime == null) {
|
---|
53 | subjects = subjectService.findAll();
|
---|
54 | } else {
|
---|
55 | subjects = subjectService.findAllByNameLike(ime);
|
---|
56 | }
|
---|
57 | model.addAttribute("subjects", subjects);
|
---|
58 | return "subjectsAdmin";
|
---|
59 | }
|
---|
60 |
|
---|
61 | @GetMapping("/allStudents")
|
---|
62 | public String getAllStudents(@RequestParam(required = false) String ime, Model model) {
|
---|
63 | List<Student> students;
|
---|
64 | if (ime == null) {
|
---|
65 | students = studentService.findAll();
|
---|
66 | } else {
|
---|
67 | students = studentService.findAllByName(ime);
|
---|
68 | }
|
---|
69 | model.addAttribute("students", students);
|
---|
70 | return "studentsAdmin";
|
---|
71 | }
|
---|
72 |
|
---|
73 | @PostMapping("/activate/{id}")
|
---|
74 | public String activateAccount(@PathVariable String id) {
|
---|
75 | Teacher n = teacherService.findById(Integer.valueOf(id));
|
---|
76 | if (n != null) {
|
---|
77 | teacherService.updateEnabled(Integer.valueOf(id));
|
---|
78 | emailService.sendMessage(n.getEmail(), "Активиран корисник - EDUCATUM", "Вашиот профил е активиран. Можете да се најавите со e-mail и лозинка. \n\n EDUCATUM");
|
---|
79 | }
|
---|
80 | return "redirect:/admin/allTeachers";
|
---|
81 | }
|
---|
82 |
|
---|
83 | @GetMapping("/add")
|
---|
84 | public String showAdd() {
|
---|
85 | return "formAdd.html";
|
---|
86 | }
|
---|
87 |
|
---|
88 | @PostMapping("/add/subject")
|
---|
89 | public String create(@RequestParam String name) {
|
---|
90 | subjectService.create(name);
|
---|
91 | return "redirect:/admin/allSubjects";
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|