1 | package com.example.web;
|
---|
2 |
|
---|
3 | import com.example.model.Enumerations.Status;
|
---|
4 | import com.example.model.Event;
|
---|
5 | import com.example.service.BandService;
|
---|
6 | import com.example.service.CateringService;
|
---|
7 | import com.example.service.EventService;
|
---|
8 | import com.example.service.PhotographerService;
|
---|
9 | import org.springframework.stereotype.Controller;
|
---|
10 | import org.springframework.ui.Model;
|
---|
11 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
12 | import org.springframework.web.bind.annotation.PathVariable;
|
---|
13 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
14 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
15 |
|
---|
16 | import javax.servlet.http.HttpServletResponse;
|
---|
17 | import java.util.ArrayList;
|
---|
18 | import java.util.List;
|
---|
19 |
|
---|
20 | @Controller
|
---|
21 | @RequestMapping(value = {"/", "/home"})
|
---|
22 | public class HomeController {
|
---|
23 |
|
---|
24 | private final EventService eventService;
|
---|
25 |
|
---|
26 | private final BandService bandService;
|
---|
27 | private final PhotographerService photographerService;
|
---|
28 | private final CateringService cateringService;
|
---|
29 |
|
---|
30 | public HomeController(EventService eventService, BandService bandService,
|
---|
31 | PhotographerService photographerService, CateringService cateringService) {
|
---|
32 | this.eventService = eventService;
|
---|
33 | this.bandService = bandService;
|
---|
34 | this.photographerService = photographerService;
|
---|
35 | this.cateringService = cateringService;
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | @GetMapping
|
---|
40 | public String getHomePage() {
|
---|
41 | return "home";
|
---|
42 | }
|
---|
43 |
|
---|
44 | @GetMapping("/event/{id}")
|
---|
45 | public String getEventInfo(@PathVariable Integer id, Model model) {
|
---|
46 | Event event = eventService.findById(id);
|
---|
47 |
|
---|
48 | List<String> bandList = new ArrayList<>();
|
---|
49 | for (int i = 0; i < event.getBandList().size(); i++) {
|
---|
50 | bandList.add(event.getBandList().get(i).getName());
|
---|
51 | }
|
---|
52 |
|
---|
53 | List<String> cateringList = new ArrayList<>();
|
---|
54 | for (int i = 0; i < event.getCateringList().size(); i++) {
|
---|
55 | cateringList.add(event.getCateringList().get(i).getName());
|
---|
56 | }
|
---|
57 |
|
---|
58 | List<String> photographerList = new ArrayList<>();
|
---|
59 | for (int i = 0; i < event.getPhotographerList().size(); i++) {
|
---|
60 | photographerList.add(event.getPhotographerList().get(i).getName());
|
---|
61 | }
|
---|
62 |
|
---|
63 | model.addAttribute("event", event);
|
---|
64 | model.addAttribute("bandList", bandList);
|
---|
65 | model.addAttribute("cateringList", cateringList);
|
---|
66 | model.addAttribute("photographerList", photographerList);
|
---|
67 | return "more_details";
|
---|
68 | }
|
---|
69 |
|
---|
70 | @PostMapping("/approveEvent/{id}")
|
---|
71 | public String approveEvent(@PathVariable Integer id, HttpServletResponse response){
|
---|
72 | Event event = eventService.findById(id);
|
---|
73 | event.setStatus(Status.APPROVED);
|
---|
74 | eventService.update(event);
|
---|
75 | return "redirect:/my_events";
|
---|
76 | }
|
---|
77 |
|
---|
78 | @PostMapping("/rejectEvent/{id}")
|
---|
79 | public String rejectEvent(@PathVariable Integer id, HttpServletResponse response){
|
---|
80 | Event event = eventService.findById(id);
|
---|
81 | event.setStatus(Status.REJECTED);
|
---|
82 | eventService.update(event);
|
---|
83 | return "redirect:/my_events";
|
---|
84 | }
|
---|
85 | }
|
---|