Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Editing pass and version upgrade
Browse files Browse the repository at this point in the history
I edited all the readme files (and added callouts, as comments, to several code files). I also upgraded the Spring Boot version to 2.2.4 (the latest) and dealt with the resulting breaking changes in org.springframework.hateoas.
  • Loading branch information
Jay Bryant authored and gregturn committed Feb 13, 2020
1 parent eb2e93c commit 5b4d3e4
Show file tree
Hide file tree
Showing 21 changed files with 571 additions and 425 deletions.
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

= React.js and Spring Data REST

This tutorial shows a collection of apps that use Spring Data REST and its powerful backend functionality combined with React's sophisticated features to build an easy-to-grok UI.
This tutorial shows a collection of apps that use Spring Data REST and its powerful backend functionality, combined with React's sophisticated features to build an easy-to-understand UI.

* https://www.youtube.com/watch?v=TgCr7v9tdKM[Spring Data REST] provides a fast way to build hypermedia-powered repositories.
* https://facebook.github.io/react/index.html[React] is Facebook's solution to efficient, fast, and easy-to-use views in the land of JavaScript.
* https://facebook.github.io/react/index.html[React] is Facebook's solution to efficient, fast, and easy-to-use views in JavaScript.

include::basic/README.adoc[leveloffset=+1]
include::hypermedia/README.adoc[leveloffset=+1]
Expand Down
257 changes: 152 additions & 105 deletions basic/README.adoc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
* @author Greg Turnquist
*/
// tag::code[]
@Component
public class DatabaseLoader implements CommandLineRunner {
@Component // <1>
public class DatabaseLoader implements CommandLineRunner { // <2>

private final EmployeeRepository repository;

@Autowired
@Autowired // <3>
public DatabaseLoader(EmployeeRepository repository) {
this.repository = repository;
}

@Override
public void run(String... strings) throws Exception {
public void run(String... strings) throws Exception { // <4>
this.repository.save(new Employee("Frodo", "Baggins", "ring bearer"));
}
}
// end::code[]
// end::code[]
6 changes: 3 additions & 3 deletions basic/src/main/java/com/greglturnquist/payroll/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
* @author Greg Turnquist
*/
// tag::code[]
@Entity
@Entity // <1>
public class Employee {

private @Id @GeneratedValue Long id;
private @Id @GeneratedValue Long id; // <2>
private String firstName;
private String lastName;
private String description;
Expand Down Expand Up @@ -100,4 +100,4 @@ public String toString() {
'}';
}
}
// end::code[]
// end::code[]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Greg Turnquist
*/
// tag::code[]
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
public interface EmployeeRepository extends CrudRepository<Employee, Long> { // <1>

}
// end::code[]
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
* @author Greg Turnquist
*/
// tag::code[]
@Controller
@Controller // <1>
public class HomeController {

@RequestMapping(value = "/")
@RequestMapping(value = "/") // <2>
public String index() {
return "index";
return "index"; // <3>
}

}
// end::code[]
// end::code[]
13 changes: 6 additions & 7 deletions basic/src/main/js/app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
'use strict';

// tag::vars[]
const React = require('react');
const ReactDOM = require('react-dom');
const client = require('./client');
const React = require('react'); // <1>
const ReactDOM = require('react-dom'); // <2>
const client = require('./client'); // <3>
// end::vars[]

// tag::app[]
class App extends React.Component {
class App extends React.Component { // <1>

constructor(props) {
super(props);
this.state = {employees: []};
}

componentDidMount() {
componentDidMount() { // <2>
client({method: 'GET', path: '/api/employees'}).done(response => {
this.setState({employees: response.entity._embedded.employees});
});
}

render() {
render() { // <3>
return (
<EmployeeList employees={this.state.employees}/>
)
Expand Down Expand Up @@ -70,4 +70,3 @@ ReactDOM.render(
document.getElementById('react')
)
// end::render[]

107 changes: 64 additions & 43 deletions conditional/README.adoc

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions conditional/src/main/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class App extends React.Component {

// tag::follow-2[]
loadFromServer(pageSize) {
follow(client, root, [
follow(client, root, [ // <1>
{rel: 'employees', params: {size: pageSize}}]
).then(employeeCollection => {
).then(employeeCollection => { // <2>
return client({
method: 'GET',
path: employeeCollection.entity._links.profile.href,
Expand All @@ -35,16 +35,16 @@ class App extends React.Component {
this.links = employeeCollection.entity._links;
return employeeCollection;
});
}).then(employeeCollection => {
}).then(employeeCollection => { // <3>
return employeeCollection.entity._embedded.employees.map(employee =>
client({
method: 'GET',
path: employee._links.self.href
})
);
}).then(employeePromises => {
}).then(employeePromises => { // <4>
return when.all(employeePromises);
}).done(employees => {
}).done(employees => { // <5>
this.setState({
employees: employees,
attributes: Object.keys(this.schema.properties),
Expand Down
118 changes: 67 additions & 51 deletions events/README.adoc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.data.rest.core.annotation.HandleAfterDelete;
import org.springframework.data.rest.core.annotation.HandleAfterSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.hateoas.EntityLinks;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

Expand All @@ -31,10 +31,10 @@
*/
// tag::code[]
@Component
@RepositoryEventHandler(Employee.class)
@RepositoryEventHandler(Employee.class) // <1>
public class EventHandler {

private final SimpMessagingTemplate websocket;
private final SimpMessagingTemplate websocket; // <2>

private final EntityLinks entityLinks;

Expand All @@ -44,19 +44,19 @@ public EventHandler(SimpMessagingTemplate websocket, EntityLinks entityLinks) {
this.entityLinks = entityLinks;
}

@HandleAfterCreate
@HandleAfterCreate // <3>
public void newEmployee(Employee employee) {
this.websocket.convertAndSend(
MESSAGE_PREFIX + "/newEmployee", getPath(employee));
}

@HandleAfterDelete
@HandleAfterDelete // <3>
public void deleteEmployee(Employee employee) {
this.websocket.convertAndSend(
MESSAGE_PREFIX + "/deleteEmployee", getPath(employee));
}

@HandleAfterSave
@HandleAfterSave // <3>
public void updateEmployee(Employee employee) {
this.websocket.convertAndSend(
MESSAGE_PREFIX + "/updateEmployee", getPath(employee));
Expand All @@ -68,7 +68,7 @@ public void updateEmployee(Employee employee) {
* @param employee
*/
private String getPath(Employee employee) {
return this.entityLinks.linkForSingleResource(employee.getClass(),
return this.entityLinks.linkForItemResource(employee.getClass(),
employee.getId()).toUri().getPath();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
*/
// tag::code[]
@Component
@EnableWebSocketMessageBroker
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer {
@EnableWebSocketMessageBroker // <1>
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { // <2>

static final String MESSAGE_PREFIX = "/topic";
static final String MESSAGE_PREFIX = "/topic"; // <3>

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
public void registerStompEndpoints(StompEndpointRegistry registry) { // <4>
registry.addEndpoint("/payroll").withSockJS();
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
public void configureMessageBroker(MessageBrokerRegistry registry) { // <5>
registry.enableSimpleBroker(MESSAGE_PREFIX);
registry.setApplicationDestinationPrefixes("/app");
}
}
// end::code[]
// end::code[]
Loading

0 comments on commit 5b4d3e4

Please sign in to comment.