Add post, fix delete forum, fix null pointer exceptions, min max limist
on database strings
This commit is contained in:
@@ -83,5 +83,15 @@ namespace WebApi.Controllers
|
||||
|
||||
return Ok(f);
|
||||
}
|
||||
|
||||
public IHttpActionResult PostPost(int id, [FromBody] PostDTO post)
|
||||
{
|
||||
var p = _foorumService.AddPost(id, post);
|
||||
if (p == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,5 +26,10 @@ namespace WebApi.Controllers
|
||||
{
|
||||
return Ok(_foorumService.SearchFoorumTitle(title));
|
||||
}
|
||||
|
||||
public IHttpActionResult GetAuthorPosts(string authorPosts)
|
||||
{
|
||||
return Ok(_foorumService.SearchPostAuthor(authorPosts));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@
|
||||
<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>
|
||||
|
||||
@@ -83,4 +87,22 @@
|
||||
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>
|
||||
Reference in New Issue
Block a user