Skip to content

Commit dffd001

Browse files
committed
completed adding a unique ID
1 parent 13699bb commit dffd001

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

  • Spring Boot/codingevents/src/main

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
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;
9+
510
private String name;
611
private String description;
712

813
public Event(String name, String description) {
914
this.name = name;
1015
this.description = description;
16+
this.id = nextId;
17+
nextId++;
1118
}
1219

1320
public String getName() {
@@ -26,8 +33,25 @@ public void setDescription(String description) {
2633
this.description = description;
2734
}
2835

36+
public int getId() {
37+
return id;
38+
}
39+
2940
@Override
3041
public String toString() {
3142
return name;
3243
}
44+
45+
@Override
46+
public boolean equals(Object o) {
47+
if (this == o) return true;
48+
if (o == null || getClass() != o.getClass()) return false;
49+
Event event = (Event) o;
50+
return id == event.id;
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(id);
56+
}
3357
}

Spring Boot/codingevents/src/main/resources/templates/events/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ <h1>All Events</h1>
1010
<table class="table table-striped">
1111
<thead>
1212
<tr>
13+
<th>ID</th>
1314
<th>Name</th>
1415
<th>Description</th>
1516
</tr>
1617
</thead>
1718
<tr th:each="event : ${events}">
19+
<td th:text="${event.id}"> </td>
1820
<td th:text="${event.name}"></td>
1921
<td th:text="${event.description}"></td>
2022
</tr>

0 commit comments

Comments
 (0)