|
@ -8,15 +8,25 @@ import javax.validation.constraints.Size; |
|
|
import javax.validation.constraints.Pattern; |
|
|
import javax.validation.constraints.Pattern; |
|
|
import javax.validation.constraints.NotNull; |
|
|
import javax.validation.constraints.NotNull; |
|
|
import javax.validation.constraints.NotEmpty; |
|
|
import javax.validation.constraints.NotEmpty; |
|
|
import javax.validation.constraints.PastOrPresent; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
|
|
|
|
//import java.sql.Timestamp; |
|
|
|
|
|
//import javax.validation.constraints.PastOrPresent; |
|
|
|
|
|
|
|
|
import org.springframework.format.annotation.DateTimeFormat; |
|
|
|
|
|
|
|
|
import javax.persistence.Entity; |
|
|
|
|
|
import javax.persistence.GeneratedValue; |
|
|
|
|
|
import javax.persistence.GenerationType; |
|
|
|
|
|
import javax.persistence.Id; |
|
|
|
|
|
|
|
|
|
|
|
@Entity |
|
|
public class Book { |
|
|
public class Book { |
|
|
|
|
|
|
|
|
|
|
|
//////////////////// |
|
|
|
|
|
// Primary key value in database |
|
|
|
|
|
|
|
|
|
|
|
@Id |
|
|
|
|
|
@GeneratedValue(strategy=GenerationType.AUTO) |
|
|
|
|
|
private long id; |
|
|
|
|
|
|
|
|
//////////////////// |
|
|
//////////////////// |
|
|
// Attributes with hard-coded constraints |
|
|
// Attributes with hard-coded constraints |
|
|
|
|
|
|
|
@ -33,9 +43,11 @@ public class Book { |
|
|
private String author; |
|
|
private String author; |
|
|
|
|
|
|
|
|
@NotNull |
|
|
@NotNull |
|
|
@PastOrPresent |
|
|
|
|
|
@DateTimeFormat(pattern = "yyyy") |
|
|
|
|
|
private LocalDate year; |
|
|
|
|
|
|
|
|
//@PastOrPresent |
|
|
|
|
|
//@DateTimeFormat(pattern = "yyyy") |
|
|
|
|
|
// TODO: Prefer Timestamp data type |
|
|
|
|
|
// private Timestamp year; |
|
|
|
|
|
private int year; |
|
|
|
|
|
|
|
|
@NotNull |
|
|
@NotNull |
|
|
@NotEmpty(message = "Please provide an ISBN code for the book") |
|
|
@NotEmpty(message = "Please provide an ISBN code for the book") |
|
@ -46,14 +58,16 @@ public class Book { |
|
|
@NotNull |
|
|
@NotNull |
|
|
@DecimalMin(value = "0.01", message = "Too low price value" ) |
|
|
@DecimalMin(value = "0.01", message = "Too low price value" ) |
|
|
@DecimalMax(value = "999.99", message = "Too high price value") |
|
|
@DecimalMax(value = "999.99", message = "Too high price value") |
|
|
// Keep precision |
|
|
|
|
|
private BigDecimal price; |
|
|
|
|
|
|
|
|
// TODO: Use BigDecimal to keep exact precision? |
|
|
|
|
|
private double price; |
|
|
|
|
|
|
|
|
//////////////////// |
|
|
//////////////////// |
|
|
// Attribute setters |
|
|
// Attribute setters |
|
|
|
|
|
|
|
|
// TODO consider accessibility restrictions? |
|
|
// TODO consider accessibility restrictions? |
|
|
|
|
|
|
|
|
|
|
|
// Id generated automatically |
|
|
|
|
|
|
|
|
public void setTitle(String title) { |
|
|
public void setTitle(String title) { |
|
|
this.title = title; |
|
|
this.title = title; |
|
|
} |
|
|
} |
|
@ -62,7 +76,7 @@ public class Book { |
|
|
this.author = author; |
|
|
this.author = author; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setYear(LocalDate year) { |
|
|
|
|
|
|
|
|
public void setYear(int year) { |
|
|
this.year = year; |
|
|
this.year = year; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -70,7 +84,7 @@ public class Book { |
|
|
this.isbn = isbn; |
|
|
this.isbn = isbn; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setPrice(BigDecimal price) { |
|
|
|
|
|
|
|
|
public void setPrice(double price) { |
|
|
this.price = price; |
|
|
this.price = price; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -79,6 +93,8 @@ public class Book { |
|
|
|
|
|
|
|
|
// TODO consider accessibility restrictions? |
|
|
// TODO consider accessibility restrictions? |
|
|
|
|
|
|
|
|
|
|
|
// Id generated automatically |
|
|
|
|
|
|
|
|
public String getTitle() { |
|
|
public String getTitle() { |
|
|
return title; |
|
|
return title; |
|
|
} |
|
|
} |
|
@ -87,7 +103,7 @@ public class Book { |
|
|
return author; |
|
|
return author; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public LocalDate getYear() { |
|
|
|
|
|
|
|
|
public int getYear() { |
|
|
return year; |
|
|
return year; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -95,25 +111,30 @@ public class Book { |
|
|
return isbn; |
|
|
return isbn; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public BigDecimal getPrice() { |
|
|
|
|
|
|
|
|
public double getPrice() { |
|
|
return price; |
|
|
return price; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//////////////////// |
|
|
//////////////////// |
|
|
// Class constructors |
|
|
// Class constructors |
|
|
|
|
|
|
|
|
public Book() { |
|
|
|
|
|
|
|
|
public Book() {} |
|
|
|
|
|
|
|
|
|
|
|
public Book(String title, String author, int year, String isbn, double price) { |
|
|
|
|
|
// super(); |
|
|
|
|
|
this.title = title; |
|
|
|
|
|
this.author = author; |
|
|
|
|
|
this.year = year; |
|
|
|
|
|
this.isbn = isbn; |
|
|
|
|
|
this.price = price; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ... |
|
|
|
|
|
|
|
|
|
|
|
//////////////////// |
|
|
//////////////////// |
|
|
// Class overrides |
|
|
// Class overrides |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String toString() { |
|
|
public String toString() { |
|
|
// TODO |
|
|
|
|
|
return "N/A (placeholder)"; |
|
|
|
|
|
|
|
|
return this.id + ", " + this.title + ", " + this.author + ", " + this.year + ", " + this.isbn + ", " + this.price; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ... |
|
|
// ... |
|
|