This commit is contained in:
Michele Artini 2022-06-23 12:04:38 +02:00
parent 9c7656e618
commit bbcd58a353
4 changed files with 32 additions and 21 deletions

View File

@ -23,7 +23,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import eu.dnetlib.common.controller.AbstractDnetController;
@ -119,13 +118,13 @@ public class VocabularyRestController extends AbstractDnetController {
}
@PostMapping("/{vocabulary}/terms")
public Iterable<VocabularyTerm> saveTerm(@PathVariable final String vocabulary, @RequestParam final VocabularyTerm term) {
public Iterable<VocabularyTerm> saveTerm(@PathVariable final String vocabulary, @RequestBody final VocabularyTerm term) {
term.setVocabulary(vocabulary);
vocabularyTermRepository.save(term);
return vocabularyTermRepository.findByVocabularyOrderByCode(vocabulary);
}
@DeleteMapping("/{vocabulary}/terms/{termId}")
@DeleteMapping("/{vocabulary}/terms/{term}")
public Iterable<VocabularyTerm> listTerms(@PathVariable final String vocabulary, @PathVariable final String term) {
final VocabularyTermPK pk = new VocabularyTermPK();
pk.setCode(term);

View File

@ -52,7 +52,7 @@ app.controller('vocabulariesController', function($scope, $http) {
$scope.deleteVocabulary = function(id) {
if (confirm("Are you sure ?")) {
$http.delete('./api/vocs/' + id).then(function successCallback(res) {
$http.delete('./api/vocs/' + encodeURIComponent(id)).then(function successCallback(res) {
$scope.vocabularies = res.data;
alert("Vocabulary deleted");
}, function errorCallback(res) {

View File

@ -39,29 +39,41 @@ app.controller('vocabularyController', function($scope, $http, $location) {
$scope.saveTerm = function(term) {
var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms';
$http.defaults.headers.post["Content-Type"] = "application/json;charset=UTF-8";
alert("TO SAVE HERE - " + term.code);
//TODO
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) {
$scope.callDeleteTerm($scope.editTermCode);
}
$http.post(url, term).then(function successCallback(res) {
if ($scope.editTermCode != '' && $scope.editTermCode != $scope.tmpTerm.code) {
var deleteUrl = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent($scope.editTermCode);
$http.delete(deleteUrl).then(function successCallback(res) {
$scope.terms = res.data;
alert("Term replaced");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
} else {
$scope.terms = res.data;
alert("Term saved");
}
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
};
$scope.deleteTerm = function(code) {
if (confirm("Are you sure ?")) {
$scope.callDeleteTerm(code);
var url = './api/vocs/' + encodeURIComponent($scope.vocId) + '/terms/' + encodeURIComponent(code);
$http.delete(url).then(function successCallback(res) {
$scope.terms = res.data;
alert("Term deleted");
}, function errorCallback(res) {
alert('ERROR: ' + res.data.message);
});
}
};
$scope.callDeleteTerm = function(code) {
alert("TO DELETE HERE - " + code);
// TODO
};
$scope.reload();
});

View File

@ -5,7 +5,7 @@ CREATE TABLE vocabularies (
);
CREATE TABLE vocabulary_terms (
vocabulary text NOT NULL REFERENCES vocabularies(id),
vocabulary text NOT NULL REFERENCES vocabularies(id) ON UPDATE CASCADE ON DELETE CASCADE,
code text NOT NULL,
name text NOT NULL,
encoding text DEFAULT 'OPENAIRE',