Skip to content

Commit 5661b8a

Browse files
committed
Fix case of QB responses keys
1 parent 1eefa1d commit 5661b8a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

NorthwindCRUD/Controllers/QueryBuilderController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace QueryBuilder;
22

33
using System.Diagnostics.CodeAnalysis;
44
using System.Globalization;
5+
using System.Reflection;
56
using AutoMapper;
67
using Microsoft.AspNetCore.Mvc;
78
using Newtonsoft.Json;
@@ -49,11 +50,16 @@ public ActionResult<QueryBuilderResult> ExecuteQuery(Query query)
4950
{
5051
var sanitizedEntity = query.Entity.Replace("\r", string.Empty).Replace("\n", string.Empty);
5152
logger.LogInformation("Executing query for entity: {Entity}", sanitizedEntity);
52-
var t = query.Entity.ToLower(CultureInfo.InvariantCulture);
53+
54+
var lookupFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase;
55+
var key = typeof(QueryBuilderResult).GetProperty(sanitizedEntity, lookupFlags)?.Name
56+
?? throw new InvalidOperationException($"Unknown entity {sanitizedEntity}");
57+
var t = key.ToLower(CultureInfo.InvariantCulture);
58+
5359
return Ok(new Dictionary<string, object[]?>
5460
{
5561
{
56-
t,
62+
ToCamelCase(key),
5763
t switch
5864
{
5965
"addresses" => dataContext.Addresses.Run<AddressDb, AddressDto>(query, mapper),
@@ -72,4 +78,6 @@ public ActionResult<QueryBuilderResult> ExecuteQuery(Query query)
7278
},
7379
});
7480
}
81+
82+
private static string ToCamelCase(string s) => char.ToLowerInvariant(s[0]) + s[1..];
7583
}

0 commit comments

Comments
 (0)