1 | package com.example.task.controller;
|
---|
2 |
|
---|
3 | import com.example.task.service.SubjectService;
|
---|
4 | import lombok.AllArgsConstructor;
|
---|
5 | import org.springframework.stereotype.Controller;
|
---|
6 | import org.springframework.ui.Model;
|
---|
7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
8 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
9 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
10 |
|
---|
11 | import java.time.LocalDate;
|
---|
12 |
|
---|
13 | @Controller
|
---|
14 | @AllArgsConstructor
|
---|
15 | public class SubjectController {
|
---|
16 |
|
---|
17 | private final SubjectService subjectService;
|
---|
18 |
|
---|
19 | @GetMapping("/add/subject/exam")
|
---|
20 | public String getAddExamPage(Model model) {
|
---|
21 | model.addAttribute("subjects", subjectService.findAllSubjects());
|
---|
22 | model.addAttribute("places", subjectService.findAllPlaces());
|
---|
23 | return "subject/form_exam";
|
---|
24 | }
|
---|
25 |
|
---|
26 | @GetMapping("/add/subject/class")
|
---|
27 | public String getAddClassPage(Model model) {
|
---|
28 | model.addAttribute("subjects", subjectService.findAllSubjects());
|
---|
29 | model.addAttribute("places", subjectService.findAllPlaces());
|
---|
30 | return "subject/form_class";
|
---|
31 | }
|
---|
32 |
|
---|
33 | @PostMapping("/add/subject/exam")
|
---|
34 | public String addExam(@RequestParam(name = "subject") String subjectId,
|
---|
35 | @RequestParam(name = "place") Integer placeId,
|
---|
36 | @RequestParam(name = "name") String examName,
|
---|
37 | @RequestParam(name = "description") String examDescription,
|
---|
38 | @RequestParam(name = "date") LocalDate date,
|
---|
39 | @RequestParam(name = "startTime") String startTime,
|
---|
40 | @RequestParam(name = "endTime") String endTime) throws Exception {
|
---|
41 | subjectService.addExam(subjectId, placeId, examName, examDescription, date, startTime, endTime);
|
---|
42 | return "redirect:/add/subject/exam";
|
---|
43 | }
|
---|
44 |
|
---|
45 | @PostMapping("/add/subject/class")
|
---|
46 | public String addClass(@RequestParam(name = "subject") String subjectId,
|
---|
47 | @RequestParam(name = "place") Integer placeId,
|
---|
48 | @RequestParam(name = "name") String examName,
|
---|
49 | @RequestParam(name = "description") String examDescription,
|
---|
50 | @RequestParam(name = "startingDate", required = false) LocalDate startingDate,
|
---|
51 | @RequestParam(name = "endingDate", required = false) LocalDate endingDate,
|
---|
52 | @RequestParam(name = "day", required = false) String day,
|
---|
53 | @RequestParam(name = "startTime") String startTime,
|
---|
54 | @RequestParam(name = "endTime") String endTime) throws Exception {
|
---|
55 | subjectService.addClass(subjectId, placeId, examName, examDescription, startingDate, endingDate, day, startTime, endTime);
|
---|
56 | return "redirect:/add/subject/class";
|
---|
57 | }
|
---|
58 |
|
---|
59 | @GetMapping("/exam")
|
---|
60 | public String getUserExam(Model model) {
|
---|
61 | model.addAttribute("exams", subjectService.findAllUserExams());
|
---|
62 | return "subject/list_exam";
|
---|
63 | }
|
---|
64 |
|
---|
65 | @GetMapping("/class")
|
---|
66 | public String getUserClasses(Model model) {
|
---|
67 | model.addAttribute("nonRepeatingClasses", subjectService.findAllUserNonRepeatingClasses());
|
---|
68 | model.addAttribute("repeatingClasses", subjectService.findAllUserRepeatingClasses());
|
---|
69 | return "subject/list_class";
|
---|
70 | }
|
---|
71 | }
|
---|