File tree Expand file tree Collapse file tree
java/org/launchcode/codingevents
resources/templates/events Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .launchcode .codingevents .controllers ;
22
3+ import org .launchcode .codingevents .data .EventData ;
34import org .launchcode .codingevents .models .Event ;
45import org .springframework .stereotype .Controller ;
56import org .springframework .web .bind .annotation .GetMapping ;
1819@ RequestMapping ("events" )
1920public class EventController {
2021
21- private static List <Event > events = new ArrayList <>();
22-
2322 @ GetMapping
2423 public String displayAllEvents (Model model ) {
2524 model .addAttribute ("title" , "All Events" );
26- model .addAttribute ("events" , events );
25+ model .addAttribute ("events" , EventData . getAll () );
2726 return "events/index" ;
2827 }
2928
@@ -36,7 +35,7 @@ public String displayCreateEventForm(Model model) {
3635 @ PostMapping ("create" )
3736 public String processCreateEventForm (@ RequestParam String eventName ,
3837 @ RequestParam String eventDescription ) {
39- events .add (new Event (eventName , eventDescription ));
38+ EventData .add (new Event (eventName , eventDescription ));
4039 return "redirect:/events" ;
4140 }
4241
Original file line number Diff line number Diff line change 1+ package org .launchcode .codingevents .data ;
2+
3+ import org .launchcode .codingevents .models .Event ;
4+
5+ import java .util .Collection ;
6+ import java .util .HashMap ;
7+ import java .util .Map ;
8+
9+ /**
10+ * Created by Chris Bay
11+ */
12+ public class EventData {
13+
14+ private static final Map <Integer , Event > events = new HashMap <>();
15+
16+ public static Collection <Event > getAll () {
17+ return events .values ();
18+ }
19+
20+ public static Event getById (int id ) {
21+ return events .get (id );
22+ }
23+
24+ public static void add (Event event ) {
25+ events .put (event .getId (), event );
26+ }
27+
28+ public static void remove (int id ) {
29+ events .remove (id );
30+ }
31+
32+ }
Original file line number Diff line number Diff line change 55
66< header th:replace ="fragments :: header "> </ header >
77
8-
98< form method ="post ">
109 < div class ="form-group ">
1110 < label > Name
You can’t perform that action at this time.
0 commit comments