removed service

This commit is contained in:
Yann Esposito (Yogsototh) 2019-08-07 22:33:20 +02:00
parent 2725dcef74
commit e09653d3a6
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
6 changed files with 19 additions and 153 deletions

View file

@ -4,7 +4,7 @@ cabal-version: 1.12
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: c6ba67633d506787943c9e979e0f721a602447dfad110f1302bbd2c64035d461 -- hash: 45f4a7726914fbb361f0d4f25c0b9f0520907688f03bde8ff31dda1fcaa58274
name: aggreact name: aggreact
version: 0.1.0.0 version: 0.1.0.0
@ -61,8 +61,6 @@ library
Generics.SOP.Fieldnames Generics.SOP.Fieldnames
Servant.Clay Servant.Clay
Servant.Errors Servant.Errors
Service.Config
Service.Service
other-modules: other-modules:
Paths_aggreact Paths_aggreact
hs-source-dirs: hs-source-dirs:

View file

@ -64,7 +64,8 @@ type CommentAPI =
:<|> "comment" :> Capture "commentId" Text :<|> "comment" :> Capture "commentId" Text
:> Get '[HTML,JSON] CommentPage :> Get '[HTML,JSON] CommentPage
:<|> "comment" :> Capture "commentId" Text :<|> "comment" :> Capture "commentId" Text
:> DeleteAccepted '[JSON] () :> "delete"
:> PostAccepted '[JSON] ()
data Handlers = data Handlers =
Handlers { userHandler :: UserHandler Handlers { userHandler :: UserHandler

View file

@ -139,14 +139,6 @@ deriving instance (FromJSON ms, FromJSON a) => FromJSON (Entity ms a)
deriving instance (FromJSON ms, FromJWT ms, FromJSON a, FromJWT a) => FromJWT (Entity ms a) deriving instance (FromJSON ms, FromJWT ms, FromJSON a, FromJWT a) => FromJWT (Entity ms a)
deriving instance (ToJSON ms, ToJWT ms, ToJSON a, ToJWT a) => ToJWT (Entity ms a) deriving instance (ToJSON ms, ToJWT ms, ToJSON a, ToJWT a) => ToJWT (Entity ms a)
-- data StoreService store metas entity
-- data family StoreConfig store
-- data family StoreHandler store
--
-- instance Serv.Service (StoreService store metas entity) b where
-- type Config (StoreService store metas entity) b = StoreConfig store
-- type Handle (StoreService store metas entity) b = StoreHandler store
class Store store m metas entity | store -> m metas entity where class Store store m metas entity | store -> m metas entity where
data DBConf store data DBConf store
data StartedStore store data StartedStore store

View file

@ -1,21 +1,21 @@
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE BlockArguments #-} -- blabla do ... instead of blabla $ do ... {-# LANGUAGE BlockArguments #-} -- blabla do ... instead of blabla $ do ...
{-# LANGUAGE DeriveGeneric #-} -- deriving ToJSON ... {-# LANGUAGE DeriveGeneric #-} -- deriving ToJSON ...
{-# LANGUAGE DerivingStrategies #-} -- remove warn about deriving strategies {-# LANGUAGE DerivingStrategies #-} -- remove warn about deriving strategies
{-# LANGUAGE ExplicitForAll #-} -- f :: forall a b. a -> b -> b {-# LANGUAGE ExplicitForAll #-} -- f :: forall a b. a -> b -> b
{-# LANGUAGE GeneralizedNewtypeDeriving #-} -- newtype Id = Id Text deriving (StringConv Id String) {-# LANGUAGE GeneralizedNewtypeDeriving #-} -- newtype Id = Id Text deriving (StringConv Id String)
{-# LANGUAGE NamedWildCards #-} -- can use _type instead of just _ {-# LANGUAGE NamedWildCards #-} -- can use _type instead of just _
{-# LANGUAGE NoImplicitPrelude #-} -- to use protolude for example {-# LANGUAGE NoImplicitPrelude #-} -- to use protolude for example
{-# LANGUAGE NumericUnderscores #-} -- write 1_000 instead of 1000 {-# LANGUAGE NumericUnderscores #-} -- write 1_000 instead of 1000
{-# LANGUAGE OverloadedLists #-} -- write [1,2,3] :: Set {-# LANGUAGE OverloadedLists #-} -- write [1,2,3] :: Set
{-# LANGUAGE OverloadedStrings #-} -- write "foo" and it will be the correct text type {-# LANGUAGE OverloadedStrings #-} -- write "foo" and it will be the correct text type
{-# LANGUAGE PartialTypeSignatures #-} -- {-# LANGUAGE PartialTypeSignatures #-} --
{-# LANGUAGE RecordWildCards #-} -- f Conf{..} = field1 ... {-# LANGUAGE RecordWildCards #-} -- f Conf{..} = field1 ...
{-# LANGUAGE ScopedTypeVariables #-} -- write expr :: Type inside an expression {-# LANGUAGE ScopedTypeVariables #-} -- write expr :: Type inside an expression
{-# LANGUAGE StandaloneDeriving #-} -- write deriving instance ... {-# LANGUAGE StandaloneDeriving #-} -- write deriving instance ...
{-# LANGUAGE Strict #-} -- a la Clojure {-# LANGUAGE Strict #-} -- a la Clojure
{-# LANGUAGE TupleSections #-} -- (a,,) instead of \x y -> (a,x,y) {-# LANGUAGE TupleSections #-} -- (a,,) instead of \x y -> (a,x,y)
module Servant.Errors where module Servant.Errors where
import Protolude import Protolude

View file

@ -1,81 +0,0 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
-- Common
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE NamedWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- |
Module : Database.Store.SQLite
Description : SQLite implentation for Store
Copyright : (c) 2018, Yann Esposito
License : ISC
Maintainer : yann.esposito@gmail.com
Stability : experimental
Portability : POSIX
Provide a Service Abstraction
-}
module Service.Config where
import Protolude hiding (Handle)
import Service.Service
import Dhall
import Data.Yaml
import System.FilePath
data ConfigService a
newtype ConfigServiceConfig conf =
ConfigServiceConfig { config :: Either conf FilePath }
newtype ConfigSvc a = ConfigSvc { getConfig :: a }
{-
Configuration service that can read a configuration from a file.
-}
instance ( a ~ b
, Interpret b
, FromJSON b
) => Service (ConfigService a) b where
type Config (ConfigService a) b = ConfigServiceConfig b
type Handle (ConfigService a) b = ConfigSvc b
init _ ConfigServiceConfig{..} = ConfigSvc <$>
case config of
Left c -> return c
Right configFile ->
case takeExtension configFile of
".dhall" -> input auto (toS configFile)
".json" -> parseyaml configFile -- json are yaml
".yaml" -> parseyaml configFile
_ -> die "unrecognized format (only .dhall, .json and .yaml are supported)"
where
parseyaml configFile = do
parseResult <- decodeFileEither configFile
case parseResult of
Left err -> die ("Error while parsing " <> toS configFile <> ":\n"
<> toS (prettyPrintParseException err))
Right c -> return c

View file

@ -1,44 +0,0 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
-- Common
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE NamedWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- |
Module : Database.Store.SQLite
Description : SQLite implentation for Store
Copyright : (c) 2018, Yann Esposito
License : ISC
Maintainer : yann.esposito@gmail.com
Stability : experimental
Portability : POSIX
Provide a Service Abstraction
-}
module Service.Service where
import Protolude hiding (Handle)
import Control.Exception (bracket)
class Service s a where
type Config s a -- the initial config a service should have
type Handle s a -- a type that should contains methods provided by the service
init :: Proxy (Service s a) -> Config s a -> IO (Handle s a)
stop :: Proxy (Service s a) -> Handle s a -> IO ()
stop _ _ = pure ()
withService :: Config s a -> (Handle s a -> IO b) -> IO b
withService config = bracket (init svc config) (stop svc)
where svc = Proxy :: Proxy (Service s a)