+
+
\ No newline at end of file
diff --git a/spring-data-rest/src/main/webapp/view/app.js b/spring-data-rest/src/main/webapp/view/app.js
new file mode 100644
index 0000000000..0bdc6e1979
--- /dev/null
+++ b/spring-data-rest/src/main/webapp/view/app.js
@@ -0,0 +1,122 @@
+var app = angular.module('app',[]);
+
+app.controller('UserCRUDCtrl', ['$scope','UserCRUDService', function ($scope,UserCRUDService) {
+
+ $scope.updateUser = function () {
+ UserCRUDService.updateUser($scope.user.id,$scope.user.name,$scope.user.email)
+ .then(function success(response){
+ $scope.message = 'User data updated!';
+ $scope.errorMessage = '';
+ },
+ function error(response){
+ $scope.errorMessage = 'Error updating user!';
+ $scope.message = '';
+ });
+ }
+
+ $scope.getUser = function () {
+ var id = $scope.user.id;
+ UserCRUDService.getUser($scope.user.id)
+ .then(function success(response){
+ $scope.user = response.data;
+ $scope.user.id = id;
+ $scope.message='';
+ $scope.errorMessage = '';
+ },
+ function error (response ){
+ $scope.message = '';
+ if (response.status === 404){
+ $scope.errorMessage = 'User not found!';
+ }
+ else {
+ $scope.errorMessage = "Error getting user!";
+ }
+ });
+ }
+
+ $scope.addUser = function () {
+ if ($scope.user != null && $scope.user.name) {
+ UserCRUDService.addUser($scope.user.name, $scope.user.email)
+ .then (function success(response){
+ $scope.message = 'User added!';
+ $scope.errorMessage = '';
+ },
+ function error(response){
+ $scope.errorMessage = 'Error adding user!';
+ $scope.message = '';
+ });
+ }
+ else {
+ $scope.errorMessage = 'Please enter a name!';
+ $scope.message = '';
+ }
+ }
+
+ $scope.deleteUser = function () {
+ UserCRUDService.deleteUser($scope.user.id)
+ .then (function success(response){
+ $scope.message = 'User deleted!';
+ $scope.user = null;
+ $scope.errorMessage='';
+ },
+ function error(response){
+ $scope.errorMessage = 'Error deleting user!';
+ $scope.message='';
+ })
+ }
+
+ $scope.getAllUsers = function () {
+ UserCRUDService.getAllUsers()
+ .then(function success(response){
+ $scope.users = response.data._embedded.users;
+ $scope.message='';
+ $scope.errorMessage = '';
+ },
+ function error (response ){
+ $scope.message='';
+ $scope.errorMessage = 'Error getting users!';
+ });
+ }
+
+}]);
+
+app.service('UserCRUDService',['$http', function ($http) {
+
+ this.getUser = function getUser(userId){
+ return $http({
+ method: 'GET',
+ url: 'users/'+userId
+ });
+ }
+
+ this.addUser = function addUser(name, email){
+ return $http({
+ method: 'POST',
+ url: 'users',
+ data: {name:name, email:email}
+ });
+ }
+
+ this.deleteUser = function deleteUser(id){
+ return $http({
+ method: 'DELETE',
+ url: 'users/'+id
+ })
+ }
+
+ this.updateUser = function updateUser(id,name,email){
+ return $http({
+ method: 'PATCH',
+ url: 'users/'+id,
+ data: {name:name, email:email}
+ })
+ }
+
+ this.getAllUsers = function getAllUsers(){
+ return $http({
+ method: 'GET',
+ url: 'users'
+ });
+ }
+
+}]);
\ No newline at end of file
diff --git a/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsTest.java b/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsTest.java
index 21a067a645..43b5dd7da6 100644
--- a/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsTest.java
+++ b/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsTest.java
@@ -18,6 +18,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
+import org.json.JSONException;
import static org.junit.Assert.assertEquals;
@@ -37,7 +38,7 @@ public class SpringDataRelationshipsTest {
private static final String AUTHOR_NAME = "George Orwell";
@Test
- public void whenSaveOneToOneRelationship_thenCorrect() {
+ public void whenSaveOneToOneRelationship_thenCorrect() throws JSONException {
Library library = new Library(LIBRARY_NAME);
template.postForEntity(LIBRARY_ENDPOINT, library, Library.class);
@@ -55,7 +56,7 @@ public class SpringDataRelationshipsTest {
}
@Test
- public void whenSaveOneToManyRelationship_thenCorrect() {
+ public void whenSaveOneToManyRelationship_thenCorrect() throws JSONException{
Library library = new Library(LIBRARY_NAME);
template.postForEntity(LIBRARY_ENDPOINT, library, Library.class);
@@ -77,7 +78,7 @@ public class SpringDataRelationshipsTest {
}
@Test
- public void whenSaveManyToManyRelationship_thenCorrect() {
+ public void whenSaveManyToManyRelationship_thenCorrect() throws JSONException{
Author author1 = new Author(AUTHOR_NAME);
template.postForEntity(AUTHOR_ENDPOINT, author1, Author.class);