<%

include("../model/orderQuery.jag");
response.contentType = 'text/javascript';

var verb = request.getMethod();
var orderid = request.getParameter('orderid');
var order = request.getParameter('order');
var status = request.getParameter('status');
var addition = request.getParameter('addition');
var data = request.getContent();
var log = new Log();

var uri = request.getRequestURI();
uri = uri.substring(request.getContextPath().length);
if(uri != null) {
var uriMatcher = new URIMatcher(uri);

	if(uriMatcher.match("/orders/{orderid}/{page}")) {
		orderid = uriMatcher.elements().orderid;
	}
	if(uriMatcher.match("/orders/{orderid}/")) {
		orderid = uriMatcher.elements().orderid;
	}
}

if(data != "") {
    data = parse(data);
	if(data.addition) {
		addition = data.addition;
	}
	if(data.status) {
		status = data.status;
	}
}



if(verb == "DELETE" && orderid != null) {
	deleteOrder(orderid);

} else if(verb == "GET" && orderid != null && addition == null && status == null) {
	viewOrder(orderid);

} else if(verb == "PUT" && orderid != null && addition != null) {	
	addAddition(orderid, addition);

} else if(verb == "PUT" && orderid != null && status != null) {
	updateStatus(orderid, status);

} else if(verb == "POST" && order != null) {
	addOrder(order);

} else if(verb == "GET") {
	listAllOrders();
}



%>