using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Routing; | |
using Microsoft.Extensions.Logging; | |
using Notifier.WebApi.Models; | |
using Notifier.WebApi.Services; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Notifier.WebApi.Controllers | |
{ | |
[Route("api/notifications")] | |
public class NotificationController : ControllerBase | |
{ | |
private readonly INotificationService _notificationService; | |
private readonly ILogger<NotificationController> _logger; | |
public NotificationController(INotificationService notificationService, ILogger<NotificationController> logger) | |
{ | |
_notificationService = notificationService ?? throw new System.ArgumentNullException(nameof(notificationService)); | |
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); | |
} | |
[HttpPost] | |
[ProducesResponseType(200)] | |
[ProducesResponseType(500)] | |
public async Task<IActionResult> PostAsync(string message, CancellationToken cancellationToken) | |
{ | |
_logger.LogInformation($"Route: {HttpContext.Request.Path} has been called."); | |
await _notificationService.CreateAndSendAsync(message, cancellationToken); | |
return Ok(); | |
} | |
[HttpGet] | |
[ProducesResponseType(typeof(NotificationModel), 200)] | |
[ProducesResponseType(500)] | |
public async Task<IActionResult> GetAsync(CancellationToken cancellationToken) | |
{ | |
_logger.LogInformation($"Route: {HttpContext.Request.Path} has been called."); | |
var notifications = await _notificationService.GetAsync(cancellationToken); | |
return Ok(notifications); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment