ctucx.git: oeffi-web

[nimlang] oeffisearch fork that works without javascript

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
import json, options, strutils
import nimhafas
import ../asyncWebServer
import ../types
import ../formaters/formaters

proc suggestionsHandler* (request: Request, server: ServerRef) {.async.} = 
  let requestParams = parseQuery(request.url.query)
  var results       = 10
  var suggestions:    seq[string]

  if requestParams.hasKey("results"):
    results = parseInt(requestParams["results"])

  if requestParams.hasKey("query"):
    let points = (await suggestions(SuggestionsParams(
        query: requestParams["query"],
        results: some(results)
      )))

    for point in points:
      suggestions.add(formatPoint(point))

  var json = %* {"suggestions": suggestions}
  await request.respondJson(Http200, "success", "", json["suggestions"])