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 .models .Event ;
34import org .springframework .stereotype .Controller ;
45import org .springframework .web .bind .annotation .*;
56import org .springframework .ui .Model ;
1314@ Controller
1415@ RequestMapping ("/events" )
1516public class EventController {
16-
17- private static List <String > events = new ArrayList <>();
18-
17+ // create a collection to store the data which is linked to the Model//
18+ private static List <Event > events = new ArrayList <>();
19+ // displays form at//
1920 @ GetMapping
2021 public String displayAllEvents (Model model ) {
2122 model .addAttribute ("events" , events );
2223 return "/events/index" ;
2324 }
24-
25+ // displays create event form //
2526 @ GetMapping ("/create" )
2627 public String displayCreateEventForm () {
2728 return "events/create" ;
2829 }
2930
3031 @ PostMapping ("/create" )
31- public String createEvent (@ RequestParam String eventName ) {
32- events .add (eventName );
32+ public String createEvent (@ RequestParam String eventName ,
33+ @ RequestParam String eventDescription ) {
34+ events .add (new Event (eventName , eventDescription ));
3335 return "redirect:/events" ;
3436 }
3537
Original file line number Diff line number Diff line change 11package org .launchcode .codingevents .models ;
22
33public class Event {
4+
5+ private String name ;
6+
7+ private String description ;
8+
9+ public Event (String name , String description ) {
10+ this .name = name ;
11+ this .description = description ;
12+ }
13+
14+ public String getName () {
15+ return name ;
16+ }
17+
18+ public void setName (String name ) {
19+ this .name = name ;
20+ }
21+
22+ public String getDescription () {
23+ return description ;
24+ }
25+
26+ public void setDescription (String description ) {
27+ this .description = description ;
28+ }
29+
30+ @ Override
31+ public String toString () {
32+ return "Event{" +
33+ "name='" + name + '\'' +
34+ ", description='" + description + '\'' +
35+ '}' ;
36+ }
437}
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ <h1>Create Event</h1>
1313 < input type ="text " name ="eventName " class ="form-control ">
1414 </ label >
1515 </ div >
16+ < div class ="form-group ">
17+ < label > Description
18+ < input type ="text " name ="eventDescription " class ="form-control ">
19+ </ label >
20+ </ div >
1621 < div class ="form-group ">
1722 < input type ="submit " value ="Create Event " class ="btn btn-success ">
1823 </ div >
Original file line number Diff line number Diff line change @@ -9,15 +9,19 @@ <h1>All Events</h1>
99
1010< p th:unless ="${events} and ${events.size()} "> No events!</ p >
1111
12- < table >
12+ < table class =" table table-striped " >
1313 < thead >
1414 < tr >
1515 < th > Name</ th >
16+ < th > Description</ th >
1617 </ tr >
1718 </ thead >
19+ < tbody >
1820 < tr th:each ="event : ${events} ">
19- < td th:text ="${event} "> </ td >
21+ < td th:text ="${event.name} "> </ td >
22+ < td th:text ="${event.description} "> </ td >
2023 </ tr >
24+ </ tbody >
2125</ table >
2226
2327</ body >
You can’t perform that action at this time.
0 commit comments