Skip to content

Commit

Permalink
Toevoegen van validatie.
Browse files Browse the repository at this point in the history
Aanpassen van de hoogste categorie.
  • Loading branch information
kurtdb committed May 27, 2016
1 parent 8093eb0 commit 0890021
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 102 deletions.
22 changes: 15 additions & 7 deletions src/main/java/be/boks/domain/Category.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
16 changes: 16 additions & 0 deletions src/main/java/be/boks/rest/RunnerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<String> 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;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1><img src="img/runner.png"> Runs</h1>
15.00 u.: 5km <span class="price">(&euro; 5 vvk, &euro; 6 adk)</span>
</div>
<div class="runCategory">
13.20 u.: Kids Run 2 <span class="price">(&euro; 7vvk, &euro;8 adk)</span><br>
16.00 u.: 10km <span class="price">(&euro; 7vvk, &euro;8 adk)</span><br>
<span class="extrainfo bedrijvenklassement">(incl. bedrijvenklassement)</span>
</div>
<div class="opbrengst">
Expand Down
105 changes: 12 additions & 93 deletions src/main/resources/static/js/RegistrationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
});
}
;

};

Expand All @@ -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);
32 changes: 31 additions & 1 deletion src/main/resources/static/js/RegistrationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 0890021

Please sign in to comment.