Skip to content

Commit f30f015

Browse files
committed
Added Model and corrected Table format
1 parent 82cc873 commit f30f015

4 files changed

Lines changed: 52 additions & 8 deletions

File tree

src/main/java/org/launchcode/codingevents/controllers/EventController.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.launchcode.codingevents.controllers;
22

3+
import org.launchcode.codingevents.models.Event;
34
import org.springframework.stereotype.Controller;
45
import org.springframework.web.bind.annotation.*;
56
import org.springframework.ui.Model;
@@ -13,23 +14,24 @@
1314
@Controller
1415
@RequestMapping("/events")
1516
public 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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
11
package org.launchcode.codingevents.models;
22

33
public 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
}

src/main/resources/templates/events/create.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

src/main/resources/templates/events/index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)