44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using System.Threading.Tasks;
|
|
using HN.Application;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public sealed class LinksController : ControllerBase
|
|
{
|
|
private readonly IMediator _bus;
|
|
|
|
public LinksController(IMediator bus)
|
|
{
|
|
_bus = bus;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve all links already posted.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[ProducesResponseType(typeof(LinkDto[]), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> GetLinks()
|
|
{
|
|
return Ok(await _bus.Send(new ListLinksQuery()));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Post a new link.
|
|
/// </summary>
|
|
/// <param name="command"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateLink(AddLinkCommand command)
|
|
{
|
|
var result = await _bus.Send(command);
|
|
|
|
return Created("blabla", result);
|
|
}
|
|
}
|
|
} |