From c6425fde99da45df31a796370eb6b2f718751326 Mon Sep 17 00:00:00 2001 From: Thomas Ryan Date: Wed, 14 Aug 2024 14:04:20 -0700 Subject: [PATCH] Added a new API endpoint. --- .../Controllers/CartAPIController.cs | 56 ++++++++++++++++++- .../Controllers/LookupController.cs | 10 ++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/NumberSearch.Mvc/Controllers/CartAPIController.cs b/NumberSearch.Mvc/Controllers/CartAPIController.cs index c5ee9011..15836f6a 100644 --- a/NumberSearch.Mvc/Controllers/CartAPIController.cs +++ b/NumberSearch.Mvc/Controllers/CartAPIController.cs @@ -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; @@ -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 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(); + await Parallel.ForEachAsync(parsedNumbers, async (number, token) => + { + var result = await lookup.VerifyPortabilityAsync(number); + results.Add(result); + }); + + var lookups = new List(); + 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 support@acceleratenetworks.com for help."); + } + } + + [HttpPost("Add/NewClient/{id}/ExtensionRegistration")] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public async Task AddNewClientExtensionRegistrationAsync([FromRoute] Guid id, [FromBody] ExtensionRegistration registration) @@ -609,7 +661,7 @@ public async Task 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; @@ -1088,7 +1140,7 @@ public async Task 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); diff --git a/NumberSearch.Mvc/Controllers/LookupController.cs b/NumberSearch.Mvc/Controllers/LookupController.cs index f5779a08..2d62882c 100644 --- a/NumberSearch.Mvc/Controllers/LookupController.cs +++ b/NumberSearch.Mvc/Controllers/LookupController.cs @@ -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 {