From a4fab6550c2681010f0beda317a01bc9de45b905 Mon Sep 17 00:00:00 2001 From: ecyr20 Date: Tue, 9 Apr 2024 10:29:41 -0500 Subject: [PATCH] Removed extraneous parts in OpenAtmos JSON Made the reactants and products in the reaction part of the JSON only show up if there are any. --- Services/OpenAtmosService.cs | 40 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/Services/OpenAtmosService.cs b/Services/OpenAtmosService.cs index 9acc29e..222e4c6 100644 --- a/Services/OpenAtmosService.cs +++ b/Services/OpenAtmosService.cs @@ -116,26 +116,40 @@ public async Task Get(Guid tag_mechanism_uuid) JSON += ", \n"; } var reactants = reactantProductListService.GetReactantsAsync(reaction.reactant_list_uuid).Result; - JSON += " \"reactants\": [ \n" + - " {\n"; - foreach (ReactantsProducts reactant in reactants) + if(reactants.Count != 0) { - JSON += " \"species name\": \"" + reactant.type + "\", \n"; - JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n"; + JSON += " \"reactants\": [ \n" + + " {\n"; + foreach (ReactantsProducts reactant in reactants) + { + JSON += " \"species name\": \"" + reactant.type + "\", \n"; + JSON += " \"coefficient\": \"" + reactant.quantity + "\" \n"; + } + JSON += " }\n" + + " ], \n"; } - JSON += " }\n" + - " ], \n"; var products = reactantProductListService.GetProductsAsync(reaction.product_list_uuid).Result; - JSON += " \"products\": [ \n" + + + if(products.Count != 0) + { + JSON += " \"products\": [ \n" + " {\n"; - foreach (ReactantsProducts product in products) + foreach (ReactantsProducts product in products) + { + JSON += " \"species name\": \"" + product.type + "\", \n"; + JSON += " \"coefficient\": \"" + product.quantity + "\" \n"; + } + JSON += " }\n" + + " ]\n"; + } + + if(reactants.Count == 0 && products.Count == 0) { - JSON += " \"species name\": \"" + product.type + "\", \n"; - JSON += " \"coefficient\": \"" + product.quantity + "\" \n"; + JSON = JSON.Remove(JSON.LastIndexOf(',')); + JSON += "\n"; } - JSON += " }\n" + - " ]\n"; + JSON += " },\n"; } JSON = JSON.Remove(JSON.LastIndexOf(','));