Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed studio #50

Open
wants to merge 1 commit into
base: add-persistent-category
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.launchcode.codingevents.models;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.Objects;


@MappedSuperclass
public abstract class AbstractEntity {

@Id
@GeneratedValue
private int id;

public int getId() {
return id;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbstractEntity entity = (AbstractEntity) o;
return id == entity.id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
22 changes: 3 additions & 19 deletions src/main/java/org/launchcode/codingevents/models/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
* Created by Chris Bay
*/
@Entity
public class Event {

@Id
@GeneratedValue
private int id;
public class Event extends AbstractEntity{

@NotBlank(message = "Name is required")
@Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters")
Expand Down Expand Up @@ -72,25 +68,13 @@ public void setType(EventType type) {
this.type = type;
}

public int getId() {
return id;
}

@Override
public String toString() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Event event = (Event) o;
return id == event.id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.swing.plaf.nimbus.AbstractRegionPainter;
import javax.validation.constraints.Size;
import java.util.Objects;

/**
* Created by Chris Bay
*/
@Entity
public class EventCategory {

@Id
@GeneratedValue
private int id;
public class EventCategory extends AbstractEntity {

@Size(min=3, message="Name must be at least 3 characters long")
private String name;
Expand All @@ -33,25 +30,10 @@ public void setName(String name) {
this.name = name;
}

public int getId() {
return id;
}

@Override
public String toString() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EventCategory that = (EventCategory) o;
return id == that.id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring.datasource.url=jdbc:mysql://localhost:3306/coding_events_demo
spring.datasource.username=coding_events_demo
spring.datasource.url=jdbc:mysql://localhost:3306/coding_events
spring.datasource.username=coding_events
spring.datasource.password=Learn2code!

# Specify the DBMS
Expand Down