Skip to content

Commit ae43c5d

Browse files
committed
add-id branch complete
1 parent 9b219da commit ae43c5d

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
*/
88
public class Event {
99

10+
private int id;
11+
private static int nextId = 1;
12+
1013
private String name;
1114
private String description;
1215

1316
public Event(String name, String description) {
1417
this.name = name;
1518
this.description = description;
19+
this.id = nextId;
20+
nextId++;
1621
}
1722

1823
public String getName() {
@@ -31,9 +36,25 @@ public void setDescription(String description) {
3136
this.description = description;
3237
}
3338

39+
public int getId() {
40+
return id;
41+
}
42+
3443
@Override
3544
public String toString() {
3645
return name;
3746
}
3847

48+
@Override
49+
public boolean equals(Object o) {
50+
if (this == o) return true;
51+
if (o == null || getClass() != o.getClass()) return false;
52+
Event event = (Event) o;
53+
return id == event.id;
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return Objects.hash(id);
59+
}
3960
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
<table class="table table-striped">
99
<thead>
1010
<tr>
11+
<th>ID</th>
1112
<th>Name</th>
1213
<th>Description</th>
1314
</tr>
1415
</thead>
1516
<tr th:each="event : ${events}">
17+
<td th:text="${event.id}"></td>
1618
<td th:text="${event.name}"></td>
1719
<td th:text="${event.description}"></td>
1820
</tr>

0 commit comments

Comments
 (0)