ctucx.git: oeffisearch

[nimlang] fast and simple tripplanner

commit a03e08b99bca66ddc7adfe3884da5a2907f9f0fd
parent cb2fcc16dda85fcfc044501ef35bcf8ebdc41bf9
Author: Leah Thein <leah@toaster.fritz.box>
Date: Fri, 4 Dec 2020 22:08:31 +0100

fix compiler-warnings
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/cache.nim b/src/cache.nim
@@ -5,12 +5,12 @@ randomize()
 
 
 proc cacheExists* (id: string ): bool =
-  return existsFile(getEnv("CACHE_PATH") & "/" & $id & ".json")
+  return fileExists(getEnv("CACHE_PATH") & "/" & $id & ".json")
 
 proc getFreeId (): 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 getCacheObject* (reqId: string): CacheObject = 

@@ -25,7 +25,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,

@@ -51,13 +51,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:

@@ -74,7 +74,7 @@ proc updateJourney* (reqId: string, journeyId: string, journey: Journey): Future
   var cacheObj    = getCacheObject(reqId)
 
   cacheObj.lastUpdated = getTime().toUnix()
-  cacheObj.journeys.add(journeyId, journey) 
+  cacheObj.journeys[journeyId] = journey
 
   var file = openAsync(getEnv("CACHE_PATH") & "/" & $reqId & ".json", fmReadWrite)
   await file.write($(%* cacheObj))
diff --git a/src/endpoints/journeys.nim b/src/endpoints/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/fileserver.nim b/src/fileserver.nim
@@ -29,9 +29,9 @@ proc servePath*(req: Request): NimHttpResponse =
   let path = "client" & req.url.path.decodeUrl()
   #if path.existsDir:
   #  return sendDirContents(path)
-  if path.existsFile:
+  if path.fileExists:
     return sendStaticFile(path)
-  if existsFile(path & "index.html"):
+  if fileExists(path & "index.html"):
     return sendStaticFile(path & "index.html")
   else:
     raise newException(notFoundException, "NOT_FOUND")
diff --git a/src/oeffisearch.nim b/src/oeffisearch.nim
@@ -41,10 +41,10 @@ proc handleRequest(req: Request) {.async,gcsafe.} =
 proc main() =
   endpoints = initTable[string, proc(data: JsonNode): Future[JsonNode] {.gcsafe.}]()
 
-  endpoints.add($HttpGet & "/suggestions",    suggestionsEndpoint)
-  endpoints.add($HttpGet & "/journeys",       journeysEndpoint)
-  endpoints.add($HttpGet & "/moreJourneys",   moreJourneysEndpoint)
-  endpoints.add($HttpGet & "/refreshJourney", refreshJourneyEndpoint)
+  endpoints[$HttpGet & "/suggestions"]    = suggestionsEndpoint
+  endpoints[$HttpGet & "/journeys"]       = journeysEndpoint
+  endpoints[$HttpGet & "/moreJourneys"]   = moreJourneysEndpoint
+  endpoints[$HttpGet & "/refreshJourney"] = refreshJourneyEndpoint
 
   if getEnv("CACHE_PATH") == "":
     echo "CACHE_PATH not set! Bye...."