From 54f3706ba0fa329791cd70bb023dc2569a6cb29d Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Fri, 11 Aug 2023 16:32:11 +0100 Subject: [PATCH] refactor: move blog api controller to project root --- .../Api => }/Controllers/BlogApiController.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) rename OliverBooth/{Areas/Api => }/Controllers/BlogApiController.cs (91%) diff --git a/OliverBooth/Areas/Api/Controllers/BlogApiController.cs b/OliverBooth/Controllers/BlogApiController.cs similarity index 91% rename from OliverBooth/Areas/Api/Controllers/BlogApiController.cs rename to OliverBooth/Controllers/BlogApiController.cs index b5732bd..7ae029f 100644 --- a/OliverBooth/Areas/Api/Controllers/BlogApiController.cs +++ b/OliverBooth/Controllers/BlogApiController.cs @@ -3,14 +3,14 @@ using Microsoft.AspNetCore.Mvc; using OliverBooth.Data.Blog; using OliverBooth.Services; -namespace OliverBooth.Areas.Api.Controllers; +namespace OliverBooth.Controllers; /// /// Represents a controller for the blog API. /// -[Controller] -[Area("api")] -[Route("blog")] +[ApiController] +[Route("api/blog")] +[Produces("application/json")] public sealed class BlogApiController : ControllerBase { private readonly BlogService _blogService; @@ -24,7 +24,7 @@ public sealed class BlogApiController : ControllerBase _blogService = blogService; } - [HttpGet("count")] + [Route("count")] public IActionResult Count() { if (!ValidateReferer()) return NotFound(); @@ -69,6 +69,7 @@ public sealed class BlogApiController : ControllerBase return Ok(new { + id = author.Id, name = author.Name, avatarHash = author.AvatarHash, }); @@ -77,6 +78,6 @@ public sealed class BlogApiController : ControllerBase private bool ValidateReferer() { var referer = Request.Headers["Referer"].ToString(); - return referer.StartsWith(Url.PageLink("/Blog/Index")!); + return referer.StartsWith(Url.PageLink("/index",values: new{area="blog"})!); } }