Better client
This commit is contained in:
parent
430d02f59e
commit
5493c5d2df
@ -1,9 +1,8 @@
|
|||||||
<h1>api</h1>
|
<h1><a href="/api/foorum">/api/foorum</a></h1>
|
||||||
<a href="/api/foorum">foorum</a>
|
|
||||||
<br/>
|
<br/>
|
||||||
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
|
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
|
||||||
<button onclick="getForums()">GetAllForums</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>
|
<button onclick="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
|
||||||
<br/>
|
<br/>
|
||||||
<button onclick="deleteForum(prompt('ForumId: ', '1'), true)">DeleteForum</button>
|
<button onclick="deleteForum(prompt('ForumId: ', '1'), true)">DeleteForum</button>
|
||||||
@ -14,7 +13,7 @@
|
|||||||
<button onclick="searchForum('authorPosts', prompt('Author: ', 'test'))">SearchAuthorPosts</button>
|
<button onclick="searchForum('authorPosts', prompt('Author: ', 'test'))">SearchAuthorPosts</button>
|
||||||
|
|
||||||
<br/>
|
<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>
|
<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 = {
|
var dto = {
|
||||||
Author: "Veebileht",
|
Author: author,
|
||||||
Body: "Siia tuleb äge pikk sisu mingist asjast",
|
Body: body,
|
||||||
Description: "Siia kirjeldus",
|
Description: description,
|
||||||
Title: title
|
Title: title
|
||||||
}
|
}
|
||||||
fetch("/api/foorum",
|
fetch("/api/foorum",
|
||||||
@ -71,12 +75,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteForum(id, permanent) {
|
function deleteForum(id, permanent) {
|
||||||
|
if (id == null) throw new Error("Forum id is unset");
|
||||||
|
|
||||||
var q = "";
|
var q = "";
|
||||||
if (permanent) {
|
if (permanent) {
|
||||||
q = "?permanent=true";
|
q = "?permanent=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("/api/foorum/"+id+q, { method: 'DELETE'});
|
fetch("/api/foorum/" + id + q, { method: 'DELETE' })
|
||||||
|
.then(resp => getForums());
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchForum(what, author) {
|
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 = {
|
var dto = {
|
||||||
Author: "Ajax",
|
Author: author,
|
||||||
Body: body,
|
Body: body,
|
||||||
Title: title
|
Title: title
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("/api/foorum/"+id,
|
fetch("/api/foorum/"+id,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
Loading…
Reference in New Issue
Block a user