Moved using statements to globalusing file in webhooks.api

This commit is contained in:
Sumit Ghosh 2021-10-12 19:28:22 +05:30
parent ac9874e44a
commit 2cdb56fb69
27 changed files with 704 additions and 881 deletions

View File

@ -1,7 +1,4 @@
using Microsoft.AspNetCore.Mvc;
namespace Webhooks.API.Controllers
{
namespace Webhooks.API.Controllers;
public class HomeController : Controller
{
@ -12,4 +9,3 @@ namespace Webhooks.API.Controllers
}
}
}

View File

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Webhooks.API.Model;
namespace Webhooks.API.Controllers;
namespace Webhooks.API.Controllers
{
public class WebhookSubscriptionRequest : IValidatableObject
{
public string Url { get; set; }
@ -32,4 +27,3 @@ namespace Webhooks.API.Controllers
}
}
}

View File

@ -1,17 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Webhooks.API.Infrastructure;
using Webhooks.API.Model;
using Webhooks.API.Services;
namespace Webhooks.API.Controllers;
namespace Webhooks.API.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class WebhooksController : ControllerBase
@ -110,6 +98,3 @@ namespace Webhooks.API.Controllers
}
}
}

View File

@ -1,8 +1,5 @@
using System;
namespace Webhooks.API.Exceptions;
namespace Webhooks.API.Exceptions
{
public class WebhooksDomainException : Exception
{
}
}

View File

@ -1,8 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Webhooks.API.Infrastructure.ActionResult;
namespace Webhooks.API.Infrastructure.ActionResult
{
class InternalServerErrorObjectResult : ObjectResult
{
public InternalServerErrorObjectResult(object error) : base(error)
@ -10,4 +7,3 @@ namespace Webhooks.API.Infrastructure.ActionResult
StatusCode = StatusCodes.Status500InternalServerError;
}
}
}

View File

@ -1,11 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Webhooks.API.Infrastructure;
namespace Webhooks.API.Infrastructure
{
public class AuthorizeCheckOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
@ -33,4 +27,3 @@ namespace Webhooks.API.Infrastructure
};
}
}
}

View File

@ -1,15 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Net;
using Webhooks.API.Exceptions;
using Webhooks.API.Infrastructure.ActionResult;
namespace Webhooks.API.Infrastructure;
namespace Webhooks.API.Infrastructure
{
public class HttpGlobalExceptionFilter : IExceptionFilter
{
private readonly IWebHostEnvironment env;
@ -66,4 +56,3 @@ namespace Webhooks.API.Infrastructure
public object DeveloperMeesage { get; set; }
}
}
}

View File

@ -1,9 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Webhooks.API.Model;
namespace Webhooks.API.Infrastructure;
namespace Webhooks.API.Infrastructure
{
public class WebhooksContext : DbContext
{
@ -23,4 +19,3 @@ namespace Webhooks.API.Infrastructure
return new WebhooksContext(optionsBuilder.Options);
}
}
}

View File

@ -1,8 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using System.Collections.Generic;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public record OrderStatusChangedToPaidIntegrationEvent : IntegrationEvent
{
public int OrderId { get; }
@ -27,4 +24,3 @@ namespace Webhooks.API.IntegrationEvents
Units = units;
}
}
}

View File

@ -1,12 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
using Webhooks.API.Model;
using Webhooks.API.Services;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
{
private readonly IWebhooksRetriever _retriever;
@ -27,4 +20,3 @@ namespace Webhooks.API.IntegrationEvents
await _sender.SendAll(subscriptions, whook);
}
}
}

View File

@ -1,7 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent
{
public int OrderId { get; private init; }
@ -15,4 +13,3 @@ namespace Webhooks.API.IntegrationEvents
BuyerName = buyerName;
}
}
}

View File

@ -1,12 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
using Webhooks.API.Model;
using Webhooks.API.Services;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToShippedIntegrationEvent>
{
private readonly IWebhooksRetriever _retriever;
@ -27,4 +20,3 @@ namespace Webhooks.API.IntegrationEvents
await _sender.SendAll(subscriptions, whook);
}
}
}

View File

@ -1,7 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public record ProductPriceChangedIntegrationEvent : IntegrationEvent
{
public int ProductId { get; private init; }
@ -17,4 +15,3 @@ namespace Webhooks.API.IntegrationEvents
OldPrice = oldPrice;
}
}
}

View File

@ -1,8 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using System.Threading.Tasks;
namespace Webhooks.API.IntegrationEvents;
namespace Webhooks.API.IntegrationEvents
{
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>
{
public async Task Handle(ProductPriceChangedIntegrationEvent @event)
@ -10,4 +7,3 @@ namespace Webhooks.API.IntegrationEvents
int i = 0;
}
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Text.Json;
namespace Webhooks.API.Model;
namespace Webhooks.API.Model
{
public class WebhookData
{
public DateTime When { get; }
@ -18,4 +15,3 @@ namespace Webhooks.API.Model
Payload = JsonSerializer.Serialize(data);
}
}
}

View File

@ -1,7 +1,5 @@
using System;
namespace Webhooks.API.Model;
namespace Webhooks.API.Model
{
public class WebhookSubscription
{
public int Id { get; set; }
@ -12,4 +10,3 @@ namespace Webhooks.API.Model
public string Token { get; set; }
public string UserId { get; set; }
}
}

View File

@ -1,9 +1,8 @@
namespace Webhooks.API.Model
{
namespace Webhooks.API.Model;
public enum WebhookType
{
CatalogItemPriceChange = 1,
OrderShipped = 2,
OrderPaid = 3
}
}

View File

@ -1,11 +1,4 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Webhooks.API;
using Webhooks.API.Infrastructure;
CreateWebHostBuilder(args).Build()
CreateWebHostBuilder(args).Build()
.MigrateDbContext<WebhooksContext>((_, __) => { })
.Run();

View File

@ -1,11 +1,5 @@
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
class GrantUrlTesterService : IGrantUrlTesterService
{
private readonly IHttpClientFactory _clientFactory;
@ -54,4 +48,3 @@ namespace Webhooks.API.Services
firstUrl.Host == firstUrl.Host;
}
}
}

View File

@ -1,9 +1,6 @@
using System.Threading.Tasks;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public interface IGrantUrlTesterService
{
Task<bool> TestGrantUrl(string urlHook, string url, string token);
}
}

View File

@ -1,7 +1,6 @@
namespace Webhooks.API.Services
{
namespace Webhooks.API.Services;
public interface IIdentityService
{
string GetUserIdentity();
}
}

View File

@ -1,12 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Webhooks.API.Model;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public interface IWebhooksRetriever
{
Task<IEnumerable<WebhookSubscription>> GetSubscriptionsOfType(WebhookType type);
}
}

View File

@ -1,11 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Webhooks.API.Model;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public interface IWebhooksSender
{
Task SendAll(IEnumerable<WebhookSubscription> receivers, WebhookData data);
}
}

View File

@ -1,9 +1,5 @@

using Microsoft.AspNetCore.Http;
using System;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
@ -18,4 +14,3 @@ namespace Webhooks.API.Services
return _context.HttpContext.User.FindFirst("sub").Value;
}
}
}

View File

@ -1,12 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Webhooks.API.Infrastructure;
using Webhooks.API.Model;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public class WebhooksRetriever : IWebhooksRetriever
{
private readonly WebhooksContext _db;
@ -20,4 +13,3 @@ namespace Webhooks.API.Services
return data;
}
}
}

View File

@ -1,15 +1,5 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Webhooks.API.Model;
namespace Webhooks.API.Services;
namespace Webhooks.API.Services
{
public class WebhooksSender : IWebhooksSender
{
private readonly IHttpClientFactory _httpClientFactory;
@ -46,4 +36,3 @@ namespace Webhooks.API.Services
}
}
}

View File

@ -1,36 +1,5 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Devspaces.Support;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.ServiceBus;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.IdentityModel.Tokens.Jwt;
using System.Reflection;
using System.Threading;
using Webhooks.API.Infrastructure;
using Webhooks.API.IntegrationEvents;
using Webhooks.API.Services;
namespace Webhooks.API;
namespace Webhooks.API
{
public class Startup
{
public IConfiguration Configuration { get; }
@ -347,4 +316,3 @@ namespace Webhooks.API
return services;
}
}
}