This commit is contained in:
2023-01-18 00:41:04 +00:00
parent 64337d1e42
commit a2fda0e738
4 changed files with 43 additions and 27 deletions

View File

@@ -6,6 +6,7 @@ using Sockeye.Models;
using Sockeye.Api.ControllerHelpers;
using Newtonsoft.Json.Linq;
using System;
using Sockeye.Biz;
namespace Sockeye.Api.Controllers
{
@@ -36,6 +37,14 @@ namespace Sockeye.Api.Controllers
[HttpPost("shareit")]
public async Task<IActionResult> Post([FromHeader] string Authorization, [FromBody] JObject j)
{
if (!serverState.IsOpen)
{
var msg = ("Server state was not open when Vendor Order notification received; returning 503 (temp. unavailable) to them, they should retry when server open again.");
log.LogError(msg);
await NotifyEventHelper.AddOpsProblemEvent(msg);
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
}
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
@@ -50,19 +59,20 @@ namespace Sockeye.Api.Controllers
//put the jobject notification into the db as json string freeform notification information
//to be processed by other code later. i.e. just capture it as is cleanly and don't bother trying to do anything fancy here this should be tight and focused and side effect free
TODO
//although...on second thought it could just make a purchase record with some sort of state of unprocessed so a job could swing by and process it or we could
//do that manually so then there would be no need for extra UI and stuff, and it wont' conflict with the need to process immediately and lightly here
//i.e. two stage: one is to make the record barebones for purchase then a job comes along and turns it into a real purchase
//also add error handling here iwth proper notification see trial request code so we get notified on error
//and don't return OK / 200 unless the order is stored successfully in db as shareit will retry until it's successful several times, see the link below for deets
//although...on second thought it could just make a purchase record with some sort of state of unprocessed so a job could swing by and process it or we could
//do that manually so then there would be no need for extra UI and stuff, and it wont' conflict with the need to process immediately and lightly here
//i.e. two stage: one is to make the record barebones for purchase then a job comes along and turns it into a real purchase
//also add error handling here iwth proper notification see trial request code so we get notified on error
//and don't return OK / 200 unless the order is stored successfully in db as shareit will retry until it's successful several times, see the link below for deets
//Need to be able to make a manual purchase record with almost nothing more than the vendor notifciation text so can recover if auto system fails and for testing
//save it to the database
var VendorNotification = new VendorNotification();
VendorNotification.Vendor = "shareit";
VendorNotification.Data = j.ToString();
VendorNotification.Processed = false;
await ct.VendorNotification.AddAsync(VendorNotification);
var Purchase = new Purchase();
Purchase.PurchaseDate = DateTime.UtcNow;//this is kind of fucky, what if the order takes more than a day to arrive? I guess fixup from the vendordata later
Purchase.VendorId = 1;//MyCommerce/shareit is vendor 1, for now that's all that's needed
Purchase.VendorData = j.ToString();
await ct.Purchase.AddAsync(Purchase);
await ct.SaveChangesAsync();
}
@@ -70,12 +80,11 @@ TODO
}
catch (Exception ex)
{
//todo Log this here
System.Diagnostics.Debug.WriteLine($"order/shareit - Exception processing request: {ex.Message}");
log.LogError(ex, "OrderController/shareit - Exception processing vendor notification, returned 503 to vendor");
await NotifyEventHelper.AddOpsProblemEvent("OrderController/shareit - Exception processing vendor notification, see log");
return StatusCode(503);//ask it to retry again later
}
return Ok("ok");//shareit robot looks for an OK response to know if it should resend or not https://account.mycommerce.com/home/wiki/7479805
}
//------------