Skip to content

Commit bb75ecf

Browse files
committed
enums addition
1 parent 50e8ec7 commit bb75ecf

5 files changed

Lines changed: 44 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.*;
@@ -27,6 +28,7 @@ public String displayAllEvents(Model model) {
2728
public String displayCreateEventForm(Model model) {
2829
model.addAttribute("title", "Create Event");
2930
model.addAttribute(new Event());
31+
model.addAttribute("types", EventType.values()); //return an array of the 4 types of enums created
3032
return "events/create";
3133
}
3234

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, 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() {
@@ -62,6 +65,14 @@ public void setContactEmail(String contactEmail) {
6265
this.contactEmail = contactEmail;
6366
}
6467

68+
public EventType getType() {
69+
return type;
70+
}
71+
72+
public void setType(EventType type) {
73+
this.type = type;
74+
}
75+
6576
@Override
6677
public String toString() {
6778
return name;
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
@@ -24,6 +24,16 @@
2424
</label>
2525
<p class="error" th:errors="${event.contactEmail}"></p>
2626
</div>
27+
<div class="form-group">
28+
<label>Type
29+
<select th:field="${event.type}">
30+
<option th:each="type : ${types}"
31+
th:value="${type}"
32+
th:text="${type.displayName}">
33+
</option>
34+
</select>
35+
</label>
36+
</div>
2737
<div class="form-group">
2838
<input type="submit" value="Create Event" class="btn btn-success">
2939
</div>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
<th>Name</th>
1717
<th>Description</th>
1818
<th>Contact Email</th>
19+
<th>Type</th>
1920
</tr>
2021
</thead>
2122
<tr th:each="event : ${events}">
2223
<td th:text="${event.id}"></td>
2324
<td th:text="${event.name}"></td>
2425
<td th:text="${event.description}"></td>
2526
<td th:text="${event.contactEmail}"></td>
27+
<td th:text="${event.type.displayName}"></td>
2628
</tr>
2729
</table>
2830

0 commit comments

Comments
 (0)