diff options
-rw-r--r-- | mywatch.cabal | 1 | ||||
-rw-r--r-- | src/Application.hs | 17 | ||||
-rw-r--r-- | src/Application/Types/Process.hs | 23 |
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) |