I have one simple web application in JAVA and angularjs. Where users can add persons to app and remove them from mongo database.
My problem is, I don't know exactly how angular communicates with java and calls Java functions. For example if i want to delete a person from my database after a button click.
here's some code
persons.html
<a for-authenticated ng-click="remove(s.id)" href=""> <i
class="pull-right glyphicon glyphicon-remove"></i>
</a>
app.js
var app = angular.module('conferenceApplication', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
'ui.bootstrap',
'angularFileUpload',
'ngQuickDate']);
app.config(function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: '/partials/home.html',
controller: 'HomeCtrl'
})
.when('/speakers', {
templateUrl: '/partials/person-list.html',
controller: 'PersonListCtrl'
})
});
app.controller('PersonListCtrl', function ($scope,$http, $modal, $log, $route, PersonService) {
$scope.remove = function(id) {
var deletedPerson = id ? PersonService.remove(id, function(resp){
deletedPerson = resp;
}) : {};
};
}
PersonService.js
app.service('PersonService', function ($log, $upload, PersonResource) {
this.getById = function (id, callback) {
return PersonResource.get({personId: id}, callback);
};
this.remove = function(id, callback) {
return PersonResource.deleteObject({PersonId: id}, callback);
}
}
PersonResource.js
app.factory('PersonResource', function ($resource) {
return $resource('rest/person/:personId',
{
personId: '@personId'
},
{
'update': { method: 'PUT' }
})
});
also i have a java class where i want to delete this person from database
PersonResource.java
@Controller
@RequestMapping("/person")
public class PersonResource {
@Autowired
private PersonService personService;
@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ResponseEntity<Person> deleteObject(@RequestBody Person id) {
Person person = personService.findById(id);
personService.deleteObject(id);
return new ResponseEntity<Person>(person, HttpStatus.ACCEPTED);
}
}
PersonRepository
@Override
public void deleteObject(String id) {
getTemplate().remove(new Query(Criteria.where("id").is(id)), Person.class);
}
the getTemplate() returns MongoTemplate.
Can anyone tell me what i am doing wrong to get my entry deleted from database ?