module Web.RBB.Types.Entry
where
import Control.Lens hiding (Context, Indexable)
import Data.Data (Data, Typeable)
import Data.FileStore (RevisionId, UTCTime)
import Data.Function (on)
import Data.IxSet
import Data.Set (Set)
import Data.Text (Text)
import Web.RBB.Types.FileType
newtype EntryUpdateTime = EntryUpdateTime { getEntryTime :: UTCTime }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype EntryRevisionId = EntryRevisionId { getEntryRevisionId :: RevisionId }
deriving (Eq, Ord, Show, Read, Data, Typeable)
data EntryUpdate = EntryUpdate
{ entryUpdateTime :: UTCTime
, entryRevisionId :: RevisionId
}
deriving (Eq, Show, Read, Data, Typeable)
instance Ord EntryUpdate where
compare a b = case (compare `on` entryUpdateTime) a b of
EQ -> (compare `on` entryRevisionId) a b
c -> c
instance Indexable EntryUpdate where
empty = ixSet
[ ixFun $ \eu -> [ EntryUpdateTime $ entryUpdateTime eu ]
, ixFun $ \eu -> [ EntryRevisionId $ entryRevisionId eu ]
]
newtype Title = Title { getTitle :: Text }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype AuthorName = AuthorName { getAuthorName :: Text }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype AuthorEmail = AuthorEmail { getAuthorEmail :: Text }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype Tags = Tags { getTags :: Set Text }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype RelativePath = RelativePath { getRelativePath :: FilePath }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype FullPath = FullPath { getFullPath :: FilePath }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype Index = Index { getIndex :: Integer }
deriving (Eq, Ord, Show, Read, Data, Typeable)
newtype LastUpdate = LastUpdate { getLastUpdate :: EntryUpdate }
deriving (Eq, Ord, Show, Read, Data, Typeable)
data Entry = Entry
{ _entryId :: Integer
, _title :: Text
, _author :: Text
, _authorEmail :: Text
, _tags :: Set Text
, _fileType :: FileType
, _relativePath :: FilePath
, _fullPath :: FilePath
, _updates :: IxSet EntryUpdate
, _lastUpdate :: EntryUpdate
}
deriving (Eq, Ord, Show, Read, Data, Typeable)
makeLenses ''Entry
instance Indexable Entry where
empty = ixSet
[ ixFun $ \e -> [ Index $ e^.entryId ]
, ixFun $ \e -> [ Title $ e^.title ]
, ixFun $ \e -> [ AuthorName $ e^.author ]
, ixFun $ \e -> [ AuthorEmail $ e^.authorEmail ]
, ixFun $ \e -> [ e^.fileType ]
, ixFun $ \e -> [ RelativePath $ e^.relativePath ]
, ixFun $ \e -> [ FullPath $ e^.fullPath ]
, ixFun $ \e -> toDescList (Proxy :: Proxy EntryUpdate) (e^.updates)
, ixFun $ \e -> [ LastUpdate $ e^.lastUpdate ]
]