@@ -73,64 +73,30 @@ public async Task<ActionResult<ApiResponseDto>> GetSolutionWithEvidenceAsync([Fr
7373 }
7474
7575 [ HttpPost ( "solvers/project/{projectId:guid}/policy_table" ) ]
76- public async Task < ActionResult < List < PolicyTableDecisionOutgoingDto > > > GetPolicyTableAsync ( [ FromRoute ] Guid projectId , [ FromBody ] EvidenceRequestDto ? evidence = null , CancellationToken ct = default )
76+ public async Task < ActionResult < List < PolicyTableOutgoingDto > > > GetPolicyTableAsync ( [ FromRoute ] Guid projectId , [ FromBody ] EvidenceRequestDto ? evidence = null , CancellationToken ct = default )
7777 {
7878 UserOutgoingDto user = HttpContext . GetLoadedUser ( ) ;
7979 var fastApiResponse = await _fastApiService . SendInfluenceDiagramPolicyTableToFastApiAsync ( projectId , $ "/solvers/project/{ projectId } /policy_table", evidence , user , ct ) ;
8080 if ( fastApiResponse . StatusCode == HttpStatusCode . OK )
8181 {
82- if ( string . IsNullOrEmpty ( fastApiResponse . Content ) )
82+ Dictionary < string , List < PolicyTableStatesOutgoingDto > > response = [ ] ;
83+ if ( ! string . IsNullOrWhiteSpace ( fastApiResponse . Content ) )
8384 {
84- return Ok ( new List < PolicyTableDecisionOutgoingDto > ( ) ) ;
85- }
86-
87- var response = JsonSerializer . Deserialize < Dictionary < string , List < Dictionary < string , JsonElement > > > > (
88- fastApiResponse . Content ,
89- new JsonSerializerOptions
90- {
91- PropertyNameCaseInsensitive = true
92- }
93- ) ;
94-
95- if ( response is null )
96- {
97- return Ok ( new List < PolicyTableDecisionOutgoingDto > ( ) ) ;
85+ response = JsonSerializer . Deserialize < Dictionary < string , List < PolicyTableStatesOutgoingDto > > > (
86+ fastApiResponse . Content
87+ ) ?? [ ] ;
9888 }
9989
10090 var result = response
101- . Select ( kvp => new PolicyTableDecisionOutgoingDto
91+ . Select ( kvp => new PolicyTableOutgoingDto
10292 {
10393 DecisionId = kvp . Key ,
104- Rows = kvp . Value . Select ( row =>
105- {
106- var states = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
107- double value = 0 ;
108-
109- foreach ( var entry in row )
110- {
111- if ( string . Equals ( entry . Key , "value" , StringComparison . OrdinalIgnoreCase ) )
112- {
113- value = entry . Value . ValueKind == JsonValueKind . Number
114- ? entry . Value . GetDouble ( )
115- : double . Parse ( entry . Value . ToString ( ) ) ;
116- continue ;
117- }
118-
119- states [ entry . Key ] = entry . Value . ToString ( ) ;
120- }
121-
122- return new PolicyTableRowOutgoingDto
123- {
124- States = states ,
125- Value = value
126- } ;
127- } ) . ToList ( )
94+ Rows = kvp . Value
12895 } )
12996 . ToList ( ) ;
13097
13198 return Ok ( result ) ;
13299 }
133-
134100 return StatusCode ( ( int ) fastApiResponse . StatusCode , fastApiResponse . Content ) ;
135101 }
136102}
0 commit comments