Add post, fix delete forum, fix null pointer exceptions, min max limist

on database strings
This commit is contained in:
2017-06-12 17:22:58 +03:00
parent 1249950059
commit 430d02f59e
10 changed files with 148 additions and 22 deletions

View File

@@ -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);
}
}
}

View File

@@ -26,5 +26,10 @@ namespace WebApi.Controllers
{
return Ok(_foorumService.SearchFoorumTitle(title));
}
public IHttpActionResult GetAuthorPosts(string authorPosts)
{
return Ok(_foorumService.SearchPostAuthor(authorPosts));
}
}
}

View File

@@ -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>