Skip to content

Commit

Permalink
Permitting any single word animal value. (supporting Bird value) (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrechka authored Jan 26, 2023
1 parent bc50cd9 commit 4d821b3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions CardIndexRestAPI/Controllers/SolrProxyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,14 @@ public async Task MatchedImagesSearch([FromBody] GetMatchesRequest request)
_ => throw new ArgumentException($"Unknown EventType: {request.EventType}")
};

string animalFilterTerm = request.Animal switch
// validation animal
var match = Regex.Match(request.Animal, @"^[A-Za-z]+$", RegexOptions.None);
if (!match.Success)
{
"Cat" => "animal:Cat",
"Dog" => "animal:Dog",
_ => throw new ArgumentException($"Unknown Animal: {request.Animal}")
};
throw new FormatException($"Animal field must contain A-Za-z characters only");
}

string animalFilterTerm = $"animal:{request.Animal}";

string cardTypeAndAnimalFilter = $"{typeFilterTerm} AND {animalFilterTerm}";

Expand Down Expand Up @@ -313,7 +315,7 @@ public async Task LatestCards([FromQuery]int maxCardsCount=10, [FromQuery] strin
public async Task RecentCrawledStats([FromRoute] string cardsNamespace, [FromQuery] RecentStatsMode mode = RecentStatsMode.Days)
{
// checking input
var match = Regex.Match(cardsNamespace, @"^[0-9A-Za-z\-]+$", RegexOptions.IgnoreCase);
var match = Regex.Match(cardsNamespace, @"^[0-9A-Za-z\-]+$", RegexOptions.None);
if (!match.Success)
{
throw new FormatException($"cardsNamespace must contain 0-9A-Za-z or '-' characters only");
Expand All @@ -332,9 +334,8 @@ public async Task RecentCrawledStats([FromRoute] string cardsNamespace, [FromQue
_ => throw new NotSupportedException()
};

var safeCardsNamespace = cardsNamespace.Replace(Environment.NewLine, "");

Trace.TraceInformation($"Fetching statistics for ns \"{safeCardsNamespace}\" over recent {mode}(s)");
var modeStr = mode.ToString();
Trace.TraceInformation($"Fetching statistics for ns \"{cardsNamespace}\" over recent {modeStr}(s)");

Dictionary<string, string> requestParams = new Dictionary<string, string>();
requestParams.Add("q", "*:*");
Expand Down

0 comments on commit 4d821b3

Please sign in to comment.