using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using EllieBot.VotesApi.Services; namespace EllieBot.VotesApi.Controllers { [ApiController] public class WebhookController : ControllerBase { private readonly ILogger _logger; private readonly IVotesCache _votesCache; public WebhookController(ILogger logger, IVotesCache votesCache) { _logger = logger; _votesCache = votesCache; } [HttpPost("/discordswebhook")] [Authorize(Policy = Policies.DiscordsAuth)] public async Task DiscordsWebhook([FromBody] DiscordsVoteWebhookModel data) { _logger.LogInformation("User {UserId} has voted for Bot {BotId} on {Platform}", data.User, data.Bot, "discords.com"); await _votesCache.AddNewDiscordsVote(data.User); return Ok(); } [HttpPost("/topggwebhook")] [Authorize(Policy = Policies.TopggAuth)] public async Task TopggWebhook([FromBody] TopggVoteWebhookModel data) { _logger.LogInformation("User {UserId} has voted for Bot {BotId} on {Platform}", data.User, data.Bot, "top.gg"); await _votesCache.AddNewTopggVote(data.User); return Ok(); } } }