Skip to content

Commit 5dbecbc

Browse files
committed
enums
1 parent ee31a43 commit 5dbecbc

5 files changed

Lines changed: 47 additions & 1 deletion

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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ public class Event {
2222
@Email(message = "Invalid Email. Please try again.")
2323
private String contactEmail;
2424

25-
public Event(String name, String description, String contactEmail) {
25+
private EventType type;
26+
27+
public Event(String name, String description, String contactEmail, EventType type) {
2628
this();
2729
this.name = name;
2830
this.description = description;
2931
this.contactEmail = contactEmail;
32+
this.type = type;
3033
}
3134

3235
public Event(){
@@ -58,6 +61,14 @@ public void setContactEmail(String contactEmail) {
5861
this.contactEmail = contactEmail;
5962
}
6063

64+
public EventType getType() {
65+
return type;
66+
}
67+
68+
public void setType(EventType type) {
69+
this.type = type;
70+
}
71+
6172
public int getId() {
6273
return id;
6374
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.launchcode.codingevents.models;
2+
3+
public enum EventType {
4+
5+
CONFERENCE("Conference"),
6+
MEETUP("Meetup"),
7+
WORKSHOP("Workshop"),
8+
SOCIAL("Social");
9+
10+
private final String displayName;
11+
12+
EventType(String displayName) {
13+
this.displayName = displayName;
14+
}
15+
16+
public String getDisplayName() {
17+
return displayName;
18+
}
19+
20+
21+
}

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><br>
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
@@ -14,13 +14,15 @@
1414
<th>Name</th>
1515
<th>Description</th>
1616
<th>Contact Email</th>
17+
<th>Type</th>
1718
</tr>
1819
</thead>
1920
<tr th:each="event : ${events}">
2021
<td th:text="${event.id}"></td>
2122
<td th:text="${event.name}"></td>
2223
<td th:text="${event.description}"></td>
2324
<td th:text="${event.contactEmail}"></td>
25+
<td th:text="${event.type.displayName}"></td>
2426
</tr>
2527
</table>
2628

0 commit comments

Comments
 (0)