|
1 | 1 | package org.launchcode.codingevents.controllers; |
2 | 2 |
|
| 3 | +import org.launchcode.codingevents.models.Event; |
3 | 4 | import org.springframework.stereotype.Controller; |
4 | 5 | import org.springframework.web.bind.annotation.GetMapping; |
| 6 | +import org.springframework.web.bind.annotation.PostMapping; |
5 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
6 | 8 | import org.springframework.ui.Model; |
| 9 | +import org.springframework.web.bind.annotation.RequestParam; |
7 | 10 |
|
8 | 11 | import java.util.ArrayList; |
9 | 12 | import java.util.List; |
10 | 13 |
|
11 | | -/** |
12 | | - * Created by Chris Bay |
13 | | - */ |
| 14 | + |
14 | 15 | @Controller |
15 | 16 | @RequestMapping("events") |
16 | 17 | public class EventController { |
| 18 | + private static List<Event> events = new ArrayList<>(); |
17 | 19 |
|
18 | 20 | @GetMapping |
19 | 21 | public String displayAllEvents(Model model) { |
20 | | - List<String> events = new ArrayList<>(); |
21 | | - events.add("Code With Pride"); |
22 | | - events.add("Strange Loop"); |
23 | | - events.add("Apple WWDC"); |
24 | | - events.add("SpringOne Platform"); |
25 | | - model.addAttribute("events", events); |
| 22 | + model.addAttribute("events", events); |
| 23 | +// List<String> events = new ArrayList<>(); |
| 24 | +// events.add("Code With Pride"); |
| 25 | +// events.add("Strange Loop"); |
| 26 | +// events.add("Apple WWDC"); |
| 27 | +// events.add("SpringOne Platform"); |
| 28 | +// model.addAttribute("events", events); |
26 | 29 | return "events/index"; |
27 | 30 | } |
28 | 31 |
|
| 32 | + @GetMapping("create") |
| 33 | + public String renderCreateEventForm() { |
| 34 | + |
| 35 | + return "events/create"; |
| 36 | + } |
| 37 | + |
| 38 | +@PostMapping("create") |
| 39 | + public String createEvent(@RequestParam String eventName, @RequestParam String eventDescription) { |
| 40 | + events.add(new Event(eventName, eventDescription)); |
| 41 | + return "redirect:/events"; |
| 42 | + } |
| 43 | + |
29 | 44 | } |
0 commit comments