-
Notifications
You must be signed in to change notification settings - Fork 1
begin adding v2 api #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
begin adding v2 api #1
Conversation
| var end_datetime = end_date.ToDateTime(TimeOnly.MaxValue); | ||
| var feedbacks = (from feedback in _context.Feedbacks | ||
| join round in _context.Rounds on feedback.RoundId equals round.Id | ||
| orderby round.Id | ||
| where feedback.KeyName == key_name | ||
| && round.ShutdownDatetime != null | ||
| && round.InitializeDatetime >= start_datetime | ||
| && round.InitializeDatetime <= end_datetime | ||
| // feedback.JSON begins with `{"data": ...` so we strip the first curly brace | ||
| // in order to interpolate the rest of the JSON data into the resultant string | ||
| select $"{{\"round_id\": {round.Id}, {feedback.Json.Substring(1)}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this manages to resolve to a single query, including the substring manip, which is pretty cool:
SELECT `r`.`id`,
SUBSTRING(`f`.`json`, 1 + 1, CHAR_LENGTH(`f`.`json`))
FROM `feedback` AS `f`
INNER JOIN `round` AS `r`
ON `f`.`round_id` = `r`.`id`
WHERE (((`f`.`key_name` = @__key_name_0)
AND `r`.`shutdown_datetime` IS NOT NULL)
AND (`r`.`initialize_datetime` >= @__start_datetime_1))
AND (`r`.`initialize_datetime` <= @__end_datetime_2)
ORDER BY `r`.`id`| { | ||
| Content = "[" + string.Join(", ", feedbacks) + "]", | ||
| ContentType = "application/json", | ||
| StatusCode = 200 | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate that we are manually constructing JSON but this PR has been up long enough.
This PR creates a v2 API namespace for Parastats, and adds its first method.
Besides any new API endpoints not present on v1, the v2 namespace is differentiated because it returns JSON-formatted results of feedback data, rather than a stringified JSON value.
/v2/stats/feedback:key_name, and two dates,start_dateandend_date, which must consist of a span of two months max.key_name.This makes it painless to quickly perform queries on individual feedback keys and helps to lessen the need for mirroring feedback data locally:
The LINQ query resolves nicely into a single SQL query which runs quickly. Concatenating the strings together the way we're doing here is a tiny bit slower, but not egregiously so for queries limited to two months max.