11package org .launchcode .codingevents .controllers ;
22
33import org .springframework .stereotype .Controller ;
4+ import org .springframework .ui .Model ;
45import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .PostMapping ;
57import org .springframework .web .bind .annotation .RequestMapping ;
6- import org .springframework .ui . Model ;
8+ import org .springframework .web . bind . annotation . RequestParam ;
79
810import java .util .ArrayList ;
911import java .util .List ;
1517@ RequestMapping ("events" )
1618public class EventController {
1719
20+ private static List <String > events = new ArrayList <>();
21+
1822 @ GetMapping
1923 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" );
24+ model .addAttribute ("title" , "All Events" );
2525 model .addAttribute ("events" , events );
2626 return "events/index" ;
2727 }
2828
29- }
29+ @ GetMapping ("create" )
30+ public String displayCreateEventForm (Model model ) {
31+ model .addAttribute ("title" , "Create Event" );
32+ return "events/create" ;
33+ }
34+
35+ @ PostMapping ("create" )
36+ public String processCreateEventForm (@ RequestParam String eventName ) {
37+ events .add (eventName );
38+ return "redirect:" ;
39+ }
40+
41+ }
0 commit comments