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 public class HomeController : Controller
{ {
@ -12,4 +9,3 @@ namespace Webhooks.API.Controllers
} }
} }
}

View File

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

View File

@ -1,17 +1,5 @@
using Microsoft.AspNetCore.Authorization; namespace Webhooks.API.Controllers;
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
{
[Route("api/v1/[controller]")] [Route("api/v1/[controller]")]
[ApiController] [ApiController]
public class WebhooksController : ControllerBase 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 public class WebhooksDomainException : Exception
{ {
} }
}

View File

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

View File

@ -1,11 +1,5 @@
using Microsoft.AspNetCore.Authorization; namespace Webhooks.API.Infrastructure;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;
namespace Webhooks.API.Infrastructure
{
public class AuthorizeCheckOperationFilter : IOperationFilter public class AuthorizeCheckOperationFilter : IOperationFilter
{ {
public void Apply(OpenApiOperation operation, OperationFilterContext context) 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; namespace Webhooks.API.Infrastructure;
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
{
public class HttpGlobalExceptionFilter : IExceptionFilter public class HttpGlobalExceptionFilter : IExceptionFilter
{ {
private readonly IWebHostEnvironment env; private readonly IWebHostEnvironment env;
@ -66,4 +56,3 @@ namespace Webhooks.API.Infrastructure
public object DeveloperMeesage { get; set; } public object DeveloperMeesage { get; set; }
} }
} }
}

View File

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

View File

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

View File

@ -1,12 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; namespace Webhooks.API.IntegrationEvents;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
using Webhooks.API.Model;
using Webhooks.API.Services;
namespace Webhooks.API.IntegrationEvents
{
public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent> public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToPaidIntegrationEvent>
{ {
private readonly IWebhooksRetriever _retriever; private readonly IWebhooksRetriever _retriever;
@ -27,4 +20,3 @@ namespace Webhooks.API.IntegrationEvents
await _sender.SendAll(subscriptions, whook); 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 record OrderStatusChangedToShippedIntegrationEvent : IntegrationEvent
{ {
public int OrderId { get; private init; } public int OrderId { get; private init; }
@ -15,4 +13,3 @@ namespace Webhooks.API.IntegrationEvents
BuyerName = buyerName; BuyerName = buyerName;
} }
} }
}

View File

@ -1,12 +1,5 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; namespace Webhooks.API.IntegrationEvents;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
using Webhooks.API.Model;
using Webhooks.API.Services;
namespace Webhooks.API.IntegrationEvents
{
public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToShippedIntegrationEvent> public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEventHandler<OrderStatusChangedToShippedIntegrationEvent>
{ {
private readonly IWebhooksRetriever _retriever; private readonly IWebhooksRetriever _retriever;
@ -27,4 +20,3 @@ namespace Webhooks.API.IntegrationEvents
await _sender.SendAll(subscriptions, whook); 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 record ProductPriceChangedIntegrationEvent : IntegrationEvent
{ {
public int ProductId { get; private init; } public int ProductId { get; private init; }
@ -17,4 +15,3 @@ namespace Webhooks.API.IntegrationEvents
OldPrice = oldPrice; OldPrice = oldPrice;
} }
} }
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,5 @@
using Microsoft.Extensions.Logging; namespace Webhooks.API.Services;
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Webhooks.API.Services
{
class GrantUrlTesterService : IGrantUrlTesterService class GrantUrlTesterService : IGrantUrlTesterService
{ {
private readonly IHttpClientFactory _clientFactory; private readonly IHttpClientFactory _clientFactory;
@ -54,4 +48,3 @@ namespace Webhooks.API.Services
firstUrl.Host == firstUrl.Host; 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 public interface IGrantUrlTesterService
{ {
Task<bool> TestGrantUrl(string urlHook, string url, string token); 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 public interface IIdentityService
{ {
string GetUserIdentity(); string GetUserIdentity();
} }
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,15 +1,5 @@
using Microsoft.Extensions.Logging; namespace Webhooks.API.Services;
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
{
public class WebhooksSender : IWebhooksSender public class WebhooksSender : IWebhooksSender
{ {
private readonly IHttpClientFactory _httpClientFactory; private readonly IHttpClientFactory _httpClientFactory;
@ -46,4 +36,3 @@ namespace Webhooks.API.Services
} }
} }
}

View File

@ -1,36 +1,5 @@
using Autofac; namespace Webhooks.API;
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
{
public class Startup public class Startup
{ {
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
@ -347,4 +316,3 @@ namespace Webhooks.API
return services; return services;
} }
} }
}