Skip to content

Commit bb16808

Browse files
committed
changes for coding events chapter
1 parent e4c3769 commit bb16808

5 files changed

Lines changed: 49 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.*;
@@ -32,6 +33,7 @@ public String displayAllEvents(Model model) {
3233
public String displayCreateEventForm(Model model) {
3334
model.addAttribute("title", "Create Event");
3435
model.addAttribute(new Event());
36+
model.addAttribute("types", EventType.values());
3537

3638
return "events/create";
3739
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ public class Event {
2323

2424
private String contactEmail;
2525

26-
public Event(String name, String description, String contactEmail) {
26+
private EventType type;
27+
28+
public Event(String name, String description, String contactEmail, EventType type) {
29+
this();
2730
this.name = name;
2831
this.description = description;
2932
this.contactEmail = contactEmail;
33+
this.type= type;
34+
35+
}
36+
37+
public Event () {
3038
this.id = nextID;
3139
nextID++;
3240
}
3341

34-
public Event () {}
35-
3642
public String getName() {
3743
return name;
3844
}
@@ -57,6 +63,14 @@ public void setContactEmail(String contactEmail) {
5763
this.contactEmail = contactEmail;
5864
}
5965

66+
public EventType getType() {
67+
return type;
68+
}
69+
70+
public void setType(EventType type) {
71+
this.type = type;
72+
}
73+
6074
public int getId() {
6175
return id;
6276
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
</label>
4343
<p class="error" th:errors="${event.contactEmail}"></p>
4444
</div>
45+
<div class="form-group">
46+
<label>Type
47+
<select th:field="${event.type}">
48+
<option th:each="type : ${types}"
49+
th:value="${type}"
50+
th:text="${type.displayName}"
51+
></option>
52+
</select>
53+
</label>
54+
</div>
4555
<div class="form-group">
4656
<input type="submit" value="Create" class="btn btn-success">
4757
</div>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<td th:text="${event.name}"></td>
4242
<td th:text="${event.description}"></td>
4343
<td th:text="${event.contactEmail}"></td>
44+
<td th:text="${event.type.displayName}"></td>
4445
</tr>
4546
</table>
4647

0 commit comments

Comments
 (0)