Skip to content

Commit 8abc920

Browse files
committed
enums branch complete
1 parent 5451588 commit 8abc920

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.web.bind.annotation.*;
89
import org.springframework.ui.Model;
@@ -29,6 +30,7 @@ public String displayAllEvents(Model model) {
2930
public String displayCreateEventForm(Model model) {
3031
model.addAttribute("title", "Create Event");
3132
model.addAttribute(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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ public class Event {
2525
@Email(message = "Invalid email. Try again.")
2626
private String contactEmail;
2727

28-
public Event(String name, String description, String contactEmail) {
28+
private EventType type;
29+
30+
public Event(String name, String description, String contactEmail, EventType type) {
2931
this();
3032
this.name = name;
3133
this.description = description;
3234
this.contactEmail = contactEmail;
35+
this.type = type;
3336
}
3437

3538
public Event() {
@@ -61,6 +64,10 @@ public void setContactEmail(String contactEmail) {
6164
this.contactEmail = contactEmail;
6265
}
6366

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

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

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