Spring HATEOAS support - multiple links
This commit is contained in:
parent
4ec8015949
commit
cdeb7147b4
|
@ -43,6 +43,8 @@ public class SecurityJavaConfig extends WebSecurityConfigurerAdapter {
|
|||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/api/csrfAttacker*").permitAll()
|
||||
.antMatchers("/api/customers**").permitAll()
|
||||
.antMatchers("/api/customer/**").permitAll()
|
||||
.antMatchers("/api/**").authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
|
|
|
@ -39,9 +39,10 @@ public class CustomerController {
|
|||
for (final Customer customer : allCustomers) {
|
||||
final Link selfLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(CustomerController.class).getCustomerById(customer.getCustomerId())).withSelfRel();
|
||||
customer.add(selfLink);
|
||||
final Link ordersLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(CustomerController.class).getOrdersForCustomer(customer.getCustomerId())).withRel("allOrders");
|
||||
customer.add(ordersLink);
|
||||
|
||||
if (customer.getOrders().values().size() > 0) {
|
||||
final Link ordersLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(CustomerController.class).getOrdersForCustomer(customer.getCustomerId())).withRel("allOrders");
|
||||
customer.add(ordersLink);
|
||||
}
|
||||
for (final Order order : customer.getOrders().values()) {
|
||||
final Link orderLink = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(CustomerController.class).getOrderByIdForCustomer(customer.getCustomerId(), order.getOrderId())).withRel("order");
|
||||
order.add(orderLink);
|
||||
|
|
|
@ -14,15 +14,18 @@ public class CustomerServiceImpl implements CustomerService {
|
|||
private HashMap<String, Customer> customerMap;
|
||||
private HashMap<String, Order> customerOneOrderMap;
|
||||
private HashMap<String, Order> customerTwoOrderMap;
|
||||
private HashMap<String, Order> customerThreeOrderMap;
|
||||
|
||||
public CustomerServiceImpl() {
|
||||
|
||||
customerMap = new HashMap<>();
|
||||
customerOneOrderMap = new HashMap<>();
|
||||
customerTwoOrderMap = new HashMap<>();
|
||||
customerThreeOrderMap = new HashMap<>();
|
||||
|
||||
final Customer customerOne = new Customer("10A", "Jane", "ABC Company");
|
||||
final Customer customerTwo = new Customer("20B", "Bob", "XYZ Company");
|
||||
final Customer customerThree = new Customer("30C", "Tim", "CKV Company");
|
||||
|
||||
customerOneOrderMap.put("001A", new Order("001A", 150.00, 25));
|
||||
customerOneOrderMap.put("002A", new Order("002A", 250.00, 15));
|
||||
|
@ -32,8 +35,10 @@ public class CustomerServiceImpl implements CustomerService {
|
|||
|
||||
customerOne.setOrders(customerOneOrderMap);
|
||||
customerTwo.setOrders(customerTwoOrderMap);
|
||||
customerThree.setOrders(customerThreeOrderMap);
|
||||
customerMap.put("10A", customerOne);
|
||||
customerMap.put("20B", customerTwo);
|
||||
customerMap.put("30C", customerThree);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue