Publish post

This commit is contained in:
Robert Marshall 2020-04-11 12:33:57 +01:00
parent cfcef8b77d
commit 2a642faecd
2 changed files with 36 additions and 0 deletions

View file

@ -103,5 +103,19 @@ namespace Robware.Api.Blog.Controllers {
await _blogRepository.DeletePostAsync(id);
return Ok();
}
[HttpPost(nameof(PublishPost))]
public async Task<ActionResult> PublishPost([FromBody] int id) {
try {
var post = await _blogRepository.GetPostByIdAsync(id);
post.Publish();
await _blogRepository.SavePost(post);
return Ok();
}
catch (ItemNotFoundException e) {
_logger.Log(LogLevel.Error, e.Message);
return BadRequest("Tried to publish post that doesn't exist");
}
}
}
}