aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-10-11 22:04:30 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-10-11 22:04:30 +0300
commitabac581cf16425b4643e4f5196e5b8fd7d903cff (patch)
tree6d076a434ab76c4c48d36ebd9f55a95487fbb46a
parent65b71a99fdb60ad063cb7e8976143027b1e260e7 (diff)
downloadmywatch-abac581cf16425b4643e4f5196e5b8fd7d903cff.tar.gz
Use TH for Process
Factor it out.
-rw-r--r--mywatch.cabal1
-rw-r--r--src/Application.hs17
-rw-r--r--src/Application/Types/Process.hs23
3 files changed, 25 insertions, 16 deletions
diff --git a/mywatch.cabal b/mywatch.cabal
index 8b1cc5f..cc525d8 100644
--- a/mywatch.cabal
+++ b/mywatch.cabal
@@ -35,6 +35,7 @@ executable mywatch
main-is: Main.hs
other-modules:
Application
+ Application.Types.Process
LogFormat
Server
build-depends:
diff --git a/src/Application.hs b/src/Application.hs
index 5624aec..b19d116 100644
--- a/src/Application.hs
+++ b/src/Application.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
@@ -11,7 +10,6 @@ module Application
import Prelude hiding (id)
import Control.Monad.Trans (liftIO)
-import Data.Aeson (ToJSON)
import Data.Default.Class (def)
import qualified Data.HashMap.Lazy as HM
import Data.List (sort)
@@ -19,7 +17,6 @@ import Data.Pool (Pool, withResource)
import Data.Text.Lazy (Text)
import Database.MySQL.Simple
(Connection, Only(..), execute, query_)
-import GHC.Generics (Generic)
import Network.HTTP.Types
(StdMethod(HEAD), notFound404, notImplemented501, ok200)
import Network.Wai (Application, Middleware)
@@ -35,6 +32,7 @@ import Web.Scotty
(ActionM, ScottyM, addroute, delete, file, get, json, middleware,
param, scottyApp, status, text)
+import Application.Types.Process (Process(..))
import LogFormat (logFormat)
type Pools = HM.HashMap Text (Pool Connection)
@@ -59,19 +57,6 @@ myProcess ps logger dataDir = do
addroute HEAD "/server/:server/processlist.json" $ apiCanProcessList ps
delete "/server/:server/process/:id" $ apiKill ps
-data Process = Process
- { id :: Int
- , user :: Text
- , host :: Text
- , db :: Maybe Text
- , command :: Text
- , time :: Int
- , state :: Maybe Text
- , info :: Text
- } deriving (Generic)
-
-instance ToJSON Process
-
apiCanProcessList :: Pools -> ActionM ()
apiCanProcessList ps = do
server <- param "server"
diff --git a/src/Application/Types/Process.hs b/src/Application/Types/Process.hs
new file mode 100644
index 0000000..2156241
--- /dev/null
+++ b/src/Application/Types/Process.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+module Application.Types.Process
+ ( Process(..)
+ ) where
+
+import Prelude hiding (id)
+
+import Data.Aeson.TH (defaultOptions, deriveToJSON)
+import Data.Text.Lazy (Text)
+
+data Process = Process
+ { id :: Int
+ , user :: Text
+ , host :: Text
+ , db :: Maybe Text
+ , command :: Text
+ , time :: Int
+ , state :: Maybe Text
+ , info :: Text
+ }
+
+$(deriveToJSON defaultOptions ''Process)