Better client

This commit is contained in:
Arti Zirk 2017-06-12 17:45:33 +03:00
parent 430d02f59e
commit 5493c5d2df
1 changed files with 24 additions and 11 deletions

View File

@ -1,9 +1,8 @@
<h1>api</h1>
<a href="/api/foorum">foorum</a>
<h1><a href="/api/foorum">/api/foorum</a></h1>
<br/>
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
<button onclick="getForums()">GetAllForums</button>
<button onclick="addForum(prompt('Title: ', 'Uus postitus'))">AddForum</button>
<button onclick="addForum(prompt('Title: ', 'Uus foorum'), 'kirjeldus', 'Äge body', prompt('Author:', 'Javascript'))">AddForum</button>
<button onclick="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
<br/>
<button onclick="deleteForum(prompt('ForumId: ', '1'), true)">DeleteForum</button>
@ -14,7 +13,7 @@
<button onclick="searchForum('authorPosts', prompt('Author: ', 'test'))">SearchAuthorPosts</button>
<br/>
<button onclick="addPost(prompt('ForumId', '1'), 'Best title', prompt('Body', 'Lahe post'))">AddPost</button>
<button onclick="addPost(prompt('ForumId', '1'), prompt('Title:', 'Best title'), prompt('Body', 'Lahe post'), prompt('Author', 'Ajax'))">AddPost</button>
<code><pre id="output"></pre></code>
@ -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',