Skip to content

Commit

Permalink
Improved the capturing of phone number ordering responses and updated…
Browse files Browse the repository at this point in the history
… the purchased phone numbers page to be more useful.
  • Loading branch information
uncheckederror committed Oct 27, 2024
1 parent 457d4dc commit e9b0435
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 56 deletions.
11 changes: 7 additions & 4 deletions NumberSearch.DataAccess/BulkVS/OrderTn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ public async Task<OrderTnResponseBody> PostAsync(string username, string passwor
try
{
var response = await route.WithBasicAuth(username, password).PostJsonAsync(this).ReceiveString().ConfigureAwait(false);
OrderTnResponseBody? weatherForecast =
System.Text.Json.JsonSerializer.Deserialize<OrderTnResponseBody>(response);
OrderTnResponseBody weatherForecast =
System.Text.Json.JsonSerializer.Deserialize<OrderTnResponseBody>(response) ?? new();
weatherForecast.RawResponse = response;
return weatherForecast ?? new();
}
catch (FlurlHttpException ex)
{
Log.Error($"[Ingest] [BulkVS] Failed to order {TN}.");
Log.Error(await ex.GetResponseStringAsync());
var x = await ex.GetResponseStringAsync();
Log.Error(x);
var error = await ex.GetResponseJsonAsync<OrderTnFailed>();

return new OrderTnResponseBody
{
TN = TN,
Failed = error
Failed = error,
RawResponse = x
};
}
}
Expand All @@ -211,6 +213,7 @@ public class OrderTnResponseBody
[JsonProperty("TN Details")]
public OrderTnTNDetails TNDetails { get; set; } = new();
public OrderTnFailed Failed { get; set; } = new();
public string RawResponse { get; set; } = string.Empty;
}

public class OrderTnRouting
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Mvc/WorkerServices/MonitorLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task MonitorAsync()
nto.Purchased = string.IsNullOrWhiteSpace(orderResponse?.Failed?.Description) && orderResponse?.Status is "Active";
productOrder.DateOrdered = DateTime.Now;
// Keep the raw response as a receipt.
productOrder.OrderResponse = JsonSerializer.Serialize(orderResponse);
productOrder.OrderResponse = orderResponse?.RawResponse ?? JsonSerializer.Serialize(orderResponse);
// If the status code of the order comes back as 200 then it was successful.
productOrder.Completed = string.IsNullOrWhiteSpace(orderResponse?.Failed?.Description);
Expand Down
25 changes: 11 additions & 14 deletions NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

using NumberSearch.Ops.Models;

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -24,40 +25,36 @@ public class PurchasedPhoneNumbersController(numberSearchContext context) : Cont
[Route("/Home/NumberOrders/{dialedNumber}")]
public async Task<IActionResult> NumberOrders(Guid? orderId, string dialedNumber)
{
var owned = await context.OwnedPhoneNumbers.AsNoTracking().ToArrayAsync();

if (orderId.HasValue)
{
var orders = await context.PurchasedPhoneNumbers
.Where(x => x.OrderId == orderId)
.OrderByDescending(x => x.DateOrdered)
.AsNoTracking()
.ToListAsync();

if (orders is not null && orders.Count != 0)
{
foreach (var order in orders)
{
// Update the product orders here.
}
}
.ToArrayAsync();

return View("NumberOrders", orders);
return View("NumberOrders", new PurchasedResult { PurchasedPhoneNumbers = orders, Owned = owned });
}
else if (string.IsNullOrWhiteSpace(dialedNumber))
{
// Show all orders
var orders = await context.PurchasedPhoneNumbers.OrderByDescending(x => x.DateOrdered).AsNoTracking().ToListAsync();
var orders = await context.PurchasedPhoneNumbers.OrderByDescending(x => x.DateOrdered).AsNoTracking().ToArrayAsync();

return View("NumberOrders", orders);
return View("NumberOrders", new PurchasedResult { PurchasedPhoneNumbers = orders, Owned = owned });
}
else
{
var order = await context.PurchasedPhoneNumbers.AsNoTracking().FirstOrDefaultAsync(x => x.DialedNumber == dialedNumber);

return View("NumberOrders", new List<PurchasedPhoneNumber> { order ?? new() });
return View("NumberOrders", new PurchasedResult { PurchasedPhoneNumber = order, Owned = owned });

Check warning on line 51 in NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference assignment.

Check warning on line 51 in NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 51 in NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 51 in NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Possible null reference assignment.

Check warning on line 51 in NumberSearch.Ops/Controllers/PurchasedPhoneNumbersController.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Possible null reference assignment.
}
}

[Authorize]
[Route("/Home/ExportNumberOrders")]

public async Task<IActionResult> ExportNumberOrders()
{
var orders = await context.PurchasedPhoneNumbers.OrderByDescending(x => x.DateOrdered).AsNoTracking().ToListAsync();
Expand Down
13 changes: 13 additions & 0 deletions NumberSearch.Ops/Models/PurcahsedResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using AccelerateNetworks.Operations;

namespace NumberSearch.Ops.Models
{
public class PurchasedResult
{
public PurchasedPhoneNumber PurchasedPhoneNumber { get; set; } = new();
public PurchasedPhoneNumber[] PurchasedPhoneNumbers { get; set; } = [];
public OwnedPhoneNumber[] Owned { get; set; } = [];
public string Message { get; set; } = string.Empty;
public string AlertType { get; set; } = string.Empty;
}
}
64 changes: 27 additions & 37 deletions NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using AccelerateNetworks.Operations
@model IEnumerable<PurchasedPhoneNumber>
@model PurchasedResult
@{
ViewData["Title"] = "Purchased Numbers";
}
Expand All @@ -8,31 +8,19 @@
<table class="table table-striped table-bordered table-hover" id="table">
<thead>
<tr>
<th>
Number
</th>
<th scope="col">
Date Ordered
</th>
<th scope="col">
Order Information
</th>
<th scope="col">
Raw Response
</th>
<th>Status</th>
<th>Date Ordered</th>
<th>Provider</th>
<th>Number</th>
<th>Raw Response</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@{
if (Model?.FirstOrDefault() is null)
if (Model is not null && Model?.PurchasedPhoneNumbers?.Length != 0)
{
<tr>
<td colspan="4" class="alert-danger">There is no record of this number being purchased. ❓</td>
</tr>
}
else
{
foreach (var order in Model.Where(x => x?.IngestedFrom != "Test"))
foreach (var order in Model.PurchasedPhoneNumbers.Where(x => x?.IngestedFrom != "Test"))

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Dereference of a possibly null reference.

Check warning on line 23 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Dereference of a possibly null reference.
{
var ingestedBadge = order?.IngestedFrom;
switch (order?.IngestedFrom)
Expand All @@ -47,19 +35,11 @@
ingestedBadge = "<h4><span class='badge bg-warning'>TeleMessage</span></h4>";
break;
}
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(order.DialedNumber, out var phoneNumber);

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Possible null reference argument for parameter 'input' in 'bool PhoneNumber.TryParse(string input, out PhoneNumber number)'.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'input' in 'bool PhoneNumber.TryParse(string input, out PhoneNumber number)'.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Dereference of a possibly null reference.

Check warning on line 38 in NumberSearch.Ops/Views/PurchasedPhoneNumbers/NumberOrders.cshtml

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Possible null reference argument for parameter 'input' in 'bool PhoneNumber.TryParse(string input, out PhoneNumber number)'.
var ownedPhoneNumber = Model.Owned.FirstOrDefault(x => x.DialedNumber == phoneNumber.DialedNumber);
string AsDialedLink = checkParse && ownedPhoneNumber is not null && ownedPhoneNumber.Active ? $"<a href='/Home/OwnedNumbers/{ownedPhoneNumber.DialedNumber}' target='_blank'>{order.DialedNumber}</a>" : $"{order.DialedNumber}";
<tr>
<td data-order="@order?.DateOrdered.Ticks">
<h4>@order?.DialedNumber</h4>
</td>
<td scope="row">
<a href="https://acceleratenetworks.com/cart/order/@order?.OrderId" class="btn btn-primary" target="_blank" rel="noopener noreferrer">
Order
</a>
<h4 class="d-flex justify-content-between align-items-center mt-3">
<span class="badge bg-info rounded-pill">
@order?.DateOrdered
</span>
</h4>
@{
if (order?.Completed is not null && order.Completed)
{
Expand All @@ -72,16 +52,26 @@
}
</td>
<td>
@Html.Raw(ingestedBadge)
<strong>Date Ingested</strong>
<p>@order?.DateIngested</p>
@order?.DateOrdered
</td>
<td class="text-break">
<td>@order?.IngestedFrom</td>
<td>@Html.Raw(AsDialedLink)</td>
<td class="text-break text-wrap">
@order?.OrderResponse
</td>
<td>
<a href="https://acceleratenetworks.com/cart/order/@order?.OrderId" class="btn btn-primary">
View Order
</a>
</td>
</tr>
}

}
else
{
<tr>
<td colspan="4" class="alert-danger">No purchased phone numbers found. ❓</td>
</tr>
}
}
</tbody>
Expand Down

0 comments on commit e9b0435

Please sign in to comment.