Working endopints for single contracts and new payments | no email

main
Griffiths Lott 3 years ago
commit 0e44190638
  1. 2
      .gitignore
  2. 23
      Controllers/ContractController.cs
  3. 26
      Controllers/NewPaymentsController.cs
  4. 34
      Models/ContractData.cs
  5. 18
      Models/VendorPayment.cs
  6. 17
      PaymentServer.csproj
  7. 7
      PaymentServer.csproj.user
  8. 27
      Program.cs
  9. 31
      Properties/launchSettings.json
  10. 0
      README.md
  11. 101
      Services/PaymentDataService.cs
  12. 8
      appsettings.Development.json
  13. 9
      appsettings.json

2
.gitignore vendored

@ -0,0 +1,2 @@
bin/
obj/

@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PaymentServer.Models;
using PaymentServer.Services;
namespace PaymentServer.Controllers
{
[Route("[controller]")]
[ApiController]
public class ContractController : ControllerBase
{
[HttpGet("{contractNumber}")]
public ActionResult<VendorPayment> Get(string contractNumber)
{
// Validating the contract number is handled by the PaymentDataService
List<VendorPayment>? payments = PaymentDataService.GetContractData(contractNumber);
if (payments == null)
return NotFound();
return Ok(payments);
}
}
}

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PaymentServer.Models;
using PaymentServer.Services;
namespace PaymentServer.Controllers
{
[Route("[controller]")]
[ApiController]
public class NewPaymentsController : ControllerBase
{
[HttpGet("{timestamp}")]
public ActionResult<string> Get(string timestamp)
{
DateTime dateTime = DateTime.Parse(timestamp);
List<VendorPayment>? payments = PaymentDataService.GetNew(dateTime);
if (payments == null)
return NotFound();
ContractData contractData = new ContractData();
contractData.AddPayments(payments);
string contractJson = contractData.ToJson();
Console.WriteLine(contractJson);
return Ok(contractJson);
}
}
}

@ -0,0 +1,34 @@
using System.Collections.Generic;
using PaymentServer.Models;
using Newtonsoft.Json;
namespace PaymentServer.Models
{
public class ContractData
{
public Dictionary<string, List<VendorPayment>> contracts = new Dictionary<string, List<VendorPayment>>();
public void AddPayments(List<VendorPayment> vendorPayments)
{
List<string> existingContracts = new List<string>(this.contracts.Keys);
foreach (VendorPayment payment in vendorPayments)
{
if (existingContracts.Contains(payment.contractNumber))
{
this.contracts[payment.contractNumber].Add(payment);
}
else
{
this.contracts.Add(payment.contractNumber, new List<VendorPayment> { payment });
existingContracts.Add(payment.contractNumber);
}
}
Console.WriteLine(this.contracts.Count);
}
public string ToJson()
{
return JsonConvert.SerializeObject(this.contracts.Values);
}
}
}

@ -0,0 +1,18 @@
namespace PaymentServer.Models
{
public class VendorPayment
{
public string contractNumber { get; set; }
public string bachNumber { get; set; }
public string vendorId { get; set; }
public string pordNumber { get; set; }
public decimal purchaseAmount { get; set; }
public DateTime docDate { get; set; }
public DateTime dexRowTimestamp { get; set; }
public int? customerKey { get; set; }
public decimal? totalListPrice { get; set; }
public decimal? equipmentCost { get; set; }
public string? salesRep { get; set; }
public string? salesRepEmail { get; set; }
}
}

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Queryable" Version="4.3.0" />
</ItemGroup>
</Project>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>

@ -0,0 +1,27 @@
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:22575",
"sslPort": 44333
}
},
"profiles": {
"PaymentServer": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7100;http://localhost:5100",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,101 @@
using Microsoft.Data.SqlClient;
using PaymentServer.Models;
using System.Text.RegularExpressions;
namespace PaymentServer.Services
{
public static class PaymentDataService
{
static string connectionString = "Server=LPP-SQL01;Database=NLCF;Trusted_Connection=True;TrustServerCertificate=True;";
static string baseQuery = $@"
SELECT TOP (5000)
SUBSTRING(TRXDSCRN, PATINDEX('%[0-9]^3-[0-9]^7-[0-9]^3%', TRXDSCRN), 16) as ContractNumber
,BACHNUMB, VENDORID, PORDNMBR, PRCHAMNT, DOCDATE, DEX_ROW_TS
,app.CustomerKey
,app.TotalListPrice
,app.EquipmentCost
,ps.PersonnelName
,su.Email
FROM [NLCF].[dbo].[PM30200] as pif
LEFT JOIN[LCCPHL-PDSQL003].[LEAFCore].[dbo].[Application] as app
ON
app.ContractID = TRY_CAST(SUBSTRING(TRXDSCRN, PATINDEX('%[0-9]^3-[0-9]^7-[0-9]^3%', TRXDSCRN) + 5, 7) as int)
AND app.ScheduleID = TRY_CAST(SUBSTRING(TRXDSCRN, PATINDEX('%[0-9]^3-[0-9]^7-[0-9]^3%', TRXDSCRN) + 13, 3) as int)
AND app.LessorID = TRY_CAST(SUBSTRING(TRXDSCRN, PATINDEX('%[0-9]^3-[0-9]^7-[0-9]^3%', TRXDSCRN), 4) as int)
LEFT JOIN[LCCPHL-PDSQL003].[LEAFCore].[dbo].[Personnel] as ps
ON app.MarketingRepID = ps.PersonnelID
LEFT JOIN[LCCPHL-PDSQL003].[LEAFCore].[dbo].[SalesUser] as su
ON
(PARSENAME(REPLACE(ps.PersonnelName, ' ', '.'), 1) = su.FirstName AND REPLACE(REVERSE(PARSENAME(REVERSE(REPLACE(ps.PersonnelName, ' ', '.')), 1)), ',', '') = su.LastName)
WHERE DOCTYPE = 1
AND(BACHNUMB LIKE '%ACH%' OR BACHNUMB LIKE '%CKS%' OR BACHNUMB LIKE '%WIRE%' OR BACHNUMB LIKE '%CHK%' OR BACHNUMB LIKE '%CK%')";
static Regex contractNumberRegex = new Regex(@"\d{3}-\d{7}-\d{3}");
public static string? ValidContractNumber(string contractNumber)
{
Match match = contractNumberRegex.Match(contractNumber);
if (match.Success)
return match.Value;
else return null;
}
public static List<VendorPayment>? GetContractData(string contractNumber)
{
// Validate the contract number to make sure nothing strange get's added to the query
string query = baseQuery + $" AND TRXDSCRN = '{ValidContractNumber(contractNumber)}'";
return PullPaymentData(query);
}
public static List<VendorPayment>? GetNew(DateTime minTimestamp)
{
string query = baseQuery +$@" AND DEX_ROW_TS >= '{minTimestamp.ToString("yyyy-MM-dd HH:mm:ss")}
AND TRXDSCRN LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9]%''";
return PullPaymentData(query);
}
static List<VendorPayment>? PullPaymentData(string sqlQuery)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sqlQuery, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
List<VendorPayment>? payments = new List<VendorPayment>();
try
{
while (reader.Read())
{
VendorPayment paymentData = new VendorPayment
{
contractNumber = reader.GetString(0),
bachNumber = reader.GetString(1),
vendorId = reader.GetString(2),
pordNumber = reader.GetString(3),
purchaseAmount = reader.GetDecimal(4),
docDate = reader.GetDateTime(5),
dexRowTimestamp = reader.GetDateTime(6),
customerKey = reader.IsDBNull(7) ? null : reader.GetInt32(7),
totalListPrice = reader.IsDBNull(8) ? null : reader.GetDecimal(8),
equipmentCost = reader.IsDBNull(9) ? null : reader.GetDecimal(9),
salesRep = reader.IsDBNull(10) ? null : reader.GetString(10),
salesRepEmail = reader.IsDBNull(11) ? null : reader.GetString(11)
};
payments.Add(paymentData);
Console.WriteLine(String.Format("{0}", paymentData));
}
}
finally
{
reader.Close();
}
Console.WriteLine("Failed to get data...");
return payments;
}
}
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading…
Cancel
Save