src/Services/Webhooks/Webhooks.API/Controllers/WebhooksController.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace Webhooks.API.Controllers;

[Route("api/v1/[controller]")]
[ApiController]
public class WebhooksController : ControllerBase
{
    private readonly WebhooksContext _dbContext;
    private readonly IIdentityService _identityService;
    private readonly IGrantUrlTesterService _grantUrlTester;

    public WebhooksController(WebhooksContext dbContext, IIdentityService identityService, IGrantUrlTesterService grantUrlTester)
    {
        _dbContext = dbContext;
        _identityService = identityService;
        _grantUrlTester = grantUrlTester;
    }

    [Authorize]
    [HttpGet]
    [ProducesResponseType(typeof(IEnumerable<WebhookSubscription>), (int)HttpStatusCode.OK)]
    public async Task<IActionResult> ListByUser()
    {
        var userId = _identityService.GetUserIdentity();
        var data = await _dbContext.Subscriptions.Where(s => s.UserId == userId).ToListAsync();
        return Ok(data);
    }

    [Authorize]
    [HttpGet("{id:int}")]
    [ProducesResponseType(typeof(WebhookSubscription), (int)HttpStatusCode.OK)]
    [ProducesResponseType((int)HttpStatusCode.NotFound)]
    public async Task<IActionResult> GetByUserAndId(int id)
    {
        var userId = _identityService.GetUserIdentity();
        var subscription = await _dbContext.Subscriptions.SingleOrDefaultAsync(s => s.Id == id && s.UserId == userId);
        if (subscription != null)
        {
            return Ok(subscription);
        }
        return NotFound($"Subscriptions {id} not found");
    }

    [Authorize]
    [HttpPost]
    [ProducesResponseType((int)HttpStatusCode.Created)]
    [ProducesResponseType((int)HttpStatusCode.BadRequest)]
    [ProducesResponseType(418)]
    public async Task<IActionResult> SubscribeWebhook(WebhookSubscriptionRequest request)
    {
        if (!ModelState.IsValid)
        {
            return ValidationProblem(ModelState);
        }

        var grantOk = await _grantUrlTester.TestGrantUrl(request.Url, request.GrantUrl, request.Token ?? string.Empty);

        if (grantOk)
        {
            var subscription = new WebhookSubscription()
            {
后面还有 37 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。