Commit cd13a168 authored by Andy Wilkinson's avatar Andy Wilkinson

Align HATEAOS sample with latest breaking API changes

See gh-15939
parent 66f00c20
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -19,10 +19,10 @@ package sample.hateoas.web;
import sample.hateoas.domain.Customer;
import sample.hateoas.domain.CustomerRepository;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.ExposesResourceFor;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.server.ExposesResourceFor;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
......@@ -47,16 +47,17 @@ public class CustomerController {
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
HttpEntity<Resources<Customer>> showCustomers() {
Resources<Customer> resources = new Resources<>(this.repository.findAll());
HttpEntity<CollectionModel<Customer>> showCustomers() {
CollectionModel<Customer> resources = new CollectionModel<>(
this.repository.findAll());
resources.add(this.entityLinks.linkToCollectionResource(Customer.class));
return new ResponseEntity<>(resources, HttpStatus.OK);
}
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
HttpEntity<Resource<Customer>> showCustomer(@PathVariable Long id) {
Resource<Customer> resource = new Resource<>(this.repository.findOne(id));
resource.add(this.entityLinks.linkToSingleResource(Customer.class, id));
HttpEntity<EntityModel<Customer>> showCustomer(@PathVariable Long id) {
EntityModel<Customer> resource = new EntityModel<>(this.repository.findOne(id));
resource.add(this.entityLinks.linkToItemResource(Customer.class, id));
return new ResponseEntity<>(resource, HttpStatus.OK);
}
......
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