ctucx.git: oeffi-web

[nimlang] oeffisearch fork that works without javascript

commit b2602958b81c3301c22983be76ff1dd06faf64b3
parent 353a0576f48f8a6089e526d3ad891256b6f4fe72
Author: Leah Thein <leah@toaster.fritz.box>
Date: Fri, 4 Dec 2020 17:41:32 +0100

fix compiler errors
7 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/asyncWebServer.nim b/src/asyncWebServer.nim
@@ -1,6 +1,6 @@
 import asyncdispatch, asynchttpserver, macros
 import strutils, parseutils
-import cookies, uri, times, os, re, json
+import cookies, uri, times, re, json
 import tables
 
 export asyncdispatch, asynchttpserver, cookies, uri

@@ -46,7 +46,7 @@ proc parseQuery*(data: string): Table[string, string] =
   for i in data:
     let timed = i.split("=")
     if timed.len > 1:
-      result.add(decodeUrl(timed[0]), decodeUrl(timed[1]))
+      result[decodeUrl(timed[0])] = decodeUrl(timed[1])
 
 proc daysForward*(days: int): DateTime =
   return getTime().utc + initTimeInterval(days = days)
diff --git a/src/cache.nim b/src/cache.nim
@@ -27,11 +27,11 @@ proc fromAlphaId (s: string): int =
 proc getFreeAlphaId (): string =
   result = toAlphaId(int32(rand(high(int32))))
 
-  while existsFile(getEnv("CACHE_PATH") & "/" & $result & ".json"):
+  while fileExists(getEnv("CACHE_PATH") & "/" & $result & ".json"):
     result = toAlphaId(int32(rand(high(int32))))
 
 proc cacheExists* (id: string ): bool =
-  return existsFile(getEnv("CACHE_PATH") & "/" & $id & ".json")
+  return fileExists(getEnv("CACHE_PATH") & "/" & $id & ".json")
 
 proc getCacheObject* (reqId: string): CacheObject = 
   if not cacheExists(reqId): raise newException(notFoundException, "REQUEST_NOT_FOUND")

@@ -45,7 +45,7 @@ proc saveJourneys* (params: JourneysParams, journeysResponse: JourneysResponse):
 
   for journey in journeysResponse.journeys:
     inc(maxId)
-    journeys.add($maxId, journey)
+    journeys[$maxId] = journey
 
   var cacheObj = CacheObject(
       version:     1,

@@ -71,13 +71,13 @@ proc updateJourneys* (reqId: string, mode: moreJourneysMode, journeysResponse: J
     cacheObj.minId -= journeysResponse.journeys.len
     var cnt = cacheObj.minId
     for journey in journeysResponse.journeys:
-      cacheObj.journeys.add($cnt, journey)
+      cacheObj.journeys[$cnt] = journey
       inc(cnt)
 
   else:
     for journey in journeysResponse.journeys:
       inc(cacheObj.maxId)
-      cacheObj.journeys.add($cacheObj.maxId, journey)
+      cacheObj.journeys[$cacheObj.maxId] = journey
 
   cacheObj.lastUpdated = getTime().toUnix()
   if mode != later:
diff --git a/src/endpoints/api/journeys.nim b/src/endpoints/api/journeys.nim
@@ -1,4 +1,4 @@
-import json, tables, options, asyncdispatch, sequtils
+import json, tables, options, asyncdispatch
 import ../../types, ../../backend/hafas, ../../cache
 
 when not defined(release):
diff --git a/src/endpoints/journeyHandler.nim b/src/endpoints/journeyHandler.nim
@@ -1,7 +1,7 @@
-import json, times, options, strutils, tables
+import json, options, strutils, tables
 import ../asyncWebServer
 import ../utils, ../translations, ../types, ../cache_types, ../cache, ../backend/hafas
-import ../formaters/formaters, ../formaters/renderJourney
+import ../formaters/renderJourney
 
 proc journeyHandler* (request: Request, server: ServerRef) {.async.} =
   let urlParts      = request.url.path.split("/")
diff --git a/src/endpoints/journeysHandler.nim b/src/endpoints/journeysHandler.nim
@@ -1,7 +1,7 @@
-import json, times, asyncdispatch, options, strutils
+import json, asyncdispatch, options, strutils
 import ../asyncWebServer
 import ../utils, ../translations, ../types, ../cache_types, ../cache, ../backend/hafas
-import ../formaters/formaters, ../formaters/renderJourneys
+import ../formaters/renderJourneys
 
 proc journeysHandler* (request: Request, server: ServerRef) {.async.} = 
   let urlParts      = request.url.path.split("/")
diff --git a/src/oeffi.nim b/src/oeffi.nim
@@ -1,5 +1,5 @@
 import os, json, times, options, strutils, asyncdispatch, re
-import jester, moustachu
+import moustachu
 import types, backend/hafas, cache, cache_types
 import endpoints/[suggestions, journeys, moreJourneys, refreshJourney]
 import utils, translations, formaters/[formaters, renderJourneys, renderJourney, formatFullResponse]

@@ -214,4 +214,4 @@ routes:
       if not requestParams.hasKey("json"):
         respError(Http404, "Nichts gefunden!", "Für diese Anfrage gibts nix.")
       else:
-        respApi(Http404, "error", getCurrentExceptionMsg().split("\n")[0], "")-
\ No newline at end of file
+        respApi(Http404, "error", getCurrentExceptionMsg().split("\n")[0], "")
diff --git a/src/types.nim b/src/types.nim
@@ -88,6 +88,8 @@ type
     fullProductName*:   string
     operator*:          Option[Operator]
     additionalName*:    Option[string]
+    trainType*:         Option[string]
+    trainTypeShort*:    Option[string]
 
   Operator* = object
     id*:   string

@@ -99,9 +101,8 @@ type
     nr*:  Option[int]
 
   Price* = object
-    amount*:   Option[float]
+    amount*:   float
     currency*: Option[string]
-    hint*:     Option[string]
 
   StopoverPart* = object
     plannedTime*:          Option[int64]

@@ -178,13 +179,13 @@ type
     coordinates*:  seq[float]
 
 
-  notFoundException* = object of Exception
-  errorException*    = object of Exception
+  notFoundException* = object of CatchableError
+  errorException*    = object of CatchableError
 
   hafasExceptionKind* = enum
     SERVER_ERROR, ACCESS_DENIED, INVALID_REQUEST, NOT_FOUND
 
-  hafasException*    = ref object of Exception
+  hafasException*    = ref object of CatchableError
     code*: hafasExceptionKind
     message*: string
     statusCode*: HttpCode