diff --git a/C#api/ApiRequestHandler.cs b/C#api/ApiRequestHandler.cs deleted file mode 100644 index d162334..0000000 --- a/C#api/ApiRequestHandler.cs +++ /dev/null @@ -1,1356 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Text; -using Models; - -using Newtonsoft.Json; - -public class ApiRequestHandler -{ - public void HandleGet(HttpListenerRequest request, HttpListenerResponse response) - { - string apiKey = request.Headers["API_KEY"]; - var user = AuthProvider.GetUser(apiKey); - - if (user == null) - { - response.StatusCode = (int)HttpStatusCode.Unauthorized; - response.Close(); - return; - } - - try - { - string[] path = request.Url.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (path.Length > 2 && path[0] == "api" && path[1] == "v1") - { - HandleGetVersion1(path[2..], user, response); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - } - catch (Exception) - { - response.StatusCode = (int)HttpStatusCode.InternalServerError; - response.Close(); - } - } - - private void HandleGetVersion1(string[] path, User user, HttpListenerResponse response) - { - if (!AuthProvider.HasAccess(user, path[0], "get")) - { - response.StatusCode = (int)HttpStatusCode.Forbidden; - response.Close(); - return; - } - - switch (path[0]) - { - case "warehouses": - HandleWarehouses(path, response); - break; - case "locations": - HandleLocations(path, response); - break; - case "transfers": - HandleTransfers(path, response); - break; - case "items": - HandleItems(path, response); - break; - case "item_lines": - HandleItemLines(path, response); - break; - case "item_groups": - HandleItemGroups(path, response); - break; - case "item_types": - HandleItemTypes(path, response); - break; - case "inventories": - HandleInventories(path, response); - break; - case "suppliers": - HandleSuppliers(path, response); - break; - case "orders": - HandleOrders(path, response); - break; - case "clients": - HandleClients(path, response); - break; - case "shipments": - HandleShipments(path, response); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleWarehouses(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var warehouses = DataProvider.fetch_warehouse_pool().GetWarehouses(); - SendResponse(response, warehouses); - break; - case 2: - int warehouseId = int.Parse(path[1]); - var warehouse = DataProvider.fetch_warehouse_pool().GetWarehouse(warehouseId); - SendResponse(response, warehouse); - break; - case 3 when path[2] == "locations": - warehouseId = int.Parse(path[1]); - var locations = DataProvider.fetch_location_pool().GetLocationsInWarehouse(warehouseId); - SendResponse(response, locations); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleLocations(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var locations = DataProvider.fetch_location_pool().GetLocations(); - SendResponse(response, locations); - break; - case 2: - int locationId = int.Parse(path[1]); - var location = DataProvider.fetch_location_pool().GetLocation(locationId); - SendResponse(response, location); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleTransfers(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var transfers = DataProvider.fetch_transfer_pool().GetTransfers(); - SendResponse(response, transfers); - break; - case 2: - int transferId = int.Parse(path[1]); - var transfer = DataProvider.fetch_transfer_pool().GetTransfer(transferId); - SendResponse(response, transfer); - break; - case 3 when path[2] == "items": - transferId = int.Parse(path[1]); - var items = DataProvider.fetch_transfer_pool().GetItemsInTransfer(transferId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleItems(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var items = DataProvider.fetch_item_pool().GetItems(); - SendResponse(response, items); - break; - case 2: - var itemId = path[1]; - var item = DataProvider.fetch_item_pool().GetItem(itemId); - SendResponse(response, item); - break; - case 3 when path[2] == "inventory": - itemId = path[1]; - var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(itemId); - SendResponse(response, inventories); - break; - case 4 when path[2] == "inventory" && path[3] == "totals": - itemId = path[1]; - var totals = DataProvider.fetch_inventory_pool().GetInventoryTotalsForItem(itemId); - SendResponse(response, totals); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleItemLines(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var itemLines = DataProvider.fetch_itemline_pool().GetItemLines(); - SendResponse(response, itemLines); - break; - case 2: - int itemLineId = int.Parse(path[1]); - var itemLine = DataProvider.fetch_itemline_pool().GetItemLine(itemLineId); - SendResponse(response, itemLine); - break; - case 3 when path[2] == "items": - itemLineId = int.Parse(path[1]); - var items = DataProvider.fetch_item_pool().GetItemsForItemLine(itemLineId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleItemGroups(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var itemGroups = DataProvider.fetch_itemgroup_pool().GetItemGroups(); - SendResponse(response, itemGroups); - break; - case 2: - int itemGroupId = int.Parse(path[1]); - var itemGroup = DataProvider.fetch_itemgroup_pool().GetItemGroup(itemGroupId); - SendResponse(response, itemGroup); - break; - case 3 when path[2] == "items": - itemGroupId = int.Parse(path[1]); - var items = DataProvider.fetch_item_pool().GetItemsForItemGroup(itemGroupId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleItemTypes(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var itemTypes = DataProvider.fetch_itemtype_pool().GetItemTypes(); - SendResponse(response, itemTypes); - break; - case 2: - int itemTypeId = int.Parse(path[1]); - var itemType = DataProvider.fetch_itemtype_pool().GetItemType(itemTypeId); - SendResponse(response, itemType); - break; - case 3 when path[2] == "items": - itemTypeId = int.Parse(path[1]); - var items = DataProvider.fetch_item_pool().GetItemsForItemType(itemTypeId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleInventories(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var inventories = DataProvider.fetch_inventory_pool().GetInventories(); - SendResponse(response, inventories); - break; - case 2: - int inventoryId = int.Parse(path[1]); - var inventory = DataProvider.fetch_inventory_pool().GetInventory(inventoryId); - SendResponse(response, inventory); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleSuppliers(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var suppliers = DataProvider.fetch_supplier_pool().GetSuppliers(); - SendResponse(response, suppliers); - break; - case 2: - int supplierId = int.Parse(path[1]); - var supplier = DataProvider.fetch_supplier_pool().GetSupplier(supplierId); - SendResponse(response, supplier); - break; - case 3 when path[2] == "items": - supplierId = int.Parse(path[1]); - var items = DataProvider.fetch_item_pool().GetItemsForSupplier(supplierId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleOrders(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var orders = DataProvider.fetch_order_pool().GetOrders(); - SendResponse(response, orders); - break; - case 2: - int orderId = int.Parse(path[1]); - var order = DataProvider.fetch_order_pool().GetOrder(orderId); - SendResponse(response, order); - break; - case 3 when path[2] == "items": - orderId = int.Parse(path[1]); - var items = DataProvider.fetch_order_pool().GetItemsInOrder(orderId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleClients(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var clients = DataProvider.fetch_client_pool().GetClients(); - SendResponse(response, clients); - break; - case 2: - int clientId = int.Parse(path[1]); - var client = DataProvider.fetch_client_pool().GetClient(clientId); - SendResponse(response, client); - break; - case 3 when path[2] == "orders": - clientId = int.Parse(path[1]); - var orders = DataProvider.fetch_order_pool().GetOrdersForClient(clientId); - SendResponse(response, orders); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandleShipments(string[] path, HttpListenerResponse response) - { - switch (path.Length) - { - case 1: - var shipments = DataProvider.fetch_shipment_pool().GetShipments(); - SendResponse(response, shipments); - break; - case 2: - int shipmentId = int.Parse(path[1]); - var shipment = DataProvider.fetch_shipment_pool().GetShipment(shipmentId); - SendResponse(response, shipment); - break; - case 3 when path[2] == "orders": - shipmentId = int.Parse(path[1]); - var orders = DataProvider.fetch_order_pool().GetOrdersInShipment(shipmentId); - SendResponse(response, orders); - break; - case 3 when path[2] == "items": - shipmentId = int.Parse(path[1]); - var items = DataProvider.fetch_shipment_pool().GetItemsInShipment(shipmentId); - SendResponse(response, items); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - public void HandleDelete(HttpListenerRequest request, HttpListenerResponse response) - { - string apiKey = request.Headers["API_KEY"]; - var user = AuthProvider.GetUser(apiKey); - - if (user == null) - { - response.StatusCode = (int)HttpStatusCode.Unauthorized; - response.Close(); - return; - } - - try - { - string[] path = request.Url.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (path.Length > 2 && path[0] == "api" && path[1] == "v1") - { - HandleDeleteVersion1(path[2..], user, response); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - } - catch (Exception) - { - response.StatusCode = (int)HttpStatusCode.InternalServerError; - response.Close(); - } - } - - public void HandlePost(HttpListenerRequest request, HttpListenerResponse response) - { - string apiKey = request.Headers["API_KEY"]; - var user = AuthProvider.GetUser(apiKey); - - if (user == null) - { - response.StatusCode = (int)HttpStatusCode.Unauthorized; - response.Close(); - return; - } - - try - { - string[] path = request.Url.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (path.Length > 2 && path[0] == "api" && path[1] == "v1") - { - HandlePostVersion1(path[2..], user, request, response); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - } - catch (Exception) - { - response.StatusCode = (int)HttpStatusCode.InternalServerError; - response.Close(); - } - } - - public void HandlePut(HttpListenerRequest request, HttpListenerResponse response) - { - string apiKey = request.Headers["API_KEY"]; - var user = AuthProvider.GetUser(apiKey); - - if (user == null) - { - response.StatusCode = (int)HttpStatusCode.Unauthorized; - response.Close(); - return; - } - - try - { - string[] path = request.Url.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (path.Length > 2 && path[0] == "api" && path[1] == "v1") - { - HandlePutVersion1(path[2..], user, request, response); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - } - catch (Exception) - { - response.StatusCode = (int)HttpStatusCode.InternalServerError; - response.Close(); - } - } - - - private void HandlePostVersion1(string[] path, User user, HttpListenerRequest request, HttpListenerResponse response) - { - if (!AuthProvider.HasAccess(user, path[0], "post")) - { - response.StatusCode = (int)HttpStatusCode.Forbidden; - response.Close(); - return; - } - - int contentLength = (int)request.ContentLength64; - byte[] buffer = new byte[contentLength]; - request.InputStream.Read(buffer, 0, contentLength); - string postData = Encoding.UTF8.GetString(buffer); - - bool check; - switch (path[0]) - { - case "warehouses": - var newWarehouse = JsonConvert.DeserializeObject(postData); - if (newWarehouse.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_warehouse_pool().AddWarehouse(newWarehouse); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_warehouse_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "locations": - var newLocation = JsonConvert.DeserializeObject(postData); - if (newLocation.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_location_pool().AddLocation(newLocation); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_location_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "transfers": - var newTransfer = JsonConvert.DeserializeObject(postData); - if (newTransfer.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_transfer_pool().AddTransfer(newTransfer); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_transfer_pool().Save(); - var notificationSystem = new NotificationSystem(); - notificationSystem.Push($"Scheduled batch transfer {newTransfer.Id}"); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "items": - var newItem = JsonConvert.DeserializeObject(postData); - if (newItem.Uid == null) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_item_pool().AddItem(newItem); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_item_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "item_lines": - var newItemLine = JsonConvert.DeserializeObject(postData); - if (newItemLine.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemline_pool().AddItemline(newItemLine); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_itemline_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "item_types": - var newItemType = JsonConvert.DeserializeObject(postData); - if (newItemType.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemtype_pool().AddItemtype(newItemType); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_itemtype_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "item_groups": - var newItemGroup = JsonConvert.DeserializeObject(postData); - if (newItemGroup.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemgroup_pool().AddItemGroup(newItemGroup); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_itemgroup_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "inventories": - var newInventory = JsonConvert.DeserializeObject(postData); - if (newInventory.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_inventory_pool().AddInventory(newInventory); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_inventory_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "suppliers": - var newSupplier = JsonConvert.DeserializeObject(postData); - if (newSupplier.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_supplier_pool().AddSupplier(newSupplier); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_supplier_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "orders": - var newOrder = JsonConvert.DeserializeObject(postData); - if (newOrder.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_order_pool().AddOrder(newOrder); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_order_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "clients": - var newClient = JsonConvert.DeserializeObject(postData); - if (newClient.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_client_pool().AddClient(newClient); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_client_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - case "shipments": - var newShipment = JsonConvert.DeserializeObject(postData); - if (newShipment.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_shipment_pool().AddShipment(newShipment); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID in Body already exists in data"; - response.Close(); - return; - } - DataProvider.fetch_shipment_pool().Save(); - response.StatusCode = (int)HttpStatusCode.Created; - response.Close(); - break; - - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - break; - } - } - - private void HandlePutVersion1(string[] path, User user, HttpListenerRequest request, HttpListenerResponse response) - { - if (!AuthProvider.HasAccess(user, path[0], "put")) - { - response.StatusCode = (int)HttpStatusCode.Forbidden; - response.Close(); - return; - } - - int contentLength = (int)request.ContentLength64; - byte[] buffer = new byte[contentLength]; - request.InputStream.Read(buffer, 0, contentLength); - string putData = Encoding.UTF8.GetString(buffer); - - bool check; - - switch (path[0]) - { - case "warehouses": - int warehouseId = int.Parse(path[1]); - var updatedWarehouse = JsonConvert.DeserializeObject(putData); - if (updatedWarehouse.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_warehouse_pool().UpdateWarehouse(warehouseId, updatedWarehouse); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_warehouse_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "locations": - int locationId = int.Parse(path[1]); - var updatedLocation = JsonConvert.DeserializeObject(putData); - if (updatedLocation.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_location_pool().UpdateLocation(locationId, updatedLocation); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_location_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "transfers": - if (path.Length == 2) // Update transfer - { - int transferId = int.Parse(path[1]); - var updatedTransfer = JsonConvert.DeserializeObject(putData); - if (updatedTransfer.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_transfer_pool().UpdateTransfer(transferId, updatedTransfer); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_transfer_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else if (path.Length == 3 && path[2] == "commit") // Commit transfer - { - int transferId = int.Parse(path[1]); - var transfer = DataProvider.fetch_transfer_pool().GetTransfer(transferId); - if (transfer is null) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - if (transfer.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - // Update inventories based on transfer items - foreach (var item in transfer.Items) - { - var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(item.Item_Id); - foreach (var inventory in inventories) - { - if (transfer.Transfer_From is null) break; - if (inventory.Locations.Contains((int)transfer.Transfer_From)) - { - inventory.Total_On_Hand -= item.Amount; - } - else if (inventory.Locations.Contains((int)transfer.Transfer_To)) - { - inventory.Total_On_Hand += item.Amount; - } - DataProvider.fetch_inventory_pool().UpdateInventory(inventory.Id, inventory); - } - } - transfer.Transfer_Status = "Processed"; - check = DataProvider.fetch_transfer_pool().UpdateTransfer(transferId, transfer); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - // Notify processing completion - var notificationSystem = new NotificationSystem(); - notificationSystem.Push($"Processed batch transfer with id: {transfer.Id}"); - DataProvider.fetch_transfer_pool().Save(); - DataProvider.fetch_inventory_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - break; - - case "items": - string itemId = path[1]; - var updatedItem = JsonConvert.DeserializeObject(putData); - if (updatedItem.Uid == null) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_item_pool().UpdateItem(itemId, updatedItem); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_item_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "item_lines": - int itemLineId = int.Parse(path[1]); - var updatedItemLine = JsonConvert.DeserializeObject(putData); - if (updatedItemLine.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemline_pool().UpdateItemline(itemLineId, updatedItemLine); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_itemline_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "item_types": - int itemTypeId = int.Parse(path[1]); - var updatedItemType = JsonConvert.DeserializeObject(putData); - if (updatedItemType.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemtype_pool().UpdateItemtype(itemTypeId, updatedItemType); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_itemtype_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "item_groups": - int itemGroupId = int.Parse(path[1]); - var updatedItemGroup = JsonConvert.DeserializeObject(putData); - if (updatedItemGroup.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_itemgroup_pool().UpdateItemGroup(itemGroupId, updatedItemGroup); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_itemgroup_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "inventories": - int inventoryId = int.Parse(path[1]); - var updatedInventory = JsonConvert.DeserializeObject(putData); - if (updatedInventory.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_inventory_pool().UpdateInventory(inventoryId, updatedInventory); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_inventory_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "suppliers": - int supplierId = int.Parse(path[1]); - var updatedSupplier = JsonConvert.DeserializeObject(putData); - if (updatedSupplier.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_supplier_pool().UpdateSupplier(supplierId, updatedSupplier); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_supplier_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "orders": - if (path.Length == 2) // Update order - { - int orderId = int.Parse(path[1]); - var updatedOrder = JsonConvert.DeserializeObject(putData); - if (updatedOrder.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_order_pool().UpdateOrder(orderId, updatedOrder); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_order_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else if (path.Length == 3 && path[2] == "items") // Update items in order - { - int orderId = int.Parse(path[1]); - var updatedItems = JsonConvert.DeserializeObject>(putData); - if (updatedItems.Any(x => x.Uid == null)) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given (everywhere) in body"; - response.Close(); - return; - } - DataProvider.fetch_order_pool().UpdateItemsInOrder(orderId, updatedItems); - DataProvider.fetch_order_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - break; - - case "clients": - int clientId = int.Parse(path[1]); - var updatedClient = JsonConvert.DeserializeObject(putData); - if (updatedClient.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_client_pool().UpdateClient(clientId, updatedClient); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_client_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - break; - - case "shipments": - if (path.Length == 2) // Update shipment - { - int shipmentId = int.Parse(path[1]); - var updatedShipment = JsonConvert.DeserializeObject(putData); - if (updatedShipment.Id == -10) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given in body"; - response.Close(); - return; - } - check = DataProvider.fetch_shipment_pool().UpdateShipment(shipmentId, updatedShipment); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - DataProvider.fetch_shipment_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else if (path.Length == 3 && path[2] == "orders") // Update orders in shipment - { - int shipmentId = int.Parse(path[1]); - var updatedOrders = JsonConvert.DeserializeObject>(putData); - if (updatedOrders.Any(x => x.Id == -10)) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given (everywhere) in body"; - response.Close(); - return; - } - if (DataProvider.fetch_shipment_pool().GetShipment(shipmentId) == null) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "No data for given ID"; - response.Close(); - return; - } - DataProvider.fetch_order_pool().UpdateOrdersInShipment(shipmentId, updatedOrders); - DataProvider.fetch_order_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else if (path.Length == 3 && path[2] == "items") // Update items in shipment - { - int shipmentId = int.Parse(path[1]); - var updatedItems = JsonConvert.DeserializeObject>(putData); - if (updatedItems.Any(x => x.Uid == null)) - { - response.StatusCode = (int)HttpStatusCode.BadRequest; - response.StatusDescription = "ID not given (everywhere) in body"; - response.Close(); - return; - } - if (DataProvider.fetch_shipment_pool().GetShipment(shipmentId) == null) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "No data for given ID"; - response.Close(); - return; - } - DataProvider.fetch_shipment_pool().UpdateItemsInShipment(shipmentId, updatedItems); - DataProvider.fetch_shipment_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else if (path.Length == 3 && path[2] == "commit") // Commit shipment - { - int shipmentId = int.Parse(path[1]); - var shipment = DataProvider.fetch_shipment_pool().GetShipment(shipmentId); - if (shipment == null) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "No data found with given ID"; - response.Close(); - return; - } - // Update inventories based on shipment items - foreach (var item in shipment.Items) - { - var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(item.Item_Id); - foreach (var inventory in inventories) - { - if (inventory.Locations.Contains(shipment.Source_Id)) - { - inventory.Total_On_Hand -= item.Amount; - } - } - } - shipment.Shipment_Status = "Shipped"; - check = DataProvider.fetch_shipment_pool().UpdateShipment(shipmentId, shipment); - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or ID in Body and in Route are not matching"; - response.Close(); - return; - } - var notificationSystem = new NotificationSystem(); - notificationSystem.Push($"Shipment with id: {shipment.Id} has been processed."); - DataProvider.fetch_shipment_pool().Save(); - DataProvider.fetch_inventory_pool().Save(); - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - else - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - } - break; - - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - break; - } - - response.Close(); - } - - - private void HandleDeleteVersion1(string[] path, User user, HttpListenerResponse response) - { - if (!AuthProvider.HasAccess(user, path[0], "delete")) - { - response.StatusCode = (int)HttpStatusCode.Forbidden; - response.Close(); - return; - } - - bool check; - - switch (path[0]) - { - case "warehouses": - int warehouseId = int.Parse(path[1]); - check = DataProvider.fetch_warehouse_pool().RemoveWarehouse(warehouseId); - if (check) DataProvider.fetch_warehouse_pool().Save(); - break; - case "locations": - int locationId = int.Parse(path[1]); - check = DataProvider.fetch_location_pool().RemoveLocation(locationId); - if (check) DataProvider.fetch_location_pool().Save(); - break; - case "transfers": - int transferId = int.Parse(path[1]); - check = DataProvider.fetch_transfer_pool().RemoveTransfer(transferId); - if (check) DataProvider.fetch_transfer_pool().Save(); - break; - case "items": - string itemId = path[1]; - check = DataProvider.fetch_item_pool().RemoveItem(itemId); - if (check) DataProvider.fetch_item_pool().Save(); - break; - case "item_lines": - int itemLineId = int.Parse(path[1]); - check = DataProvider.fetch_itemline_pool().RemoveItemline(itemLineId); - if (check) DataProvider.fetch_itemline_pool().Save(); - break; - case "item_groups": - int itemGroupId = int.Parse(path[1]); - check = DataProvider.fetch_itemgroup_pool().RemoveItemGroup(itemGroupId); - if (check) DataProvider.fetch_itemgroup_pool().Save(); - break; - case "item_types": - int itemTypeId = int.Parse(path[1]); - check = DataProvider.fetch_itemtype_pool().RemoveItemtype(itemTypeId); - if (check) DataProvider.fetch_itemtype_pool().Save(); - break; - case "inventories": - int inventoryId = int.Parse(path[1]); - check = DataProvider.fetch_inventory_pool().RemoveInventory(inventoryId); - if (check) DataProvider.fetch_inventory_pool().Save(); - break; - case "suppliers": - int supplierId = int.Parse(path[1]); - check = DataProvider.fetch_supplier_pool().RemoveSupplier(supplierId); - if (check) DataProvider.fetch_supplier_pool().Save(); - break; - case "orders": - int orderId = int.Parse(path[1]); - check = DataProvider.fetch_order_pool().RemoveOrder(orderId); - if (check) DataProvider.fetch_order_pool().Save(); - break; - case "clients": - int clientId = int.Parse(path[1]); - check = DataProvider.fetch_client_pool().RemoveClient(clientId); - if (check) DataProvider.fetch_client_pool().Save(); - break; - case "shipments": - int shipmentId = int.Parse(path[1]); - check = DataProvider.fetch_shipment_pool().RemoveShipment(shipmentId); - if (check) DataProvider.fetch_shipment_pool().Save(); - break; - default: - response.StatusCode = (int)HttpStatusCode.NotFound; - response.Close(); - return; - } - - if (!check) - { - response.StatusCode = (int)HttpStatusCode.NotFound; - response.StatusDescription = "ID not found or other data is dependent on this data"; - response.Close(); - return; - } - - response.StatusCode = (int)HttpStatusCode.OK; - response.Close(); - } - - - private void SendResponse(HttpListenerResponse response, object data) - { - response.StatusCode = (int)HttpStatusCode.OK; - if (data == null) response.StatusCode = (int)HttpStatusCode.NotFound; - response.ContentType = "application/json"; - using (var writer = new StreamWriter(response.OutputStream)) - { - string jsonResponse = System.Text.Json.JsonSerializer.Serialize(data); - writer.Write(jsonResponse); - } - response.Close(); - } -} diff --git a/C#api/Controllers/BaseApiController.cs b/C#api/Controllers/BaseApiController.cs new file mode 100644 index 0000000..39bfe74 --- /dev/null +++ b/C#api/Controllers/BaseApiController.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public abstract class BaseApiController : ControllerBase +{ + protected readonly NotificationSystem _notificationSystem; + + public BaseApiController( + NotificationSystem notificationSystem) + { + _notificationSystem = notificationSystem; + } + + protected IActionResult CheckAuthorization(string apiKey, string resource, string operation) + { + var user = AuthProvider.GetUser(apiKey); + if (user == null) + return Unauthorized(); + + if (!AuthProvider.HasAccess(user, resource, operation)) + return Forbid(); + + return null; + } +} \ No newline at end of file diff --git a/C#api/Controllers/ClientsController.cs b/C#api/Controllers/ClientsController.cs new file mode 100644 index 0000000..870aae2 --- /dev/null +++ b/C#api/Controllers/ClientsController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class ClientsController : BaseApiController +{ + public ClientsController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetClients() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "get"); + if (auth != null) return auth; + + var clients = DataProvider.fetch_client_pool().GetClients(); + return Ok(clients); + } + + [HttpGet("{id}")] + public IActionResult GetClient(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "get"); + if (auth != null) return auth; + + var client = DataProvider.fetch_client_pool().GetClient(id); + if (client == null) return NotFound(); + + return Ok(client); + } + + [HttpGet("{id}/orders")] + public IActionResult GetClientOrders(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "get"); + if (auth != null) return auth; + + var orders = DataProvider.fetch_order_pool().GetOrdersForClient(id); + return Ok(orders); + } + + [HttpPost] + public IActionResult CreateClient([FromBody] Client client) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "post"); + if (auth != null) return auth; + + if (client.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_client_pool().AddClient(client); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_client_pool().Save(); + return CreatedAtAction(nameof(GetClient), new { id = client.Id }, client); + } + + [HttpPut("{id}")] + public IActionResult UpdateClient(int id, [FromBody] Client client) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "put"); + if (auth != null) return auth; + + if (client.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_client_pool().UpdateClient(id, client); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_client_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteClient(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "clients", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_client_pool().RemoveClient(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_client_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/InventoriesController.cs b/C#api/Controllers/InventoriesController.cs new file mode 100644 index 0000000..2ea49a9 --- /dev/null +++ b/C#api/Controllers/InventoriesController.cs @@ -0,0 +1,79 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class InventoriesController : BaseApiController +{ + public InventoriesController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetInventories() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "inventories", "get"); + if (auth != null) return auth; + + var inventories = DataProvider.fetch_inventory_pool().GetInventories(); + return Ok(inventories); + } + + [HttpGet("{id}")] + public IActionResult GetInventory(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "inventories", "get"); + if (auth != null) return auth; + + var inventory = DataProvider.fetch_inventory_pool().GetInventory(id); + if (inventory == null) return NotFound(); + + return Ok(inventory); + } + + [HttpPost] + public IActionResult CreateInventory([FromBody] Inventory inventory) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "inventories", "post"); + if (auth != null) return auth; + + if (inventory.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_inventory_pool().AddInventory(inventory); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_inventory_pool().Save(); + return CreatedAtAction(nameof(GetInventory), new { id = inventory.Id }, inventory); + } + + [HttpPut("{id}")] + public IActionResult UpdateInventory(int id, [FromBody] Inventory inventory) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "inventories", "put"); + if (auth != null) return auth; + + if (inventory.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_inventory_pool().UpdateInventory(id, inventory); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_inventory_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteInventory(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "inventories", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_inventory_pool().RemoveInventory(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_inventory_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/Item_GroupsController.cs b/C#api/Controllers/Item_GroupsController.cs new file mode 100644 index 0000000..e314c6e --- /dev/null +++ b/C#api/Controllers/Item_GroupsController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class Item_GroupsController : BaseApiController +{ + public Item_GroupsController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetItemGroups() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "get"); + if (auth != null) return auth; + + var itemGroups = DataProvider.fetch_itemgroup_pool().GetItemGroups(); + return Ok(itemGroups); + } + + [HttpGet("{id}")] + public IActionResult GetItemGroup(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "get"); + if (auth != null) return auth; + + var itemGroup = DataProvider.fetch_itemgroup_pool().GetItemGroup(id); + if (itemGroup == null) return NotFound(); + + return Ok(itemGroup); + } + + [HttpGet("{id}/items")] + public IActionResult GetItemGroupItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_item_pool().GetItemsForItemGroup(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateItemGroup([FromBody] ItemGroup itemGroup) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "post"); + if (auth != null) return auth; + + if (itemGroup.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemgroup_pool().AddItemGroup(itemGroup); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_itemgroup_pool().Save(); + return CreatedAtAction(nameof(GetItemGroup), new { id = itemGroup.Id }, itemGroup); + } + + [HttpPut("{id}")] + public IActionResult UpdateItemGroup(int id, [FromBody] ItemGroup itemGroup) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "put"); + if (auth != null) return auth; + + if (itemGroup.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemgroup_pool().UpdateItemGroup(id, itemGroup); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_itemgroup_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteItemGroup(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_groups", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_itemgroup_pool().RemoveItemGroup(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_itemgroup_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/Item_LinesController.cs b/C#api/Controllers/Item_LinesController.cs new file mode 100644 index 0000000..238d807 --- /dev/null +++ b/C#api/Controllers/Item_LinesController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class Item_LinesController : BaseApiController +{ + public Item_LinesController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetItemLines() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "get"); + if (auth != null) return auth; + + var itemLines = DataProvider.fetch_itemline_pool().GetItemLines(); + return Ok(itemLines); + } + + [HttpGet("{id}")] + public IActionResult GetItemLine(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "get"); + if (auth != null) return auth; + + var itemLine = DataProvider.fetch_itemline_pool().GetItemLine(id); + if (itemLine == null) return NotFound(); + + return Ok(itemLine); + } + + [HttpGet("{id}/items")] + public IActionResult GetItemLineItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_item_pool().GetItemsForItemLine(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateItemLine([FromBody] ItemLine itemLine) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "post"); + if (auth != null) return auth; + + if (itemLine.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemline_pool().AddItemline(itemLine); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_itemline_pool().Save(); + return CreatedAtAction(nameof(GetItemLine), new { id = itemLine.Id }, itemLine); + } + + [HttpPut("{id}")] + public IActionResult UpdateItemLine(int id, [FromBody] ItemLine itemLine) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "put"); + if (auth != null) return auth; + + if (itemLine.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemline_pool().UpdateItemline(id, itemLine); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_itemline_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteItemLine(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_lines", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_itemline_pool().RemoveItemline(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_itemline_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/Item_TypesController.cs b/C#api/Controllers/Item_TypesController.cs new file mode 100644 index 0000000..88f75c7 --- /dev/null +++ b/C#api/Controllers/Item_TypesController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class Item_TypesController : BaseApiController +{ + public Item_TypesController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetItemTypes() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "get"); + if (auth != null) return auth; + + var itemTypes = DataProvider.fetch_itemtype_pool().GetItemTypes(); + return Ok(itemTypes); + } + + [HttpGet("{id}")] + public IActionResult GetItemType(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "get"); + if (auth != null) return auth; + + var itemType = DataProvider.fetch_itemtype_pool().GetItemType(id); + if (itemType == null) return NotFound(); + + return Ok(itemType); + } + + [HttpGet("{id}/items")] + public IActionResult GetItemTypeItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_item_pool().GetItemsForItemType(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateItemType([FromBody] ItemType itemType) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "post"); + if (auth != null) return auth; + + if (itemType.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemtype_pool().AddItemtype(itemType); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_itemtype_pool().Save(); + return CreatedAtAction(nameof(GetItemType), new { id = itemType.Id }, itemType); + } + + [HttpPut("{id}")] + public IActionResult UpdateItemType(int id, [FromBody] ItemType itemType) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "put"); + if (auth != null) return auth; + + if (itemType.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_itemtype_pool().UpdateItemtype(id, itemType); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_itemtype_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteItemType(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "item_types", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_itemtype_pool().RemoveItemtype(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_itemtype_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/ItemsController.cs b/C#api/Controllers/ItemsController.cs new file mode 100644 index 0000000..8362f24 --- /dev/null +++ b/C#api/Controllers/ItemsController.cs @@ -0,0 +1,99 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class ItemsController : BaseApiController +{ + public ItemsController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetItems() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_item_pool().GetItems(); + return Ok(items); + } + + [HttpGet("{id}")] + public IActionResult GetItem(string id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "get"); + if (auth != null) return auth; + + var item = DataProvider.fetch_item_pool().GetItem(id); + if (item == null) return NotFound(); + + return Ok(item); + } + + [HttpGet("{id}/inventory")] + public IActionResult GetItemInventories(string id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "get"); + if (auth != null) return auth; + + var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(id); + return Ok(inventories); + } + + [HttpGet("{id}/inventory/totals")] + public IActionResult GetItemInventoryTotals(string id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "get"); + if (auth != null) return auth; + + var totals = DataProvider.fetch_inventory_pool().GetInventoryTotalsForItem(id); + return Ok(totals); + } + + [HttpPost] + public IActionResult CreateItem([FromBody] Item item) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "post"); + if (auth != null) return auth; + + if (item.Uid == null) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_item_pool().AddItem(item); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_item_pool().Save(); + return CreatedAtAction(nameof(GetItem), new { id = item.Uid }, item); + } + + [HttpPut("{id}")] + public IActionResult UpdateItem(string id, [FromBody] Item item) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "put"); + if (auth != null) return auth; + + if (item.Uid == null) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_item_pool().UpdateItem(id, item); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_item_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteItem(string id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "items", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_item_pool().RemoveItem(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_item_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/LocationsController.cs b/C#api/Controllers/LocationsController.cs new file mode 100644 index 0000000..cbf518d --- /dev/null +++ b/C#api/Controllers/LocationsController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class LocationsController : BaseApiController +{ + public LocationsController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetLocations() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "get"); + if (auth != null) return auth; + + var locations = DataProvider.fetch_location_pool().GetLocations(); + return Ok(locations); + } + + [HttpGet("{id}")] + public IActionResult GetLocation(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "get"); + if (auth != null) return auth; + + var location = DataProvider.fetch_location_pool().GetLocation(id); + if (location == null) return NotFound(); + + return Ok(location); + } + + [HttpGet("{id}/inventory")] + public IActionResult GetLocationInventory(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "get"); + if (auth != null) return auth; + + var inventory = DataProvider.fetch_location_pool().GetLocationsInWarehouse(id); + return Ok(inventory); + } + + [HttpPost] + public IActionResult CreateLocation([FromBody] Location location) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "post"); + if (auth != null) return auth; + + if (location.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_location_pool().AddLocation(location); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_location_pool().Save(); + return CreatedAtAction(nameof(GetLocation), new { id = location.Id }, location); + } + + [HttpPut("{id}")] + public IActionResult UpdateLocation(int id, [FromBody] Location location) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "put"); + if (auth != null) return auth; + + if (location.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_location_pool().UpdateLocation(id, location); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_location_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteLocation(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "locations", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_location_pool().RemoveLocation(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_location_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/OrdersController.cs b/C#api/Controllers/OrdersController.cs new file mode 100644 index 0000000..116bfa1 --- /dev/null +++ b/C#api/Controllers/OrdersController.cs @@ -0,0 +1,136 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class OrdersController : BaseApiController +{ + public OrdersController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetOrders() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "get"); + if (auth != null) return auth; + + var orders = DataProvider.fetch_order_pool().GetOrders(); + return Ok(orders); + } + + [HttpGet("{id}")] + public IActionResult GetOrder(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "get"); + if (auth != null) return auth; + + var order = DataProvider.fetch_order_pool().GetOrder(id); + if (order == null) return NotFound(); + + return Ok(order); + } + + [HttpGet("{id}/items")] + public IActionResult GetOrderItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_order_pool().GetItemsInOrder(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateOrder([FromBody] Order order) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "post"); + if (auth != null) return auth; + + if (order.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_order_pool().AddOrder(order); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_order_pool().Save(); + return CreatedAtAction(nameof(GetOrder), new { id = order.Id }, order); + } + + [HttpPut("{id}")] + public IActionResult UpdateOrder(int id, [FromBody] Order order) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "put"); + if (auth != null) return auth; + + if (order.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_order_pool().UpdateOrder(id, order); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_order_pool().Save(); + return Ok(); + } + + [HttpPut("{id}/items")] + public IActionResult UpdateOrderItems(int id, [FromBody] List items) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "put"); + if (auth != null) return auth; + + if (items.Any(x => x.Uid == null)) return BadRequest("ID not given in body"); + + if (DataProvider.fetch_order_pool().GetOrder(id) == null) + return NotFound("No data for given ID"); + + DataProvider.fetch_order_pool().UpdateItemsInOrder(id, items); + DataProvider.fetch_order_pool().Save(); + return Ok(); + } + + [HttpPut("{id}/commit")] + public IActionResult CommitOrder(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "put"); + if (auth != null) return auth; + + var order = DataProvider.fetch_order_pool().GetOrder(id); + if (order == null) return NotFound("No data found with given ID"); + + foreach (var item in order.Items) + { + var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(item.Item_Id); + foreach (var inventory in inventories) + { + if (inventory.Locations.Contains(order.Source_Id)) + { + inventory.Total_On_Hand -= item.Amount; + } + } + } + + order.Order_Status = "Processed"; + var success = DataProvider.fetch_order_pool().UpdateOrder(id, order); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + _notificationSystem.Push($"Order with id: {order.Id} has been processed."); + DataProvider.fetch_order_pool().Save(); + DataProvider.fetch_inventory_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteOrder(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "orders", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_order_pool().RemoveOrder(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_order_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/ShipmentsController.cs b/C#api/Controllers/ShipmentsController.cs new file mode 100644 index 0000000..9af786b --- /dev/null +++ b/C#api/Controllers/ShipmentsController.cs @@ -0,0 +1,162 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class ShipmentsController : BaseApiController +{ + public ShipmentsController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetShipments() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "get"); + if (auth != null) return auth; + + var shipments = DataProvider.fetch_shipment_pool().GetShipments(); + return Ok(shipments); + } + + [HttpGet("{id}")] + public IActionResult GetShipment(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "get"); + if (auth != null) return auth; + + var shipment = DataProvider.fetch_shipment_pool().GetShipment(id); + if (shipment == null) return NotFound(); + + return Ok(shipment); + } + + [HttpGet("{id}/orders")] + public IActionResult GetShipmentOrders(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "get"); + if (auth != null) return auth; + + var orders = DataProvider.fetch_order_pool().GetOrdersInShipment(id); + return Ok(orders); + } + + [HttpGet("{id}/items")] + public IActionResult GetShipmentItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_shipment_pool().GetItemsInShipment(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateShipment([FromBody] Shipment shipment) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "post"); + if (auth != null) return auth; + + if (shipment.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_shipment_pool().AddShipment(shipment); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_shipment_pool().Save(); + return CreatedAtAction(nameof(GetShipment), new { id = shipment.Id }, shipment); + } + + [HttpPut("{id}")] + public IActionResult UpdateShipment(int id, [FromBody] Shipment shipment) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "put"); + if (auth != null) return auth; + + if (shipment.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_shipment_pool().UpdateShipment(id, shipment); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_shipment_pool().Save(); + return Ok(); + } + + [HttpPut("{id}/orders")] + public IActionResult UpdateShipmentOrders(int id, [FromBody] List orders) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "put"); + if (auth != null) return auth; + + if (orders.Any(x => x.Id == -10)) return BadRequest("ID not given in body"); + + if (DataProvider.fetch_shipment_pool().GetShipment(id) == null) + return NotFound("No data for given ID"); + + DataProvider.fetch_order_pool().UpdateOrdersInShipment(id, orders); + DataProvider.fetch_order_pool().Save(); + return Ok(); + } + + [HttpPut("{id}/items")] + public IActionResult UpdateShipmentItems(int id, [FromBody] List items) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "put"); + if (auth != null) return auth; + + if (items.Any(x => x.Uid == null)) return BadRequest("ID not given in body"); + + if (DataProvider.fetch_shipment_pool().GetShipment(id) == null) + return NotFound("No data for given ID"); + + DataProvider.fetch_shipment_pool().UpdateItemsInShipment(id, items); + DataProvider.fetch_shipment_pool().Save(); + return Ok(); + } + + [HttpPut("{id}/commit")] + public IActionResult CommitShipment(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "put"); + if (auth != null) return auth; + + var shipment = DataProvider.fetch_shipment_pool().GetShipment(id); + if (shipment == null) return NotFound("No data found with given ID"); + + foreach (var item in shipment.Items) + { + var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(item.Item_Id); + foreach (var inventory in inventories) + { + if (inventory.Locations.Contains(shipment.Source_Id)) + { + inventory.Total_On_Hand -= item.Amount; + } + } + } + + shipment.Shipment_Status = "Shipped"; + var success = DataProvider.fetch_shipment_pool().UpdateShipment(id, shipment); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + _notificationSystem.Push($"Shipment with id: {shipment.Id} has been processed."); + DataProvider.fetch_shipment_pool().Save(); + DataProvider.fetch_inventory_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteShipment(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "shipments", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_shipment_pool().RemoveShipment(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_shipment_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/SuppliersController.cs b/C#api/Controllers/SuppliersController.cs new file mode 100644 index 0000000..f4b85ca --- /dev/null +++ b/C#api/Controllers/SuppliersController.cs @@ -0,0 +1,89 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class SuppliersController : BaseApiController +{ + public SuppliersController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetSuppliers() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "get"); + if (auth != null) return auth; + + var suppliers = DataProvider.fetch_supplier_pool().GetSuppliers(); + return Ok(suppliers); + } + + [HttpGet("{id}")] + public IActionResult GetSupplier(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "get"); + if (auth != null) return auth; + + var supplier = DataProvider.fetch_supplier_pool().GetSupplier(id); + if (supplier == null) return NotFound(); + + return Ok(supplier); + } + + [HttpGet("{id}/items")] + public IActionResult GetSupplierItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_item_pool().GetItemsForSupplier(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateSupplier([FromBody] Supplier supplier) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "post"); + if (auth != null) return auth; + + if (supplier.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_supplier_pool().AddSupplier(supplier); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_supplier_pool().Save(); + return CreatedAtAction(nameof(GetSupplier), new { id = supplier.Id }, supplier); + } + + [HttpPut("{id}")] + public IActionResult UpdateSupplier(int id, [FromBody] Supplier supplier) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "put"); + if (auth != null) return auth; + + if (supplier.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_supplier_pool().UpdateSupplier(id, supplier); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_supplier_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteSupplier(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "suppliers", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_supplier_pool().RemoveSupplier(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_supplier_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/TransfersController.cs b/C#api/Controllers/TransfersController.cs new file mode 100644 index 0000000..764ea0e --- /dev/null +++ b/C#api/Controllers/TransfersController.cs @@ -0,0 +1,147 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class TransfersController : BaseApiController +{ + public TransfersController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetTransfers() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "get"); + if (auth != null) return auth; + + var transfers = DataProvider.fetch_transfer_pool().GetTransfers(); + return Ok(transfers); + } + + [HttpGet("{id}")] + public IActionResult GetTransfer(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "get"); + if (auth != null) return auth; + + var transfer = DataProvider.fetch_transfer_pool().GetTransfer(id); + if (transfer == null) return NotFound(); + + return Ok(transfer); + } + + [HttpGet("{id}/items")] + public IActionResult GetTransferItems(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "get"); + if (auth != null) return auth; + + var items = DataProvider.fetch_transfer_pool().GetItemsInTransfer(id); + return Ok(items); + } + + [HttpPost] + public IActionResult CreateTransfer([FromBody] Transfer transfer) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "post"); + if (auth != null) return auth; + + if (transfer.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_transfer_pool().AddTransfer(transfer); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_transfer_pool().Save(); + return CreatedAtAction(nameof(GetTransfer), new { id = transfer.Id }, transfer); + } + + [HttpPut("{id}")] + public IActionResult UpdateTransfer(int id, [FromBody] Transfer transfer) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "put"); + if (auth != null) return auth; + + if (transfer.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_transfer_pool().UpdateTransfer(id, transfer); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_transfer_pool().Save(); + return Ok(); + } + + // [HttpPut("{id}/items")] + // public IActionResult UpdateTransferItems(int id, [FromBody] List items) + // { + // var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "put"); + // if (auth != null) return auth; + + // if (items.Any(x => x.Uid == null)) return BadRequest("ID not given in body"); + + // if (DataProvider.fetch_transfer_pool().GetTransfer(id) == null) + // return NotFound("No data for given ID"); + + // DataProvider.fetch_item_pool().UpdateItemsInTransfer(id, items); + // DataProvider.fetch_transfer_pool().Save(); + // return Ok(); + // } + + [HttpPut("{id}/commit")] + public IActionResult CommitTransfer(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "put"); + if (auth != null) return auth; + + var transfer = DataProvider.fetch_transfer_pool().GetTransfer(id); + if (transfer == null) return NotFound("Transfer not found"); + + if (transfer.Id == -10) return BadRequest("Invalid transfer ID"); + + // Update inventories based on transfer items + foreach (var item in transfer.Items) + { + var inventories = DataProvider.fetch_inventory_pool().GetInventoriesForItem(item.Item_Id); + foreach (var inventory in inventories) + { + if (transfer.Transfer_From is null) break; + if (inventory.Locations.Contains((int)transfer.Transfer_From)) + { + inventory.Total_On_Hand -= item.Amount; + } + else if (inventory.Locations.Contains((int)transfer.Transfer_To)) + { + inventory.Total_On_Hand += item.Amount; + } + DataProvider.fetch_inventory_pool().UpdateInventory(inventory.Id, inventory); + } + } + + transfer.Transfer_Status = "Processed"; + var success = DataProvider.fetch_transfer_pool().UpdateTransfer(id, transfer); + if (!success) return NotFound("Failed to update transfer status"); + + _notificationSystem.Push($"Processed batch transfer with id: {transfer.Id}"); + + DataProvider.fetch_transfer_pool().Save(); + DataProvider.fetch_inventory_pool().Save(); + + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteTransfer(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "transfers", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_transfer_pool().RemoveTransfer(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_transfer_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Controllers/WarehousesController.cs b/C#api/Controllers/WarehousesController.cs new file mode 100644 index 0000000..b391378 --- /dev/null +++ b/C#api/Controllers/WarehousesController.cs @@ -0,0 +1,99 @@ +using Microsoft.AspNetCore.Mvc; +using Models; +using Providers; + +[ApiController] +[Route("api/v1/[controller]")] +public class WarehousesController : BaseApiController +{ + public WarehousesController( + NotificationSystem notificationSystem) + : base(notificationSystem) + { + } + + [HttpGet] + public IActionResult GetWarehouses() + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "get"); + if (auth != null) return auth; + + var warehouses = DataProvider.fetch_warehouse_pool().GetWarehouses(); + return Ok(warehouses); + } + + [HttpGet("{id}")] + public IActionResult GetWarehouse(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "get"); + if (auth != null) return auth; + + var warehouse = DataProvider.fetch_warehouse_pool().GetWarehouse(id); + if (warehouse == null) return NotFound(); + + return Ok(warehouse); + } + + [HttpGet("{id}/locations")] + public IActionResult GetWarehouseLocations(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "get"); + if (auth != null) return auth; + + var locations = DataProvider.fetch_location_pool().GetLocationsInWarehouse(id); + return Ok(locations); + } + + // [HttpGet("{id}/inventory")] + // public IActionResult GetWarehouseInventory(int id) + // { + // var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "get"); + // if (auth != null) return auth; + + // var inventory = DataProvider.fetch_inventory_pool().GetInventoryForWarehouse(id); + // return Ok(inventory); + // } + + [HttpPost] + public IActionResult CreateWarehouse([FromBody] Warehouse warehouse) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "post"); + if (auth != null) return auth; + + if (warehouse.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_warehouse_pool().AddWarehouse(warehouse); + if (!success) return NotFound("ID already exists in data"); + + DataProvider.fetch_warehouse_pool().Save(); + return CreatedAtAction(nameof(GetWarehouse), new { id = warehouse.Id }, warehouse); + } + + [HttpPut("{id}")] + public IActionResult UpdateWarehouse(int id, [FromBody] Warehouse warehouse) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "put"); + if (auth != null) return auth; + + if (warehouse.Id == -10) return BadRequest("ID not given in body"); + + var success = DataProvider.fetch_warehouse_pool().UpdateWarehouse(id, warehouse); + if (!success) return NotFound("ID not found or ID in Body and Route are not matching"); + + DataProvider.fetch_warehouse_pool().Save(); + return Ok(); + } + + [HttpDelete("{id}")] + public IActionResult DeleteWarehouse(int id) + { + var auth = CheckAuthorization(Request.Headers["API_KEY"], "warehouses", "delete"); + if (auth != null) return auth; + + var success = DataProvider.fetch_warehouse_pool().RemoveWarehouse(id); + if (!success) return NotFound("ID not found or other data is dependent on this data"); + + DataProvider.fetch_warehouse_pool().Save(); + return Ok(); + } +} \ No newline at end of file diff --git a/C#api/Program.cs b/C#api/Program.cs index 38b22d3..cce60c4 100644 --- a/C#api/Program.cs +++ b/C#api/Program.cs @@ -1,56 +1,42 @@ -using System; -using System.Net; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Providers; -public class Program -{ - private const int PORT = 3000; +var builder = WebApplication.CreateBuilder(args); - public static void Main() +// Add services to the container. +builder.Services.AddControllers() + .AddJsonOptions(options => { - var httpListener = new HttpListener(); - httpListener.Prefixes.Add($"http://127.0.0.1:{PORT}/"); - - AuthProvider.Init(); // Initialize authentication provider - DataProvider.Init(); // Initialize data provider - NotificationSystem n = new NotificationSystem(); - NotificationSystem.Start(); // Start notification processor - - httpListener.Start(); - Console.WriteLine($"Serving on port {PORT}..."); - - Task.Run(async () => - { - while (true) - { - var context = await httpListener.GetContextAsync(); - var handler = new ApiRequestHandler(); - - // Determine the HTTP method and call the appropriate handler - switch (context.Request.HttpMethod) - { - case "GET": - handler.HandleGet(context.Request, context.Response); - break; - case "POST": - handler.HandlePost(context.Request, context.Response); - break; - case "PUT": - handler.HandlePut(context.Request, context.Response); - break; - case "DELETE": - handler.HandleDelete(context.Request, context.Response); - break; - default: - context.Response.StatusCode = (int)HttpStatusCode.MethodNotAllowed; - context.Response.Close(); - break; - } - } - }); - - // Prevent the main thread from exiting - Console.ReadLine(); - httpListener.Stop(); - } + options.JsonSerializerOptions.PropertyNamingPolicy = null; // Disable camelCase + }); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +// Register your services +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); + +var app = builder.Build(); + +// Initialize your providers +AuthProvider.Init(); +DataProvider.Init(); +// NotificationSystem.Start(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); } + +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Urls.Add("http://localhost:3000/"); + +app.Run(); +Console.WriteLine("Hello"); \ No newline at end of file diff --git a/C#api/Tests/test_orders.py b/C#api/Tests/test_orders.py index e8ab4df..bfff3ac 100644 --- a/C#api/Tests/test_orders.py +++ b/C#api/Tests/test_orders.py @@ -91,17 +91,25 @@ def test_6create_duplicate_order(self): # PUT tests def test_7update_existing_order(self): updated_order = { - "Id": self.new_order['Id'], # Keep the same Id - "Reference": "ORD124", # Changed Reference - "Order_Status": "Completed", # Changed Status - "Total_Amount": 1100.00, # Changed Amount - "Total_Tax": 120.00, # Changed Tax + "Id": 0, + "Source_Id": 1, + "Order_Date": "2024-11-14T16:10:14.227318", + "Request_Date": "2024-11-14T16:10:14.227318", + "Reference": "ORD123", + "Reference_Extra": "Extra details here", + "Order_Status": "Completed", + "Notes": "Order notes", + "Shipping_Notes": "Shipping instructions", + "Picking_Notes": "Picking instructions", + "Warehouse_Id": 1, + "Total_Amount": 1000.00, + "Total_Discount": 50.00, + "Total_Tax": 100.00, + "Total_Surcharge": 20.00, "Items": [ - {"Item_Id": "ITEM789", "Amount": 200}, - {"Item_Id": "ITEM101", "Amount": 150} - ], - "Created_At": self.new_order['Created_At'], # Keep the same creation time - "Updated_At": "2024-11-14T16:10:14.227318", # New update time + {"Item_Id": "ITEM123", "Amount": 100}, + {"Item_Id": "ITEM456", "Amount": 50} + ] } response = self.client.put(f"orders/{self.new_order['Id']}", content=json.dumps(updated_order), headers={"Content-Type": "application/json"}) diff --git a/C#api/models/clients.cs b/C#api/models/clients.cs index 64546e3..487ba71 100644 --- a/C#api/models/clients.cs +++ b/C#api/models/clients.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; +using Providers; namespace Models; public class Client @@ -17,8 +18,8 @@ public class Client public string Contact_name { get; set; } public string Contact_phone { get; set; } public string Contact_email { get; set; } - public string Created_at { get; set; } - public string Updated_at { get; set; } + public string? Created_at { get; set; } + public string? Updated_at { get; set; } } public class Clients : Base diff --git a/C#api/models/inventories.cs b/C#api/models/inventories.cs index d7d09cc..539d7c2 100644 --- a/C#api/models/inventories.cs +++ b/C#api/models/inventories.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text.Json; using Newtonsoft.Json; +using Providers; namespace Models; public class Inventory @@ -17,8 +18,8 @@ public class Inventory public int Total_Ordered { get; set; } public int Total_Allocated { get; set; } public int Total_Available { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class Inventories : Base diff --git a/C#api/models/item_groups.cs b/C#api/models/item_groups.cs index 8e01fb0..d5de309 100644 --- a/C#api/models/item_groups.cs +++ b/C#api/models/item_groups.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text.Json; using Newtonsoft.Json; +using Providers; namespace Models; public class ItemGroup @@ -10,8 +11,8 @@ public class ItemGroup public int Id { get; set; } = -10; public string Name { get; set; } public string Description { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class ItemGroups : Base diff --git a/C#api/models/item_lines.cs b/C#api/models/item_lines.cs index f3d8925..48fdae2 100644 --- a/C#api/models/item_lines.cs +++ b/C#api/models/item_lines.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text.Json; using Newtonsoft.Json; +using Providers; namespace Models; @@ -11,8 +12,8 @@ public class ItemLine public int Id { get; set; } = -10; public string Name { get; set; } public string Description { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class ItemLines : Base diff --git a/C#api/models/item_types.cs b/C#api/models/item_types.cs index daa985c..df04564 100644 --- a/C#api/models/item_types.cs +++ b/C#api/models/item_types.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text.Json; using Newtonsoft.Json; +using Providers; namespace Models; public class ItemType @@ -10,8 +11,8 @@ public class ItemType public int Id { get; set; } = -10; public string Name { get; set; } public string Description { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } diff --git a/C#api/models/items.cs b/C#api/models/items.cs index 8d3adc2..d814a28 100644 --- a/C#api/models/items.cs +++ b/C#api/models/items.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; +using Providers; namespace Models; @@ -24,8 +25,8 @@ public class Item public int Supplier_Id { get; set; } public string Supplier_Code { get; set; } public string Supplier_Part_Number { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class Items : Base diff --git a/C#api/models/locations.cs b/C#api/models/locations.cs index 7b69464..0bc951f 100644 --- a/C#api/models/locations.cs +++ b/C#api/models/locations.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; +using Providers; namespace Models; public class Location @@ -11,8 +12,8 @@ public class Location public int Warehouse_Id { get; set; } public string Code { get; set; } public string Name { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class Locations : Base diff --git a/C#api/models/orders.cs b/C#api/models/orders.cs index 3157b7c..e34d93e 100644 --- a/C#api/models/orders.cs +++ b/C#api/models/orders.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; +using Providers; namespace Models; public class OrderItem @@ -31,8 +32,8 @@ public class Order public decimal Total_Discount { get; set; } public decimal Total_Tax { get; set; } public decimal Total_Surcharge { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } public List Items { get; set; } } diff --git a/C#api/models/shipments.cs b/C#api/models/shipments.cs index 2ce5c20..5301adb 100644 --- a/C#api/models/shipments.cs +++ b/C#api/models/shipments.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; namespace Models; +using Providers; using Newtonsoft.Json; public class ShipmentItem @@ -28,8 +29,8 @@ public class Shipment public string Transfer_Mode { get; set; } public int Total_Package_Count { get; set; } public double Total_Package_Weight { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } public List Items { get; set; } } diff --git a/C#api/models/suppliers.cs b/C#api/models/suppliers.cs index 6c8c4f2..87f293e 100644 --- a/C#api/models/suppliers.cs +++ b/C#api/models/suppliers.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; namespace Models; +using Providers; using Newtonsoft.Json; public class Supplier @@ -19,8 +20,8 @@ public class Supplier public string Contact_Name { get; set; } public string Phonenumber { get; set; } public string Reference { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } public class Suppliers : Base diff --git a/C#api/models/transfers.cs b/C#api/models/transfers.cs index 597d203..b9beee1 100644 --- a/C#api/models/transfers.cs +++ b/C#api/models/transfers.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; namespace Models; +using Providers; using Newtonsoft.Json; public class TransferItem @@ -17,8 +18,8 @@ public class Transfer public int? Transfer_From { get; set; } public int? Transfer_To { get; set; } public string Transfer_Status { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } public List Items { get; set; } } diff --git a/C#api/models/warehouses.cs b/C#api/models/warehouses.cs index 4410e2b..31c3e27 100644 --- a/C#api/models/warehouses.cs +++ b/C#api/models/warehouses.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; namespace Models; +using Providers; using Newtonsoft.Json; // Ensure you have Newtonsoft.Json package installed public class ContactInfo @@ -22,8 +23,8 @@ public class Warehouse public string Province { get; set; } public string Country { get; set; } public ContactInfo Contact { get; set; } - public string Created_At { get; set; } - public string Updated_At { get; set; } + public string? Created_At { get; set; } + public string? Updated_At { get; set; } } diff --git a/C#api/providers/auth_provider.cs b/C#api/providers/auth_provider.cs index 3823b31..2edf308 100644 --- a/C#api/providers/auth_provider.cs +++ b/C#api/providers/auth_provider.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +namespace Providers; public class AuthProvider { diff --git a/C#api/providers/data_provider.cs b/C#api/providers/data_provider.cs index a47d050..ca3b679 100644 --- a/C#api/providers/data_provider.cs +++ b/C#api/providers/data_provider.cs @@ -1,6 +1,7 @@ using System; using Models; using System.IO; +namespace Providers; class DataProvider { diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..f518c8c --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:19115", + "sslPort": 44311 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5231", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7013;http://localhost:5231", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Software-Construction.csproj b/Software-Construction.csproj index aeea7e9..bb979ef 100644 --- a/Software-Construction.csproj +++ b/Software-Construction.csproj @@ -1,16 +1,16 @@ - + - Exe net8.0 - Software_Construction - enable enable + enable + Software_Construction + - + diff --git a/Software-Construction.http b/Software-Construction.http new file mode 100644 index 0000000..d5d9447 --- /dev/null +++ b/Software-Construction.http @@ -0,0 +1,6 @@ +@Software_Construction_HostAddress = http://localhost:5231 + +GET {{Software_Construction_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}