using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using OliverBooth.Api.Data;
using OliverBooth.Common.Data.Web.Users;
using OliverBooth.Common.Services;
namespace OliverBooth.Api.Controllers.Blog;
///
/// Represents an API controller which allows reading authors of blog posts.
///
[ApiController]
[Route("v{version:apiVersion}/blog/author")]
[Produces("application/json")]
[ApiVersion(1)]
public sealed class AuthorController : ControllerBase
{
private readonly IUserService _userService;
///
/// Initializes a new instance of the class.
///
/// The .
public AuthorController(IUserService userService)
{
_userService = userService;
}
///
/// Returns an object representing the author with the specified ID.
///
/// The ID of the author.
/// An object representing the author.
[HttpGet("{id:guid}")]
[EndpointDescription("Returns an object representing the author with the specified ID.")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(Author))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetAuthor(Guid id)
{
if (!_userService.TryGetUser(id, out IUser? author))
{
return NotFound();
}
return Ok(Author.FromUser(author));
}
}