Skip to content

Commit

Permalink
Added a new API endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Aug 14, 2024
1 parent 4257aa1 commit c6425fd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
56 changes: 54 additions & 2 deletions NumberSearch.Mvc/Controllers/CartAPIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;

using NumberSearch.DataAccess;
using NumberSearch.DataAccess.BulkVS;
using NumberSearch.Mvc.Models;

using Org.BouncyCastle.Bcpg.Sig;

using PhoneNumbersNA;

using Serilog;

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -28,6 +34,52 @@ public CartAPIController(MvcConfiguration mvcConfiguration)
_configuration = mvcConfiguration;
}

public record BulkLookupResult(string DialedNumber, string City, string State, DateTime DateIngested, bool Wireless, bool Portable, DateTime LastPorted, string SPID, string LATA, string LEC, string LECType, string LIDBName, string LRN, string OCN);

[HttpGet("Number/Search/Bulk")]
public async Task<IActionResult> NumberSearchBulkAsync(string token, string dialedNumber)
{
if (!string.IsNullOrWhiteSpace(token) && token == "Memorable8142024")
{
// Add portable numbers to cart in bulk
if (!string.IsNullOrWhiteSpace(dialedNumber))
{
var parsedNumbers = dialedNumber.ExtractDialedNumbers();

if (!parsedNumbers.Any())
{
return BadRequest("No dialed phone numbers found. Please try a different query. 🥺👉👈");
}

var lookup = new LookupController(_configuration);

var results = new List<PortedPhoneNumber>();
await Parallel.ForEachAsync(parsedNumbers, async (number, token) =>
{
var result = await lookup.VerifyPortabilityAsync(number);
results.Add(result);
});

var lookups = new List<BulkLookupResult>();
foreach (var number in results)
{
lookups.Add(new BulkLookupResult(number.PortedDialedNumber, number.City,number.State, number.DateIngested, number.Wireless, number.Portable,number.LrnLookup.LastPorted,number.LrnLookup.SPID,number.LrnLookup.LATA,number.LrnLookup.LEC,number.LrnLookup.LECType,number.LrnLookup.LIDBName,number.LrnLookup.LRN,number.LrnLookup.OCN));
}

return Ok(lookups);
}
else
{
return BadRequest("No dialed phone numbers found. Please try a different query. 🥺👉👈");
}
}
else
{
return BadRequest("Token is invalid. Please supply the correct token in your request or contact [email protected] for help.");
}
}


[HttpPost("Add/NewClient/{id}/ExtensionRegistration")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public async Task<IActionResult> AddNewClientExtensionRegistrationAsync([FromRoute] Guid id, [FromBody] ExtensionRegistration registration)
Expand Down Expand Up @@ -609,7 +661,7 @@ public async Task<IActionResult> BuyPhoneNumberAsync(string dialedPhoneNumber)
return BadRequest(ModelState);
}

var phoneNumber = await PhoneNumber.GetAsync(dialedPhoneNumber, _postgresql).ConfigureAwait(false);
var phoneNumber = await DataAccess.PhoneNumber.GetAsync(dialedPhoneNumber, _postgresql).ConfigureAwait(false);
var productOrder = new ProductOrder { ProductOrderId = Guid.NewGuid(), DialedNumber = phoneNumber.DialedNumber, Quantity = 1 };

var purchasable = false;
Expand Down Expand Up @@ -1088,7 +1140,7 @@ public async Task<IActionResult> RemovePhoneNumberAsync(string dialedPhoneNumber
return BadRequest(ModelState);
}

var phoneNumber = new PhoneNumber { DialedNumber = dialedPhoneNumber };
var phoneNumber = new DataAccess.PhoneNumber { DialedNumber = dialedPhoneNumber };
var productOrder = new ProductOrder { DialedNumber = dialedPhoneNumber };

await _httpContext.Session.LoadAsync().ConfigureAwait(false);
Expand Down
10 changes: 6 additions & 4 deletions NumberSearch.Mvc/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,17 @@ await Parallel.ForEachAsync(parsedNumbers, async (number, token) =>
var wirelessPortable = results.Where(x => x.Wireless && x.Portable).ToArray();

var builder = new StringBuilder();
builder.AppendLine("DialedNumber,City,State,DateIngested,Wireless,Portable,LastPorted,SPID,LATA,LEC,LECType,LIDBName,LRN,OCN,Activation");
builder.AppendLine("DialedNumber,City,State,DateIngested,Wireless,Portable," +
"LastPorted,SPID,LATA,LEC,LECType," +
"LIDBName,LRN,OCN");
foreach (var number in results)
{
builder.AppendLine($"{number.PortedDialedNumber},{number.City},{number.State},{number.DateIngested},{number.Wireless},{number.Portable}," +
$"{number.LrnLookup.LastPorted},{number.LrnLookup.SPID},{number.LrnLookup.LATA},{number.LrnLookup.LEC},{number.LrnLookup.LECType}," +
$"{number.LrnLookup.LIDBName},{number.LrnLookup.LRN},{number.LrnLookup.OCN},{number.LrnLookup.LastPorted}");
$"{number.LrnLookup.LastPorted},{number.LrnLookup.SPID},{number.LrnLookup.LATA},{number.LrnLookup.LEC.Replace(","," ")},{number.LrnLookup.LECType}," +
$"{number.LrnLookup.LIDBName},{number.LrnLookup.LRN},{number.LrnLookup.OCN}");
}

return File(Encoding.UTF8.GetBytes(builder.ToString()), "text/csv", $"AccelerateNetworksPhoneNumbers{DateTime.Now.ToString("yyyyMMddTHHmmss")}.csv");
return File(Encoding.UTF8.GetBytes(builder.ToString()), "text/csv", $"AccelerateNetworksPhoneNumbers{DateTime.Now:yyyyMMddTHHmmss}.csv");
}
else
{
Expand Down

0 comments on commit c6425fd

Please sign in to comment.