Commit 7f244aaa by Patryk Czarnik

ROrders i RCustomers - poprawki w modelu, aby to działało

parent aff1fefa
......@@ -18,10 +18,10 @@ repositories {
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-security'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
......
package sklep.model;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
import java.time.Instant;
import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.hibernate.annotations.ColumnDefault;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
@Entity
@Table(name = "orders")
public class Order {
......@@ -27,8 +40,8 @@ public class Order {
@Column(name = "delivery_date")
private LocalDate deliveryDate;
@OneToMany(mappedBy = "order")
private Set<OrderProduct> orderProducts = new LinkedHashSet<>();
@OneToMany(mappedBy="order", fetch=FetchType.EAGER)
private List<OrderProduct> orderProducts = new ArrayList<>();
public Integer getId() {
return id;
......@@ -62,11 +75,11 @@ public class Order {
this.deliveryDate = deliveryDate;
}
public Set<OrderProduct> getOrderProducts() {
public List<OrderProduct> getOrderProducts() {
return orderProducts;
}
public void setOrderProducts(Set<OrderProduct> orderProducts) {
public void setOrderProducts(List<OrderProduct> orderProducts) {
this.orderProducts = orderProducts;
}
......
......@@ -16,13 +16,13 @@ public class OrderProduct {
private OrderProductPK id;
@MapsId("orderId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@ManyToOne
@JoinColumn(name = "order_id", nullable = false)
@JsonIgnore
private Order order;
@MapsId("productId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@ManyToOne
@JoinColumn(name = "product_id", nullable = false)
private Product product;
......
......@@ -15,6 +15,7 @@ public class JerseyConfig extends ResourceConfig {
register(Kalkulator.class);
register(RProducts.class);
register(ROrders.class);
register(RCustomers.class);
}
}
......@@ -3,6 +3,8 @@ package sklep.rest;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
......@@ -21,6 +23,7 @@ import sklep.repository.CustomerRepository;
@Produces({ "application/xml", "application/json", "text/plain"})
@Consumes({ "application/xml", "application/json" })
public class RCustomers {
@Autowired
private CustomerRepository customerRepository;
@POST
......
......@@ -5,3 +5,4 @@ spring.datasource.username=alx
spring.datasource.password=abc123
alx.photo_dir=/home/patryk/sklep/foto
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
\ No newline at end of file
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