From 5493c5d2df045f673f7a3f0fedeaf452d438014f Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Mon, 12 Jun 2017 17:45:33 +0300 Subject: [PATCH] Better client --- WebApi/index.html | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/WebApi/index.html b/WebApi/index.html index 6685b29..feb75e7 100644 --- a/WebApi/index.html +++ b/WebApi/index.html @@ -1,9 +1,8 @@ -

api

-foorum +

/api/foorum


- +
@@ -14,7 +13,7 @@
- +
@@ -39,11 +38,16 @@ }); } - function addForum(title) { + function addForum(title, description, body, author) { + if (title == null) throw new Error("title unset"); + if (description == null) throw new Error("description unset"); + if (body == null) throw new Error("body unset"); + if (author == null) throw new Error("author unset"); + var dto = { - Author: "Veebileht", - Body: "Siia tuleb äge pikk sisu mingist asjast", - Description: "Siia kirjeldus", + Author: author, + Body: body, + Description: description, Title: title } fetch("/api/foorum", @@ -71,12 +75,15 @@ } function deleteForum(id, permanent) { + if (id == null) throw new Error("Forum id is unset"); + var q = ""; if (permanent) { q = "?permanent=true"; } - fetch("/api/foorum/"+id+q, { method: 'DELETE'}); + fetch("/api/foorum/" + id + q, { method: 'DELETE' }) + .then(resp => getForums()); } function searchForum(what, author) { @@ -88,12 +95,18 @@ }); } - function addPost(id, title, body) { + function addPost(id, title, body, author) { + if (id == null) throw new Error("forum id is unset"); + if (title == null) throw new Error("title is unset"); + if (body == null) throw new Error("body is unset"); + if (author == null) throw new Error("author is unset"); + var dto = { - Author: "Ajax", + Author: author, Body: body, Title: title } + fetch("/api/foorum/"+id, { method: 'POST',