Skip to content

Commit 0461427

Browse files
committed
updated
1 parent b91fd19 commit 0461427

5 files changed

Lines changed: 45 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jakarta.validation.Valid;
44
import org.launchcode.codingevents.data.EventData;
55
import org.launchcode.codingevents.models.Event;
6+
import org.launchcode.codingevents.models.EventType;
67
import org.springframework.stereotype.Controller;
78
import org.springframework.validation.Errors;
89
import org.springframework.web.bind.annotation.*;
@@ -29,6 +30,7 @@ public String displayAllEvents(Model model) {
2930
public String displayCreateEventForm(Model model) {
3031
model.addAttribute("title", "Create Event");
3132
model.addAttribute("event", new Event());
33+
model.addAttribute("types", EventType.values());
3234
return "events/create";
3335
}
3436

src/main/java/org/launchcode/codingevents/models/Event.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,29 @@ public class Event {
1818
@Email(message = "Invalid email. Try again.")
1919
private String contactEmail;
2020

21-
public Event(String name, String description,String contactEmail) {
21+
private EventType type;
22+
23+
24+
25+
public Event(String name, String description, String contactEmail, EventType type) {
2226
this();
2327
this.name = name;
2428
this.description = description;
2529
this.contactEmail = contactEmail;
26-
this.id = nextId;
27-
nextId++;
30+
this.type = type;
31+
2832
}
2933
public Event() {
3034
this.id = nextId;
3135
nextId++;
3236
}
37+
public EventType getType() {
38+
return type;
39+
}
3340

41+
public void setType(EventType type) {
42+
this.type = type;
43+
}
3444
public String getName() {
3545
return name;
3646
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.launchcode.codingevents.models;
2+
3+
public enum EventType {
4+
CONFERENCE("Conference"),
5+
MEETUP("Meetup"),
6+
WORKSHOP("Workshop"),
7+
SOCIAL("Social");;
8+
9+
private final String displayName;
10+
11+
EventType(String displayName) {
12+
this.displayName = displayName;
13+
}
14+
15+
public String getDisplayName() {
16+
return displayName;
17+
}
18+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
</label>
2626
<p class="error" th:errors="${event.contactEmail}"></p>
2727
</div>
28+
<div class="form-group">
29+
<label> Type
30+
<select th:field="${event.type}">
31+
<option th:each="type : ${types}"
32+
th:value="${type}"
33+
th:text="${type.displayName}"
34+
></option>
35+
</select>
36+
</label>
37+
</div>
2838
<div class="form-group">
2939
<input type="submit" value="Create" class="btn btn-success" />
3040
</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
<th>Name</th>
1313
<th>Description</th>
1414
<th>Contact Email</th>
15+
<th>Type</th>
1516
</tr>
1617
</thead>
1718
<tr th:each="event : ${events}">
1819
<td th:text="${event.id}"></td>
1920
<td th:text="${event.name}"></td>
2021
<td th:text="${event.description}"></td>
2122
<td th:text="${event.contactEmail}"></td>
23+
<td th:text="${event.type.displayName}"</td>
2224
</tr>
2325
</table>
2426

0 commit comments

Comments
 (0)