Skip to content

Commit ae31bca

Browse files
committed
adding model identifier
1 parent 805a136 commit ae31bca

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package org.launchcode.codingevents.models;
22

3+
import java.util.Objects;
4+
35
public class Event {
46

7+
private int id;
8+
private static int nextId = 1;
59
private String name;
610
private String description;
711

812
public Event(String name, String description) {
913
this.name = name;
1014
this.description = description;
15+
this.id = nextId;
16+
nextId++;
17+
}
18+
19+
public int getId() {
20+
return id;
1121
}
1222

1323
public String getName() {
@@ -30,4 +40,17 @@ public void setDescription(String description) {
3040
public String toString() {
3141
return name;
3242
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
Event event = (Event) o;
49+
return id == event.id;
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
return Objects.hash(id);
55+
}
3356
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
<table class="table table-striped">
1313
<thead>
1414
<tr>
15+
<th>ID</th>
1516
<th>Name</th>
1617
<th>Description</th>
1718
</tr>
1819
</thead>
1920
<tr th:each="event : ${events}">
21+
<td th:text="${event.id}"></td>
2022
<td th:text="${event.name}"></td>
2123
<td th:text="${event.description}"></td>
2224
</tr>

0 commit comments

Comments
 (0)