Commit e22cc28d by Patryk Czarnik

CustomerController i @JsonIgnore

parent dca054b2
......@@ -4,6 +4,8 @@ import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Pattern;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
......@@ -37,6 +39,7 @@ public class Customer implements Serializable {
//bi-directional many-to-one association to Order
@OneToMany(mappedBy="customer")
@JsonIgnore
private List<Order> orders;
public Customer() {
......
......@@ -4,6 +4,8 @@ import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Min;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.math.BigDecimal;
......@@ -29,6 +31,7 @@ public class OrderProduct implements Serializable {
//bi-directional many-to-one association to Order
@ManyToOne
@JoinColumn(name="order_id", insertable=false, updatable=false)
@JsonIgnore
private Order order;
//uni-directional many-to-one association to Product
......
package sklep.rest;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import sklep.model.Order;
import sklep.repository.OrderRepository;
@RestController
@RequestMapping("/orders")
public class OrderController {
@Autowired
private OrderRepository orderRepository;
@GetMapping
public List<Order> readAll() {
return orderRepository.findAll();
}
@GetMapping("/{id}")
public Order readOne(@PathVariable("id") int id) {
Optional<Order> order = orderRepository.findById(id);
if(order.isPresent()) {
return order.get();
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Nie ma zamówienia o numerze " + id);
}
}
}
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