108 lines
3.2 KiB
HTML
108 lines
3.2 KiB
HTML
<h1>api</h1>
|
|
<a href="/api/foorum">foorum</a>
|
|
<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="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
|
|
<br/>
|
|
<button onclick="deleteForum(prompt('ForumId: ', '1'), true)">DeleteForum</button>
|
|
<button onclick="deleteForum(prompt('ForumId: ', '1'), false)">HideForum</button>
|
|
<br/>
|
|
<button onclick="searchForum('author', prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
|
|
<button onclick="searchForum('title', prompt('Title: ', 'test'))">SearchForumTitle</button>
|
|
<button onclick="searchForum('authorPosts', prompt('Author: ', 'test'))">SearchAuthorPosts</button>
|
|
|
|
<br/>
|
|
<button onclick="addPost(prompt('ForumId', '1'), 'Best title', prompt('Body', 'Lahe post'))">AddPost</button>
|
|
|
|
<code><pre id="output"></pre></code>
|
|
|
|
<script>
|
|
var out = document.getElementById("output");
|
|
|
|
function getForum(id) {
|
|
fetch("/api/foorum/"+id).then(resp => {
|
|
return resp.json();
|
|
}).then(data => {
|
|
console.log(data);
|
|
out.innerText = JSON.stringify(data, null, 2);
|
|
});
|
|
}
|
|
|
|
function getForums() {
|
|
fetch("/api/foorum").then(resp => {
|
|
return resp.json();
|
|
}).then(data => {
|
|
console.log(data);
|
|
out.innerText = JSON.stringify(data, null, 2);
|
|
});
|
|
}
|
|
|
|
function addForum(title) {
|
|
var dto = {
|
|
Author: "Veebileht",
|
|
Body: "Siia tuleb äge pikk sisu mingist asjast",
|
|
Description: "Siia kirjeldus",
|
|
Title: title
|
|
}
|
|
fetch("/api/foorum",
|
|
{
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(dto)
|
|
}).then(resp => getForums());
|
|
}
|
|
|
|
function changeForumTitle(id, title) {
|
|
var dto = {
|
|
Title: title
|
|
}
|
|
fetch("/api/foorum/"+id,
|
|
{
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(dto)
|
|
});
|
|
}
|
|
|
|
function deleteForum(id, permanent) {
|
|
var q = "";
|
|
if (permanent) {
|
|
q = "?permanent=true";
|
|
}
|
|
|
|
fetch("/api/foorum/"+id+q, { method: 'DELETE'});
|
|
}
|
|
|
|
function searchForum(what, author) {
|
|
fetch("/api/search?"+what+"="+author).then(resp => {
|
|
return resp.json();
|
|
}).then(data => {
|
|
console.log(data);
|
|
out.innerText = JSON.stringify(data, null, 2);
|
|
});
|
|
}
|
|
|
|
function addPost(id, title, body) {
|
|
var dto = {
|
|
Author: "Ajax",
|
|
Body: body,
|
|
Title: title
|
|
}
|
|
fetch("/api/foorum/"+id,
|
|
{
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(dto)
|
|
}).then(resp => getForum(id));
|
|
}
|
|
|
|
getForums();
|
|
</script> |