Last active
March 1, 2021 22:32
-
-
Save screamingworld/9272585d35f1e7377d7b3e9a6ed2e6f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
[Route("ping")] | |
[HttpGet] | |
[ProducesResponseType(200)] | |
[ProducesResponseType(500)] | |
public async Task<IActionResult> GetPingAsync(string message, CancellationToken cancellationToken) | |
{ | |
return Ok("PING"); | |
} | |
[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