Commit 7f244aaa by Patryk Czarnik

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

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