summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2013-03-17 00:45:05 +0100
committerLennart Weller <lhw@ring0.de>2013-03-17 00:45:05 +0100
commitf38190391eca37042dd86989aad8b5245539c653 (patch)
tree321681870426119dacb2d57aa1b5772b36a02efa
parentb9e4dfad131f8678dfd51c7e7ce209ef2a0c6c02 (diff)
downloadserial-barcode-scanner-f38190391eca37042dd86989aad8b5245539c653.tar.bz2
added product list to api
-rw-r--r--src/web.vala25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/web.vala b/src/web.vala
index 79942f7..ba9137d 100644
--- a/src/web.vala
+++ b/src/web.vala
@@ -820,6 +820,12 @@ public class WebServer {
void handler_json(Soup.Server server, Soup.Message msg, string path, GLib.HashTable<string,string>? query, Soup.ClientContext client) {
string action;
+ var gen = new Json.Generator();
+ var root = new Json.Node(Json.NodeType.ARRAY);
+ var array = new Json.Array();
+ root.set_array(array);
+ gen.set_root(root);
+
if(query != null && query.contains("action")) {
action = query.get("action");
if(action == "invoice" && query.contains("userid")) {
@@ -844,12 +850,6 @@ public class WebServer {
end = now;
}
- var gen = new Json.Generator();
- var root = new Json.Node(Json.NodeType.ARRAY);
- var array = new Json.Array();
- root.set_array(array);
- gen.set_root(root);
-
foreach(var e in db.get_invoice(userid, begin.to_unix(), end.to_unix())) {
var o = new Json.Object();
o.set_int_member("timestamp", e.timestamp);
@@ -857,7 +857,18 @@ public class WebServer {
o.set_int_member("price", e.price);
array.add_object_element(o);
}
-
+ msg.set_response("application/json", Soup.MemoryUse.COPY, gen.to_data(null).data);
+ }
+ else if(action == "list") {
+ foreach(var e in db.get_stock()) {
+ var o = new Json.Object();
+ o.set_string_member("id", e.id);
+ o.set_string_member("name", e.name);
+ o.set_int_member("amount", e.amount);
+ o.set_int_member("guestprice", e.guestprice);
+ o.set_int_member("memberprice", e.memberprice);
+ array.add_object_element(o);
+ }
msg.set_response("application/json", Soup.MemoryUse.COPY, gen.to_data(null).data);
}
}