From 089002120ed34d7abfe5e7eae8556453f51d0e22 Mon Sep 17 00:00:00 2001 From: Kurt Du Bois Date: Fri, 27 May 2016 21:23:10 +0200 Subject: [PATCH] Toevoegen van validatie. Aanpassen van de hoogste categorie. --- src/main/java/be/boks/domain/Category.java | 22 ++-- .../java/be/boks/rest/RunnerController.java | 16 +++ src/main/resources/static/index.html | 2 +- .../static/js/RegistrationController.js | 105 ++---------------- .../static/js/RegistrationService.js | 32 +++++- 5 files changed, 75 insertions(+), 102 deletions(-) diff --git a/src/main/java/be/boks/domain/Category.java b/src/main/java/be/boks/domain/Category.java index 231f263..03cefc2 100644 --- a/src/main/java/be/boks/domain/Category.java +++ b/src/main/java/be/boks/domain/Category.java @@ -1,20 +1,28 @@ package be.boks.domain; public enum Category { - KIDS_RUN_1("kids_run_1"), - KIDS_RUN_2("kids_run_2"), - ROLSTOEL_RACE("rolstoelrace"), - HANDBIKE_RACE("handbikerace"), - FIVE_KM("5km"), - TEN_KM("10km"); + KIDS_RUN_1("kids_run_1", 2), + KIDS_RUN_2("kids_run_2", 2), + ROLSTOEL_RACE("rolstoelrace", 1), + HANDBIKE_RACE("handbikerace", 3), + FIVE_KM("5km", 5), + TEN_KM("10km", 7); private String categoryName; - private Category(String categoryName) { + private Integer price; + + private Category(String categoryName, Integer price) { this.categoryName = categoryName; + this.price = price; } public String getCategoryName() { return categoryName; } + + public Integer getPrice() { + return price; + } + } diff --git a/src/main/java/be/boks/rest/RunnerController.java b/src/main/java/be/boks/rest/RunnerController.java index 408a1f7..4ddd4c0 100644 --- a/src/main/java/be/boks/rest/RunnerController.java +++ b/src/main/java/be/boks/rest/RunnerController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import be.boks.domain.Category; import be.boks.domain.Runner; import be.boks.service.RunnerService; @@ -36,4 +37,19 @@ public void register(@Valid @RequestBody Runner runner) { Runner saved = runnerService.insert(runner); LOGGER.info("Saved runner: " + saved); } + + @RequestMapping(method=RequestMethod.GET, path="/berekenPrijs") + public int calculatePrice(@Valid Runner runner) { + int price = 0; + List categories = runner.getCategories(); + Category[] values = Category.values(); + for(String categoryName : categories) { + for (Category category : values) { + if (category.getCategoryName().equals(categoryName)) { + price += category.getPrice(); + } + } + } + return price; + } } diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index e47df0d..e4622f5 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -41,7 +41,7 @@

Runs

15.00 u.: 5km (€ 5 vvk, € 6 adk)
- 13.20 u.: Kids Run 2 (€ 7vvk, €8 adk)
+ 16.00 u.: 10km (€ 7vvk, €8 adk)
(incl. bedrijvenklassement)
diff --git a/src/main/resources/static/js/RegistrationController.js b/src/main/resources/static/js/RegistrationController.js index 2ef0b36..81e1a9b 100644 --- a/src/main/resources/static/js/RegistrationController.js +++ b/src/main/resources/static/js/RegistrationController.js @@ -22,8 +22,6 @@ street, town, gender, club, age, email, category, boksLid, stofwisselingsZiekte) { - if (firstname && name && street && town - && gender && age && email) { console.log('Trying to save!'); var promise = RegistrationService.add( firstname, name, street, town, @@ -36,16 +34,24 @@ $scope.saving = false; $scope.result = 'Succesvol geregistreerd'; $scope.class = 'alert alert-success'; - $uibModalInstance - .close(); + var calculatedPromise = RegistrationService.calculatePrice( + firstname, name, street, town, + gender, club, age, email, + category, boksLid, + stofwisselingsZiekte); + calculatedPromise.then(function(result) { + $scope.result = 'Registratie succesvol. Gelieve ' + result + ' euro over te schrijven op rekeningnummer BE33 9201 0189 5146'; + }, + function(error) { + $scope.result = error; + $scope.class = 'alert alert-danger'; + }); }, function(error) { $scope.saving = false; $scope.result = error; $scope.class = 'alert alert-danger'; }); - } - ; }; @@ -63,93 +69,6 @@ $scope.dt = null; }; - $scope.inlineOptions = { - customClass : getDayClass, - minDate : new Date(), - showWeeks : true - }; - - $scope.dateOptions = { - dateDisabled : disabled, - formatYear : 'yy', - maxDate : new Date(2020, 5, 22), - minDate : new Date(), - startingDay : 1 - }; - - // Disable weekend selection - function disabled(data) { - var date = data.date, mode = data.mode; - return mode === 'day' - && (date.getDay() === 0 || date - .getDay() === 6); - } - - $scope.toggleMin = function() { - $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null - : new Date(); - $scope.dateOptions.minDate = $scope.inlineOptions.minDate; - }; - - $scope.toggleMin(); - - $scope.open1 = function() { - $scope.popup1.opened = true; - }; - - $scope.open2 = function() { - $scope.popup2.opened = true; - }; - - $scope.setDate = function(year, month, day) { - $scope.dt = new Date(year, month, day); - }; - - $scope.formats = [ 'dd-MMMM-yyyy', - 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate' ]; - $scope.format = $scope.formats[0]; - $scope.altInputFormats = [ 'M!/d!/yyyy' ]; - - $scope.popup1 = { - opened : false - }; - - $scope.popup2 = { - opened : false - }; - - var tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 1); - var afterTomorrow = new Date(); - afterTomorrow.setDate(tomorrow.getDate() + 1); - $scope.events = [ { - date : tomorrow, - status : 'full' - }, { - date : afterTomorrow, - status : 'partially' - } ]; - - function getDayClass(data) { - var date = data.date, mode = data.mode; - if (mode === 'day') { - var dayToCheck = new Date(date) - .setHours(0, 0, 0, 0); - - for (var i = 0; i < $scope.events.length; i++) { - var currentDay = new Date( - $scope.events[i].date) - .setHours(0, 0, 0, 0); - - if (dayToCheck === currentDay) { - return $scope.events[i].status; - } - } - } - - return ''; - } - } ]); })(angular); \ No newline at end of file diff --git a/src/main/resources/static/js/RegistrationService.js b/src/main/resources/static/js/RegistrationService.js index 144e799..e03c665 100644 --- a/src/main/resources/static/js/RegistrationService.js +++ b/src/main/resources/static/js/RegistrationService.js @@ -32,8 +32,38 @@ return deferred.promise; }; + var calculatePrice = function(firstname, name, street, town, gender, club, age, email, categories, boksLid, stofwisselingsZiekte) { + var deferred = $q.defer(); + + var request = $http({ + method : 'get', + url : '/loper/berekenPrijs', + params : { + firstName: firstname, + lastName: name, + address : street, + city : town, + gender : gender, + runningClub : club, + age : age, + emailAddress : email, + categories : categories, + boksLid : boksLid, + stofwisselingsZiekte : stofwisselingsZiekte + } + }); + request.success(function(data) { + return deferred.resolve(data); + }).error(function(data) { + return deferred.reject(data.message); + }); + + return deferred.promise; + } + return { - add: add + add: add, + calculatePrice: calculatePrice } } ]); })(angular); \ No newline at end of file