Advertisement
Guest User

Untitled

a guest
May 16th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings, FlexibleContexts, TypeFamilies, QuasiQuotes, TemplateHaskell, DeriveGeneric #-}
  2. module Main where
  3. {-| Semester 2 assignment for CI285, University of Brighton
  4. Jim Burton <j.burton@brighton.ac.uk>
  5. -}
  6. import System.Log.Logger ( updateGlobalLogger
  7. , rootLoggerName
  8. , setLevel
  9. , debugM
  10. , Priority(..)
  11. )
  12. import Control.Monad (msum)
  13. import Happstack.Server
  14. import Database.SQLite.Simple
  15.  
  16. import WeatherService.Service
  17.  
  18. {-| Entry point. Connects to the database and passes the connection to the
  19. routing function. -}
  20. main :: IO()
  21. main = do
  22. updateGlobalLogger rootLoggerName (setLevel INFO) -- change level to DEBUG for testing
  23. conn <- open "data/np-weather.db"
  24. simpleHTTP nullConf $ do
  25. setHeaderM "Content-Type" "application/json"
  26. msum [
  27. dirs "weather/date" $ do method [GET, POST]
  28. path $ \d -> dayHandler d conn
  29. , dirs "weather/date" $ do method PUT
  30. path $ \d -> path $ \t -> dayPutHandler d t conn
  31. , dirs "weather/range" $ do method GET
  32. path $ \d -> path $ \t -> checkBetween d t conn
  33. , dirs "weather/above" $ do method GET
  34. path $ \d -> path $ \t -> maxReading d t conn
  35. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement