Stuff and things
This commit is contained in:
38
PartSource.Api/Controllers/WebhooksController.cs
Normal file
38
PartSource.Api/Controllers/WebhooksController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using PartSource.Data.Dtos;
|
||||
using PartSource.Data.Models;
|
||||
using PartSource.Services;
|
||||
using Ratermania.Shopify.Resources;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PartSource.Api.Controllers
|
||||
{
|
||||
/// <remarks>
|
||||
/// This endpoint handles Shopify webhooks
|
||||
/// </remarks>
|
||||
[Route("v2/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = "v2")]
|
||||
public class WebhooksController : BaseApiController
|
||||
{
|
||||
private readonly ShopifyChangelogService _shopifyChangelogService;
|
||||
|
||||
public WebhooksController(ShopifyChangelogService shopifyChangelogService)
|
||||
{
|
||||
_shopifyChangelogService = shopifyChangelogService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("products/update")]
|
||||
public async Task<ActionResult> OnProductUpdate([FromBody]Product product)
|
||||
{
|
||||
await _shopifyChangelogService.AddEntry(product);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.15" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Ratermania.Shopify" Version="1.3.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="5.5.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -106,5 +106,10 @@
|
||||
<response code="200"><strong>OK:</strong> The engine with the provided EngineConfigId.</response>
|
||||
<response code="404"><strong>Not Found:</strong> No engine was found matching the provided EngineConfigId.</response>
|
||||
</member>
|
||||
<member name="T:PartSource.Api.Controllers.WebhooksController">
|
||||
<remarks>
|
||||
This endpoint handles Shopify webhooks
|
||||
</remarks>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -6,9 +6,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using PartSource.Api.Formatters;
|
||||
using PartSource.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using PartSource.Data.AutoMapper;
|
||||
using PartSource.Data.Contexts;
|
||||
using PartSource.Services;
|
||||
using System.IO;
|
||||
|
||||
@@ -30,6 +31,14 @@ namespace PartSource.Api
|
||||
{
|
||||
options.OutputFormatters.RemoveType(typeof(StringOutputFormatter));
|
||||
options.EnableEndpointRouting = false;
|
||||
})
|
||||
.AddNewtonsoftJson(options =>
|
||||
{
|
||||
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
|
||||
options.SerializerSettings.ContractResolver = new DefaultContractResolver()
|
||||
{
|
||||
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
};
|
||||
});
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
@@ -46,6 +55,7 @@ namespace PartSource.Api
|
||||
services.AddTransient<NexpartService>();
|
||||
services.AddTransient<SecurityService>();
|
||||
services.AddTransient<VehicleService>();
|
||||
services.AddTransient<ShopifyChangelogService>();
|
||||
|
||||
services.AddCors(o => o.AddPolicy("Default", builder =>
|
||||
{
|
||||
@@ -57,6 +67,9 @@ namespace PartSource.Api
|
||||
services.AddDbContext<PartSourceContext>(options =>
|
||||
options.UseSqlServer(Configuration.GetConnectionString("PartSourceDatabase"))
|
||||
);
|
||||
services.AddDbContext<FitmentContext>(options =>
|
||||
options.UseSqlServer(Configuration.GetConnectionString("FitmentDatabase"))
|
||||
);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"PartSourceDatabase": "Server=tcp:ps-whi.database.windows.net,1433;Initial Catalog=ps-whi-stage;Persist Security Info=False;User ID=ps-whi;Password=9-^*N5dw!6:|.5Q;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
|
||||
"FitmentDatabase": "Data Source=localhost;Initial Catalog=WhiFitment;Integrated Security=true"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
|
||||
Reference in New Issue
Block a user