Commit d286d9d1 by Patryk Czarnik

Poprawki modelu m.in. aby JSON działał

parent 426f5be8
......@@ -71,11 +71,26 @@ public class Order {
this.orderProducts = orderProducts;
}
/*
TODO [Reverse Engineering] create field to map the 'status' column
Available actions: Define target Java type | Uncomment as is | Remove column mapping
@ColumnDefault("'NEW'::order_status")
@Column(name = "status", columnDefinition = "order_status not null")
private Object status;
*/
@Enumerated(EnumType.STRING)
private Status status;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public enum Status {
NEW,
CONFIRMED,
PAID,
SHIPPED,
DELIVERED,
CLOSED,
RETURNED;
}
}
\ No newline at end of file
......@@ -5,7 +5,9 @@ import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Pattern;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@Entity
......@@ -34,7 +36,9 @@ public class Customer {
@OneToMany(mappedBy = "customer")
@JsonIgnore
private Set<Order> orders = new LinkedHashSet<>();
// W danych klienta zwracanych w JSONie nie będzie listy zamówień.
// Można by pomyśleć o stworzeniu dwóch wersji tej klasy - jedna z zamówieniami, jedna bez.
private List<Order> orders = new ArrayList<>();
public String getCustomerEmail() {
return customerEmail;
......@@ -84,12 +88,25 @@ public class Customer {
this.city = city;
}
public Set<Order> getOrders() {
public List<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
public void setOrders(List<Order> orders) {
this.orders = orders;
}
public Order addOrder(Order order) {
getOrders().add(order);
order.setCustomer(this);
return order;
}
public Order removeOrder(Order order) {
getOrders().remove(order);
order.setCustomer(null);
return order;
}
}
\ No newline at end of file
......@@ -71,11 +71,26 @@ public class Order {
this.orderProducts = orderProducts;
}
/*
TODO [Reverse Engineering] create field to map the 'status' column
Available actions: Define target Java type | Uncomment as is | Remove column mapping
@ColumnDefault("'NEW'::order_status")
@Column(name = "status", columnDefinition = "order_status not null")
private Object status;
*/
@Enumerated(EnumType.STRING)
private Status status;
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public enum Status {
NEW,
CONFIRMED,
PAID,
SHIPPED,
DELIVERED,
CLOSED,
RETURNED;
}
}
\ No newline at end of file
package sklep.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
......@@ -14,6 +15,7 @@ public class OrderProduct {
@MapsId("orderId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "order_id", nullable = false)
@JsonIgnore
private Order order;
@MapsId("productId")
......
......@@ -6,4 +6,6 @@ spring.datasource.url=jdbc:postgresql://localhost/sklep
spring.datasource.username=alx
spring.datasource.password=abc123
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
alx.photo_dir=/home/patryk/sklep/foto
......@@ -35,13 +35,25 @@
<li><a href="/products/2/photo">przykładowe zdjęcie</a></li>
</ul>
<h2>Edycja klienta</h2>
<h2>Klienci</h2>
<ul>
<li><a href="/customers">lista klientów</a>
<li><a href="/customers/new">nowy klient</a>
<li><a href="/customers/ala@example.com/edit">edycja klienta</a>
</ul>
<h2>Zapytania RESTowe</h2>
<ul>
<li><a href="/rest/products">products</a></li>
<li><a href="/rest/products/1">products/1</a></li>
<li><a href="/rest/products/1/price">products/1/price</a></li>
<li><a href="/rest/products/1/photo">products/1/photo</a></li>
<li><a href="/rest/orders">orders</a></li>
<li><a href="/rest/orders/1">orders/1</a></li>
<li><a href="/rest/customers">customers</a></li>
<li><a href="/rest/customers/ala@example.com">customers/ala</a></li>
</ul>
<h2>Alternatywne dostępy do bazy danych</h2>
<ul>
<li><a href="/alt0/products">Dostęp JDBC</a> (klasyczne getConnection)</li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment