diff options
-rw-r--r-- | server/src/Thermoprint/Server/Database.hs | 5 | ||||
-rw-r--r-- | server/src/Thermoprint/Server/Database/Instances.hs | 33 | ||||
-rw-r--r-- | server/src/Thermoprint/Server/Printer.hs | 29 | ||||
-rw-r--r-- | server/thermoprint-server.cabal | 6 | ||||
-rw-r--r-- | server/thermoprint-server.nix | 14 |
5 files changed, 78 insertions, 9 deletions
diff --git a/server/src/Thermoprint/Server/Database.hs b/server/src/Thermoprint/Server/Database.hs index 61179e6..65bfc37 100644 --- a/server/src/Thermoprint/Server/Database.hs +++ b/server/src/Thermoprint/Server/Database.hs | |||
@@ -11,13 +11,16 @@ module Thermoprint.Server.Database | |||
11 | , migrateAll | 11 | , migrateAll |
12 | ) where | 12 | ) where |
13 | 13 | ||
14 | import Thermoprint.API (Printout, DraftTitle) | 14 | import Thermoprint.API (Printout, DraftTitle, JobStatus) |
15 | 15 | ||
16 | import Database.Persist.TH | 16 | import Database.Persist.TH |
17 | 17 | ||
18 | import Thermoprint.Server.Database.Instances | ||
19 | |||
18 | share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| | 20 | share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| |
19 | Job | 21 | Job |
20 | content Printout | 22 | content Printout |
23 | status JobStatus | ||
21 | Draft | 24 | Draft |
22 | title DraftTitle Maybe | 25 | title DraftTitle Maybe |
23 | content Printout | 26 | content Printout |
diff --git a/server/src/Thermoprint/Server/Database/Instances.hs b/server/src/Thermoprint/Server/Database/Instances.hs new file mode 100644 index 0000000..f5c22fd --- /dev/null +++ b/server/src/Thermoprint/Server/Database/Instances.hs | |||
@@ -0,0 +1,33 @@ | |||
1 | {-# LANGUAGE TemplateHaskell #-} | ||
2 | {-# LANGUAGE TypeSynonymInstances #-} | ||
3 | {-# LANGUAGE FlexibleInstances #-} | ||
4 | |||
5 | module Thermoprint.Server.Database.Instances where | ||
6 | |||
7 | import Thermoprint.API (Printout, JobStatus, PrintingError) | ||
8 | |||
9 | import Database.Persist (PersistField(..)) | ||
10 | import Database.Persist.Sql (PersistFieldSql(..)) | ||
11 | import Database.Persist.TH | ||
12 | |||
13 | import Control.Monad ((<=<)) | ||
14 | import Data.Bifunctor | ||
15 | |||
16 | import qualified Data.Aeson as JSON (encode, eitherDecodeStrict') | ||
17 | |||
18 | import Data.ByteString (ByteString) | ||
19 | import qualified Data.ByteString.Lazy as LBS (toStrict) | ||
20 | import qualified Data.Text as T (pack) | ||
21 | |||
22 | import Data.Proxy | ||
23 | |||
24 | -- | Instead of deriving an instance using 'derivePersistField', which would use 'show' and 'read', we write our own by hand in order to use json | ||
25 | instance PersistField Printout where | ||
26 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode | ||
27 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue | ||
28 | |||
29 | instance PersistFieldSql Printout where | ||
30 | sqlType _ = sqlType (Proxy :: Proxy ByteString) | ||
31 | |||
32 | derivePersistField "PrintingError" | ||
33 | derivePersistField "JobStatus" | ||
diff --git a/server/src/Thermoprint/Server/Printer.hs b/server/src/Thermoprint/Server/Printer.hs new file mode 100644 index 0000000..e66afff --- /dev/null +++ b/server/src/Thermoprint/Server/Printer.hs | |||
@@ -0,0 +1,29 @@ | |||
1 | {-# LANGUAGE RankNTypes #-} | ||
2 | |||
3 | module Thermoprint.Server.Printer | ||
4 | ( Printer | ||
5 | ) where | ||
6 | |||
7 | import Thermoprint.API (PrintingError(..), Printout) | ||
8 | |||
9 | import Thermoprint.Server.Database | ||
10 | |||
11 | import Database.Persist | ||
12 | import Database.Persist.Sql | ||
13 | |||
14 | import Data.Sequence (Seq, ViewL(..)) | ||
15 | import qualified Data.Sequence as Seq | ||
16 | import Data.Map (Map) | ||
17 | import qualified Data.Map as Map | ||
18 | |||
19 | import Control.Monad.IO.Class (MonadIO) | ||
20 | |||
21 | import Control.Concurrent.STM | ||
22 | |||
23 | data Printer = Printer | ||
24 | { print :: forall m. (MonadIO m) => Printout -> m (Maybe PrintingError) | ||
25 | , queue :: TVar (Seq JobId) | ||
26 | } | ||
27 | |||
28 | runPrinter :: Printer -> IO () | ||
29 | runPrinter = undefined | ||
diff --git a/server/thermoprint-server.cabal b/server/thermoprint-server.cabal index 45f24d3..bd22482 100644 --- a/server/thermoprint-server.cabal +++ b/server/thermoprint-server.cabal | |||
@@ -20,7 +20,8 @@ library | |||
20 | exposed-modules: Thermoprint.Server | 20 | exposed-modules: Thermoprint.Server |
21 | , Thermoprint.Server.Database | 21 | , Thermoprint.Server.Database |
22 | , Thermoprint.Server.API | 22 | , Thermoprint.Server.API |
23 | -- other-modules: | 23 | , Thermoprint.Server.Printer |
24 | other-modules: Thermoprint.Server.Database.Instances | ||
24 | -- other-extensions: | 25 | -- other-extensions: |
25 | build-depends: base >=4.8 && <5 | 26 | build-depends: base >=4.8 && <5 |
26 | , thermoprint-spec ==3.0.* | 27 | , thermoprint-spec ==3.0.* |
@@ -38,6 +39,9 @@ library | |||
38 | , containers >=0.5.6 && <1 | 39 | , containers >=0.5.6 && <1 |
39 | , either >=4.4.1 && <5 | 40 | , either >=4.4.1 && <5 |
40 | , text >=1.2.1 && <2 | 41 | , text >=1.2.1 && <2 |
42 | , stm >=2.4.4 && <3 | ||
43 | , aeson >=0.9.0 && <1 | ||
44 | , bytestring >=0.10.6 && <1 | ||
41 | hs-source-dirs: src | 45 | hs-source-dirs: src |
42 | default-language: Haskell2010 | 46 | default-language: Haskell2010 |
43 | 47 | ||
diff --git a/server/thermoprint-server.nix b/server/thermoprint-server.nix index c48ec7f..0f85c9d 100644 --- a/server/thermoprint-server.nix +++ b/server/thermoprint-server.nix | |||
@@ -1,7 +1,7 @@ | |||
1 | { mkDerivation, base, containers, data-default-class, dyre, either | 1 | { mkDerivation, aeson, base, bytestring, containers |
2 | , monad-logger, mtl, persistent, persistent-sqlite | 2 | , data-default-class, dyre, either, monad-logger, mtl, persistent |
3 | , persistent-template, resourcet, servant-server, stdenv, text | 3 | , persistent-sqlite, persistent-template, resourcet, servant-server |
4 | , thermoprint-spec, transformers, wai, warp | 4 | , stdenv, stm, text, thermoprint-spec, transformers, wai, warp |
5 | }: | 5 | }: |
6 | mkDerivation { | 6 | mkDerivation { |
7 | pname = "thermoprint-server"; | 7 | pname = "thermoprint-server"; |
@@ -10,9 +10,9 @@ mkDerivation { | |||
10 | isLibrary = true; | 10 | isLibrary = true; |
11 | isExecutable = true; | 11 | isExecutable = true; |
12 | libraryHaskellDepends = [ | 12 | libraryHaskellDepends = [ |
13 | base containers data-default-class dyre either monad-logger mtl | 13 | aeson base bytestring containers data-default-class dyre either |
14 | persistent persistent-template resourcet servant-server text | 14 | monad-logger mtl persistent persistent-template resourcet |
15 | thermoprint-spec transformers wai warp | 15 | servant-server stm text thermoprint-spec transformers wai warp |
16 | ]; | 16 | ]; |
17 | executableHaskellDepends = [ | 17 | executableHaskellDepends = [ |
18 | base monad-logger mtl persistent-sqlite resourcet | 18 | base monad-logger mtl persistent-sqlite resourcet |