refactor: move blog api controller to project root

This commit is contained in:
Oliver Booth 2023-08-11 16:32:11 +01:00
parent e060ab4dea
commit 54f3706ba0
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61

View File

@ -3,14 +3,14 @@ using Microsoft.AspNetCore.Mvc;
using OliverBooth.Data.Blog; using OliverBooth.Data.Blog;
using OliverBooth.Services; using OliverBooth.Services;
namespace OliverBooth.Areas.Api.Controllers; namespace OliverBooth.Controllers;
/// <summary> /// <summary>
/// Represents a controller for the blog API. /// Represents a controller for the blog API.
/// </summary> /// </summary>
[Controller] [ApiController]
[Area("api")] [Route("api/blog")]
[Route("blog")] [Produces("application/json")]
public sealed class BlogApiController : ControllerBase public sealed class BlogApiController : ControllerBase
{ {
private readonly BlogService _blogService; private readonly BlogService _blogService;
@ -24,7 +24,7 @@ public sealed class BlogApiController : ControllerBase
_blogService = blogService; _blogService = blogService;
} }
[HttpGet("count")] [Route("count")]
public IActionResult Count() public IActionResult Count()
{ {
if (!ValidateReferer()) return NotFound(); if (!ValidateReferer()) return NotFound();
@ -69,6 +69,7 @@ public sealed class BlogApiController : ControllerBase
return Ok(new return Ok(new
{ {
id = author.Id,
name = author.Name, name = author.Name,
avatarHash = author.AvatarHash, avatarHash = author.AvatarHash,
}); });
@ -77,6 +78,6 @@ public sealed class BlogApiController : ControllerBase
private bool ValidateReferer() private bool ValidateReferer()
{ {
var referer = Request.Headers["Referer"].ToString(); var referer = Request.Headers["Referer"].ToString();
return referer.StartsWith(Url.PageLink("/Blog/Index")!); return referer.StartsWith(Url.PageLink("/index",values: new{area="blog"})!);
} }
} }