Skip to content

Commit

Permalink
lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
Celebes committed Nov 7, 2019
1 parent 64eddca commit 8521777
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package guru.springframework.sfgpetclinic.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

@MappedSuperclass
@EqualsAndHashCode
@Getter
@Setter
public abstract class BaseEntity implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,32 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import java.util.HashSet;
import java.util.Set;

@Entity
@Getter
@Setter
public class Owner extends Person {

private String address;

private String city;

private String telephone;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
private Set<Pet> pets = new HashSet<>();

public Owner() {
}

public Owner(String firstName, String lastName, String address, String city, String telephone) {
super(firstName, lastName);
this.address = address;
this.city = city;
this.telephone = telephone;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getTelephone() {
return telephone;
}

public void setTelephone(String telephone) {
this.telephone = telephone;
}

public Set<Pet> getPets() {
return pets;
}

public void setPets(Set<Pet> pets) {
this.pets = pets;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

@MappedSuperclass
@Getter
@Setter
@NoArgsConstructor
public abstract class Person extends BaseEntity {

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

protected Person() {
}

protected Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -11,6 +15,9 @@
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Pet extends BaseEntity {

private String name;
Expand All @@ -29,43 +36,4 @@ public class Pet extends BaseEntity {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet")
private Set<Visit> visits = new HashSet<>();

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public PetType getPetType() {
return petType;
}

public void setPetType(PetType petType) {
this.petType = petType;
}

public Owner getOwner() {
return owner;
}

public void setOwner(Owner owner) {
this.owner = owner;
}

public LocalDate getBirthDate() {
return birthDate;
}

public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}

public Set<Visit> getVisits() {
return visits;
}

public void setVisits(Set<Visit> visits) {
this.visits = visits;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class PetType extends BaseEntity {

private String name;

public PetType() {
}

public PetType(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Speciality extends BaseEntity {
private String description;

public Speciality() {
}
private String description;

public Speciality(String description) {
this.description = description;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
Expand All @@ -9,23 +13,17 @@
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Vet extends Person {

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), inverseJoinColumns = @JoinColumn(name = "speciality_id"))
private Set<Speciality> specialities = new HashSet<>();

public Vet() {
}

public Vet(String firstName, String lastName) {
super(firstName, lastName);
}

public Set<Speciality> getSpecialities() {
return specialities;
}

public void setSpecialities(Set<Speciality> specialities) {
this.specialities = specialities;
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
package guru.springframework.sfgpetclinic.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.time.LocalDate;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Visit extends BaseEntity {

private LocalDate date;

private String description;

@ManyToOne
@JoinColumn(name = "pet_id")
private Pet pet;

public LocalDate getDate() {
return date;
}

public void setDate(LocalDate date) {
this.date = date;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Pet getPet() {
return pet;
}

public void setPet(Pet pet) {
this.pet = pet;
}
}
6 changes: 6 additions & 0 deletions pet-clinic-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
</dependency>
<!-- end of webjars -->

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package guru.springframework.sfgpetclinic.controllers;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
@Slf4j
class CrashController {

@GetMapping("/oups")
public String triggerException() {
log.error("Error, but it's ok since it was done on purpose lololol");
throw new RuntimeException("Expected: controller used to showcase what happens when an exception is thrown");
}

Expand Down
Loading

0 comments on commit 8521777

Please sign in to comment.