From 126b495aaa5229358511cb8a94e04dcf02703769 Mon Sep 17 00:00:00 2001 From: Benjamin Arhen Date: Thu, 21 Dec 2023 04:14:51 +0000 Subject: [PATCH] Added new authentication feature by api key (#3) authored-by: barhen Reviewed-on: https://scm.biskilog.com/barhen/Biskilog_Server_Manager/pulls/3 Co-authored-by: Benjamin Arhen Co-committed-by: Benjamin Arhen --- ServerManager/ServiceRepo/CompanyService.cs | 2 +- ServerManager/SyncMethods/CompanySync.cs | 28 ++++++++++----------- ServerManager/SyncMethods/ProductSync.cs | 20 +++++++-------- ServerManager/SyncMethods/SalesSync.cs | 20 +++++++-------- ServerManager/Worker.cs | 5 ++-- ServerManager/appsettings.json | 4 +-- 6 files changed, 39 insertions(+), 40 deletions(-) diff --git a/ServerManager/ServiceRepo/CompanyService.cs b/ServerManager/ServiceRepo/CompanyService.cs index 11dfa26..b86d2eb 100644 --- a/ServerManager/ServiceRepo/CompanyService.cs +++ b/ServerManager/ServiceRepo/CompanyService.cs @@ -74,7 +74,7 @@ namespace ServerManager.ServiceRepo // Using Dapper to call a stored procedure with parameters var parameters = new { - a_tableName = "tblbranch", + a_tableName = "tblbranches", a_branchId = a_branch, lastModified = a_dateTime }; diff --git a/ServerManager/SyncMethods/CompanySync.cs b/ServerManager/SyncMethods/CompanySync.cs index a81c20e..8423d47 100644 --- a/ServerManager/SyncMethods/CompanySync.cs +++ b/ServerManager/SyncMethods/CompanySync.cs @@ -42,7 +42,7 @@ namespace ServerManager.SyncMethods } private async Task SyncCompanyTable() { - var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblcompanydetails"); + var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblcompanydetails"); if (!responseMessage.IsSuccessStatusCode) { return; @@ -66,7 +66,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblcompanydetails", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -75,7 +75,7 @@ namespace ServerManager.SyncMethods } private async Task SyncBranchTable() { - var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblbranch"); + var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblbranch"); if (!responseMessage.IsSuccessStatusCode) { return; @@ -85,7 +85,7 @@ namespace ServerManager.SyncMethods IEnumerable modifiedCart = await m_companyService.FetchBranch(date, "BRID0"); SyncTimestamp syncTimestamp = new SyncTimestamp { - TableName = "tblbranch", + TableName = "tblbranches", Timestamp = DateTime.Now.AddSeconds(-10), }; int batchSize = 200; @@ -99,7 +99,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblbranch", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -108,7 +108,7 @@ namespace ServerManager.SyncMethods } private async Task SyncCustomer() { - var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblCustomers"); + var responseMessage = await m_httpClient.GetAsync("/api/SyncCompanyInfo/lastsyncdate/tblCustomers"); if (!responseMessage.IsSuccessStatusCode) { return; @@ -132,7 +132,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblCustomers", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -161,7 +161,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbldriver", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -190,7 +190,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/SystemRoles", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -219,7 +219,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblTruckAssignment", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -248,7 +248,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbldrivermappings", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -277,7 +277,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbltruckinventory", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -306,7 +306,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tbltrucks", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -335,7 +335,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncCompanyInfo/publish/tblusers", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } diff --git a/ServerManager/SyncMethods/ProductSync.cs b/ServerManager/SyncMethods/ProductSync.cs index 5275867..14c1226 100644 --- a/ServerManager/SyncMethods/ProductSync.cs +++ b/ServerManager/SyncMethods/ProductSync.cs @@ -56,7 +56,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblproducts", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -85,7 +85,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblInventory", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -114,7 +114,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblInventoryentry", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -143,7 +143,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblRestock", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -172,7 +172,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tlpricechanges", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -201,7 +201,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -229,7 +229,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblStock", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -258,7 +258,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblbrands", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -287,7 +287,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblCategories", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -316,7 +316,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblunitofmeasure", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } diff --git a/ServerManager/SyncMethods/SalesSync.cs b/ServerManager/SyncMethods/SalesSync.cs index 9cf8bd2..8f1bac8 100644 --- a/ServerManager/SyncMethods/SalesSync.cs +++ b/ServerManager/SyncMethods/SalesSync.cs @@ -61,7 +61,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCart", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -94,7 +94,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblcancelledtransaction", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -127,7 +127,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCreditpurchase", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -156,7 +156,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblCustomerAccount", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -185,7 +185,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/CustomerPurchase", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -214,7 +214,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/DiscountLogs", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -243,7 +243,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliverydetails", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -272,7 +272,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliveryhead", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -301,7 +301,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblDeliveryrecipient", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } @@ -330,7 +330,7 @@ namespace ServerManager.SyncMethods var response = await m_httpClient.PostAsJsonAsync("/api/SyncSales/publish/tblinvoice", batch); if (response.IsSuccessStatusCode) { - Console.WriteLine($"Sent batch {batchIndex + 1}, Count: {batch.Count}"); + Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}"); } } diff --git a/ServerManager/Worker.cs b/ServerManager/Worker.cs index efedd9f..f68a365 100644 --- a/ServerManager/Worker.cs +++ b/ServerManager/Worker.cs @@ -24,9 +24,8 @@ namespace ServerManager string baseurl = m_configuration.GetValue("BaseUrl", "")!; HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(baseurl); - string token = m_configuration.GetValue("Token", "")!; - var authHeader = new AuthenticationHeaderValue("Bearer", token); - httpClient.DefaultRequestHeaders.Authorization = authHeader; + string token = m_configuration.GetValue("APIKEY", "")!; + httpClient.DefaultRequestHeaders.Add("BISK-API-KEY", token); using var scope = _serviceProvider.CreateScope(); var salesSync = scope.ServiceProvider.GetRequiredService(); diff --git a/ServerManager/appsettings.json b/ServerManager/appsettings.json index d491365..76d349f 100644 --- a/ServerManager/appsettings.json +++ b/ServerManager/appsettings.json @@ -8,8 +8,8 @@ "ConnectionStrings": { "Connection": "Server=BarhenVM\\SqlExpress;Database=BISK_POS;Integrated Security=True;TrustServerCertificate=true" }, - "Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMWM3MWE0Ni0xZmY2LTRkMGMtYmYzMS1iMTExMzJlMGM5ODQiLCJpYXQiOiIxNC8wOC8yMDIzIDY6MjI6MzIgcG0iLCJDb250cmFjdFN0YXJ0IjoiMTgvMDUvMjAyMyA4OjQ3OjI3IHBtIiwiQ29udHJhY3RFbmQiOiIxOC8wNS8yMDI0IDg6NDc6MjkgcG0iLCJVc2VySWQiOiIxIiwiVXNlcm5hbWUiOiJ0ZXN0IiwiRGJJZCI6IjEiLCJDb21wYXJpc29uTW9kZSI6IkZhbHNlIiwiQnJhbmNoSWQiOiJCUklEMCIsIkJyYW5jaEFjY2VzcyI6IkJSSUQwIiwiQ2xpZW50SWQiOiIxIiwiZXhwIjoxNjkzMjQ2OTUyLCJpc3MiOiJBVVRIIFNFUlZFUiIsImF1ZCI6IkJJU0tJTE9HIn0.W3kxw5kEj13TDSs96doR20IW96k3aO8uR5SKGiSaSX4", - "BaseUrl": "https://localhost:7247/", + "APIKEY": "AI1@h1BBmaU4d9LqU4W6UKGh7kWFNB9V", + "BaseUrl": "https://localhost:7122/", "AllowedHosts": "*", "JWT": { "Key": "@@BISKILOGACCOUNTING2023DEV??//##$",