source: src/main/java/com/example/web/HomeController.java

Last change on this file was a51a591, checked in by colovik <j.colovik@…>, 14 months ago

final

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[a51a591]1package com.example.web;
2
3import com.example.model.Enumerations.Status;
4import com.example.model.Event;
5import com.example.service.BandService;
6import com.example.service.CateringService;
7import com.example.service.EventService;
8import com.example.service.PhotographerService;
9import org.springframework.stereotype.Controller;
10import org.springframework.ui.Model;
11import org.springframework.web.bind.annotation.GetMapping;
12import org.springframework.web.bind.annotation.PathVariable;
13import org.springframework.web.bind.annotation.PostMapping;
14import org.springframework.web.bind.annotation.RequestMapping;
15
16import javax.servlet.http.HttpServletResponse;
17import java.util.ArrayList;
18import java.util.List;
19
20@Controller
21@RequestMapping(value = {"/", "/home"})
22public 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}
Note: See TracBrowser for help on using the repository browser.