datatype fixes
This commit is contained in:
parent
1a502c7c7c
commit
7d689e9d33
1 changed files with 19 additions and 16 deletions
|
@ -1,3 +1,4 @@
|
|||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
|
@ -24,6 +25,7 @@ module Aggreact.Comments
|
|||
Id (..)
|
||||
, Comment (..)
|
||||
, Comments
|
||||
, CommentTable (..)
|
||||
) where
|
||||
|
||||
import Protolude hiding (get, put)
|
||||
|
@ -31,14 +33,12 @@ import Protolude hiding (get, put)
|
|||
import Data.Aeson (FromJSON, ToJSON)
|
||||
import Data.Char (isAlphaNum)
|
||||
import Data.Data (Data (..))
|
||||
import Data.IxSet ((@=))
|
||||
import qualified Data.IxSet as IxSet
|
||||
import Data.Serialize (Serialize (..))
|
||||
import Data.Serialize.Text ()
|
||||
import qualified Data.Text as Text
|
||||
import Data.Time (UTCTime)
|
||||
import Data.Time.Clock.Serialize ()
|
||||
import Data.Tree (Tree (..))
|
||||
import Data.Typeable (Typeable)
|
||||
|
||||
import Versioning.Base
|
||||
|
@ -46,7 +46,8 @@ import Versioning.Base
|
|||
|
||||
-- * Comments
|
||||
|
||||
data CommentTable v = IxSet (Comment v)
|
||||
type Comments = CommentTable V0
|
||||
newtype CommentTable v = IxSet (Comment v)
|
||||
|
||||
-- Orphan Instance for Serialize IxSet
|
||||
instance ( Serialize a
|
||||
|
@ -58,22 +59,22 @@ instance ( Serialize a
|
|||
|
||||
-- * Comment
|
||||
|
||||
newtype Id = Id Int64 deriving (Eq,Ord,Generic)
|
||||
newtype Id = Id Int64 deriving (Eq,Ord,Generic,Data)
|
||||
deriving instance FromJSON Id
|
||||
deriving instance ToJSON Id
|
||||
deriving instance Serialize Id
|
||||
|
||||
newtype ParentId = ParentId Int64 deriving (Eq,Ord,Generic)
|
||||
newtype ParentId = ParentId Int64 deriving (Eq,Ord,Generic,Data)
|
||||
deriving instance FromJSON ParentId
|
||||
deriving instance ToJSON ParentId
|
||||
deriving instance Serialize ParentId
|
||||
|
||||
newtype UserId = UserId Text deriving (Eq,Ord,Generic)
|
||||
newtype UserId = UserId Text deriving (Eq,Ord,Generic,Data)
|
||||
deriving instance FromJSON UserId
|
||||
deriving instance ToJSON UserId
|
||||
deriving instance Serialize UserId
|
||||
|
||||
newtype Content = Content Text deriving (Eq,Ord,Generic)
|
||||
newtype Content = Content Text deriving (Eq,Ord,Generic,Data)
|
||||
deriving instance FromJSON Content
|
||||
deriving instance ToJSON Content
|
||||
deriving instance Serialize Content
|
||||
|
@ -87,11 +88,12 @@ data Comment v =
|
|||
, created :: UTCTime
|
||||
, content :: Content
|
||||
, userid :: Since V0 v UserId
|
||||
} deriving (Generic,Typeable,Data)
|
||||
} deriving (Generic,Typeable)
|
||||
|
||||
deriving instance FromJSON (Comment V0)
|
||||
deriving instance ToJSON (Comment V0)
|
||||
deriving instance Serialize (Comment V0)
|
||||
deriving instance Data (Comment V0)
|
||||
instance IxSet.Indexable (Comment V0) where
|
||||
empty =
|
||||
IxSet.ixSet
|
||||
|
@ -101,7 +103,8 @@ instance IxSet.Indexable (Comment V0) where
|
|||
, IxSet.ixFun getTerms -- Ability to search content text
|
||||
]
|
||||
|
||||
getTerms = map Term . Text.split (not . isAlphaNum) . Text.words . unContent . content
|
||||
getTerms :: Comment v -> [Term]
|
||||
getTerms = fmap Term . Text.split (not . isAlphaNum) . unContent . content
|
||||
where unContent (Content x) = x
|
||||
|
||||
-- * Root
|
||||
|
|
Loading…
Reference in a new issue