Skip to content

Commit 352cb33

Browse files
committed
updated
1 parent 08083a8 commit 352cb33

6 files changed

Lines changed: 74 additions & 188 deletions

File tree

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,21 @@
11
package org.launchcode.codingevents.models;
22

3-
import jakarta.persistence.Entity;
43
import jakarta.persistence.GeneratedValue;
54
import jakarta.persistence.Id;
65
import jakarta.persistence.MappedSuperclass;
7-
import jakarta.validation.constraints.Email;
8-
import jakarta.validation.constraints.NotBlank;
9-
import jakarta.validation.constraints.Size;
106

117
import java.util.Objects;
12-
@Entity
138

9+
@MappedSuperclass
10+
public abstract class AbstractEntity {
1411

15-
public class AbstractEntity {
12+
@Id
13+
@GeneratedValue
14+
private int id;
1615

17-
18-
19-
20-
@Id
21-
@GeneratedValue
22-
private int id;
23-
private static int nextId = 1;
24-
@NotBlank
25-
@Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters")
26-
private String name;
27-
@Size(max = 500, message = "Description too long!")
28-
private String description;
29-
30-
@Email(message = "Invalid email. Try again.")
31-
private String contactEmail;
32-
33-
private EventType type;
34-
35-
36-
37-
public AbstractEntity(String name, String description, String contactEmail, EventType type) {
38-
this();
39-
this.name = name;
40-
this.description = description;
41-
this.contactEmail = contactEmail;
42-
this.type = type;
43-
44-
}
45-
public AbstractEntity() {
46-
this.id = nextId;
47-
nextId++;
48-
}
49-
public EventType getType() {
50-
return type;
51-
}
52-
53-
public void setType(EventType type) {
54-
this.type = type;
55-
}
56-
public String getName() {
57-
return name;
58-
}
59-
60-
public void setName(String name) {
61-
this.name = name;
62-
}
63-
64-
public String getDescription() {
65-
return description;
66-
}
67-
68-
public void setDescription(String description) {
69-
this.description = description;
70-
}
71-
72-
public int getId() {
73-
return id;
74-
}
75-
76-
public String getContactEmail() {
77-
return contactEmail;
78-
}
79-
80-
public void setContactEmail(String contactEmail) {
81-
this.contactEmail = contactEmail;
82-
}
83-
84-
@Override
85-
public String toString() {
86-
return name;
87-
}
16+
public int getId() {
17+
return id;
18+
}
8819

8920
@Override
9021
public boolean equals(Object o) {
@@ -94,10 +25,9 @@ public boolean equals(Object o) {
9425
return id == entity.id;
9526
}
9627

97-
@Override
98-
public int hashCode() {
99-
return Objects.hash(id);
100-
}
28+
@Override
29+
public int hashCode() {
30+
return Objects.hash(id);
10131
}
10232

103-
33+
}
Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
package org.launchcode.codingevents.models;
22

33
import jakarta.persistence.Entity;
4-
import jakarta.persistence.GeneratedValue;
5-
import jakarta.persistence.Id;
64
import jakarta.validation.constraints.Email;
75
import jakarta.validation.constraints.NotBlank;
86
import jakarta.validation.constraints.Size;
97

10-
import java.util.Objects;
8+
/**
9+
* Created by Chris Bay
10+
*/
1111
@Entity
12-
public class Event extends AbstractEntity {
13-
/* @Id
14-
@GeneratedValue
15-
private int id;
16-
private static int nextId = 1;
17-
@NotBlank
18-
@Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters")
19-
private String name;
20-
@Size(max = 500, message = "Description too long!")
21-
private String description;
12+
public class Event extends AbstractEntity {
2213

23-
@Email(message = "Invalid email. Try again.")
24-
private String contactEmail;
14+
@NotBlank(message = "Name is required")
15+
@Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters")
16+
private String name;
2517

26-
private EventType type;
18+
@Size(max = 500, message = "Description too long!")
19+
private String description;
2720

21+
@NotBlank(message = "Email is required")
22+
@Email(message = "Invalid email. Try again.")
23+
private String contactEmail;
2824

25+
private EventType type;
2926

3027
public Event(String name, String description, String contactEmail, EventType type) {
31-
this();
3228
this.name = name;
3329
this.description = description;
3430
this.contactEmail = contactEmail;
3531
this.type = type;
36-
37-
}
38-
public Event() {
39-
this.id = nextId;
40-
nextId++;
41-
}
42-
public EventType getType() {
43-
return type;
4432
}
4533

46-
public void setType(EventType type) {
47-
this.type = type;
34+
public Event() {}
35+
36+
public String getName() {
37+
return name;
4838
}
49-
public String getName() {
50-
return name;
51-
}
5239

53-
public void setName(String name) {
54-
this.name = name;
55-
}
40+
public void setName(String name) {
41+
this.name = name;
42+
}
5643

5744
public String getDescription() {
5845
return description;
@@ -62,10 +49,6 @@ public void setDescription(String description) {
6249
this.description = description;
6350
}
6451

65-
public int getId() {
66-
return id;
67-
}
68-
6952
public String getContactEmail() {
7053
return contactEmail;
7154
}
@@ -74,21 +57,17 @@ public void setContactEmail(String contactEmail) {
7457
this.contactEmail = contactEmail;
7558
}
7659

77-
@Override
78-
public String toString() {
79-
return name;
80-
}
60+
public EventType getType() {
61+
return type;
62+
}
8163

82-
@Override
83-
public boolean equals(Object o) {
84-
if (this == o) return true;
85-
if (o == null || getClass() != o.getClass()) return false;
86-
Event event = (Event) o;
87-
return id == event.id;
64+
public void setType(EventType type) {
65+
this.type = type;
8866
}
8967

9068
@Override
91-
public int hashCode() {
92-
return Objects.hash(id);
93-
}*/
94-
}
69+
public String toString() {
70+
return name;
71+
}
72+
73+
}
Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,33 @@
11
package org.launchcode.codingevents.models;
22

33
import jakarta.persistence.Entity;
4-
import jakarta.persistence.GeneratedValue;
5-
import jakarta.persistence.Id;
64
import jakarta.validation.constraints.Size;
75

8-
import java.util.Objects;
6+
/**
7+
* Created by Chris Bay
8+
*/
9+
@Entity
10+
public class EventCategory extends AbstractEntity {
911

12+
@Size(min=3, message="Name must be at least 3 characters long")
13+
private String name;
1014

11-
@Entity
12-
public class EventCategory extends AbstractEntity {
15+
public EventCategory(@Size(min = 3, message = "Name must be at least 3 characters long") String name) {
16+
this.name = name;
17+
}
1318

14-
/* @Id
15-
@GeneratedValue
16-
private int id;
19+
public EventCategory() {}
1720

18-
@Size(min=3, message="Name must be at least 3 characters long")
19-
private String name;
21+
public String getName() {
22+
return name;
23+
}
2024

21-
public EventCategory(@Size(min = 3, message = "Name must be at least 3 characters long") String name) {
22-
this.name = name;
23-
}
25+
public void setName(String name) {
26+
this.name = name;
27+
}
2428

25-
public EventCategory() {}
26-
27-
public String getName() {
28-
return name;
29-
}
30-
31-
public void setName(String name) {
32-
this.name = name;
33-
}
34-
35-
public int getId() {
36-
return id;
37-
}
38-
39-
@Override
40-
public String toString() {
41-
return name;
42-
}
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-
EventCategory that = (EventCategory) o;
49-
return id == that.id;
50-
}
51-
52-
@Override
53-
public int hashCode() {
54-
return Objects.hash(id);
55-
}*/
56-
57-
}
29+
@Override
30+
public String toString() {
31+
return name;
32+
}
33+
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
<header th:replace="fragments :: header"></header>
77

88
<p th:text="${errorMsg}" style="color:red;"></p>
9+
910
<form method="post">
1011
<div class="form-group">
1112
<label>Name
12-
<input type="text" th:field="${event.name}" class="form-control" />
13+
<input th:field="${event.name}" class="form-control">
1314
</label>
1415
<p class="error" th:errors="${event.name}"></p>
1516
</div>
1617
<div class="form-group">
1718
<label>Description
18-
<input type="text" th:field="${event.description}" class="form-control" />
19+
<input th:field="${event.description}" class="form-control">
1920
</label>
2021
<p class="error" th:errors="${event.description}"></p>
2122
</div>
2223
<div class="form-group">
2324
<label>Contact Email
24-
<input type="text" th:field="${event.contactEmail}" class="form-control" />
25+
<input th:field="${event.contactEmail}" class="form-control">
2526
</label>
2627
<p class="error" th:errors="${event.contactEmail}"></p>
2728
</div>
2829
<div class="form-group">
29-
<label> Type
30+
<label>Type
3031
<select th:field="${event.type}">
3132
<option th:each="type : ${types}"
3233
th:value="${type}"
@@ -36,7 +37,7 @@
3637
</label>
3738
</div>
3839
<div class="form-group">
39-
<input type="submit" value="Create" class="btn btn-success" />
40+
<input type="submit" value="Create" class="btn btn-success">
4041
</div>
4142
</form>
4243

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</div>
1717
</th:block>
1818

19-
<input type="submit" value="Delete Selected Events" class="btn btn-danger">
19+
<input type="submit" value="Delete" class="btn btn-danger">
2020
</form>
2121

2222
</body>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
22
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
3-
<head th:replace="fragments :: head"></head>
3+
<head th:replace="~{fragments :: head}"></head>
44
<body class="container">
55

6-
<header th:replace="fragments :: header"></header>
6+
<header th:replace="~{fragments :: header}"></header>
77

88
<table class="table table-striped">
99
<thead>
@@ -20,7 +20,7 @@
2020
<td th:text="${event.name}"></td>
2121
<td th:text="${event.description}"></td>
2222
<td th:text="${event.contactEmail}"></td>
23-
<td th:text="${event.type.displayName}"</td>
23+
<td th:text="${event.type.displayName}"></td>
2424
</tr>
2525
</table>
2626

0 commit comments

Comments
 (0)