refactor: return Ok(...) instead of building a JsonResult
This commit is contained in:
parent
9d46d6495e
commit
159e1ad65d
@ -1,6 +1,5 @@
|
|||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using OliverBooth.Data.Blog;
|
using OliverBooth.Data.Blog;
|
||||||
using OliverBooth.Services;
|
using OliverBooth.Services;
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ public sealed class BlogApiController : ControllerBase
|
|||||||
[Route("count")]
|
[Route("count")]
|
||||||
public IActionResult Count()
|
public IActionResult Count()
|
||||||
{
|
{
|
||||||
return new JsonResult(new { count = _blogService.AllPosts.Count });
|
return Ok(new { count = _blogService.AllPosts.Count });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("all/{skip:int?}/{take:int?}")]
|
[Route("all/{skip:int?}/{take:int?}")]
|
||||||
@ -34,7 +33,7 @@ public sealed class BlogApiController : ControllerBase
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonResult(_blogService.AllPosts.Skip(skip).Take(take).Select(post => new
|
return Ok(_blogService.AllPosts.Skip(skip).Take(take).Select(post => new
|
||||||
{
|
{
|
||||||
id = post.Id,
|
id = post.Id,
|
||||||
commentsEnabled = post.EnableComments,
|
commentsEnabled = post.EnableComments,
|
||||||
@ -63,7 +62,7 @@ public sealed class BlogApiController : ControllerBase
|
|||||||
{
|
{
|
||||||
if (!_blogService.TryGetAuthor(id, out Author? author)) return NotFound();
|
if (!_blogService.TryGetAuthor(id, out Author? author)) return NotFound();
|
||||||
|
|
||||||
return new JsonResult(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
name = author.Name,
|
name = author.Name,
|
||||||
avatarHash = author.AvatarHash,
|
avatarHash = author.AvatarHash,
|
||||||
|
Loading…
Reference in New Issue
Block a user