* getMonthCount now takes a BlogLang, as is obviously required

This commit is contained in:
Vincent Ambo 2012-03-03 03:47:11 +01:00
parent 9e4b35613c
commit 65a5443e2d

View file

@ -105,9 +105,9 @@ stripResult :: Result a -> a
stripResult (Ok z) = z stripResult (Ok z) = z
stripResult (Error s) = error $ "JSON error: " ++ s stripResult (Error s) = error $ "JSON error: " ++ s
getMonthCount :: Int -> Int -> ServerPart Int getMonthCount :: BlogLang -> Int -> Int -> ServerPart Int
getMonthCount y m = do getMonthCount lang y m = do
count <- queryDB "countDE" $ makeQuery startkey endkey count <- queryDB (view lang) $ makeQuery startkey endkey
return . stripCount $ map (stripResult . fromJSON . snd) count return . stripCount $ map (stripResult . fromJSON . snd) count
where where
startkey = JSArray [toJSON ("count" :: String), toJSON y, toJSON m] startkey = JSArray [toJSON ("count" :: String), toJSON y, toJSON m]
@ -115,13 +115,15 @@ getMonthCount y m = do
stripCount :: [Int] -> Int stripCount :: [Int] -> Int
stripCount [x] = x stripCount [x] = x
stripCount [] = 0 stripCount [] = 0
view DE = "countDE"
view EN = "countEN"
-- CouchDB View Setup -- CouchDB View Setup
latestDEView = "function(doc){ if(doc.lang == 'DE'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }" latestDEView = "function(doc){ if(doc.lang == 'DE'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }"
latestENView = "function(doc){ if(doc.lang == 'EN'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }" latestENView = "function(doc){ if(doc.lang == 'EN'){ emit([doc.year, doc.month, doc.day, doc._id], doc); } }"
countDEView = "function(doc){ if(doc.lang == 'DE'){ emit([doc.year, doc.month, doc.day, doc._id], 1); } }" countDEView = "function(doc){ if(doc.lang == 'DE'){ emit(['count', doc.year, doc.month, doc.day, doc._id], 1); } }"
countENView = "function(doc){ if(doc.lang == 'EN'){ emit([doc.year, doc.month, doc.day, doc._id], 1); } }" countENView = "function(doc){ if(doc.lang == 'EN'){ emit(['count', doc.year, doc.month, doc.day, doc._id], 1); } }"
countReduce = "function(keys, values, rereduce) { return sum(values); }" countReduce = "function(keys, values, rereduce) { return sum(values); }"
latestDE = ViewMap "latestDE" latestDEView latestDE = ViewMap "latestDE" latestDEView