/
Types.hs
124 lines (105 loc) · 3.39 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module : FeedReader.Data.DB
-- Copyright : (c) 2015 Călin Ardelean
-- License : BSD-style
--
-- Maintainer : Călin Ardelean <calinucs@gmail.com>
-- Stability : experimental
-- Portability : portable
--
-- This module provides the core types and functions for Feed Reader.
----------------------------------------------------------------------------
module FeedReader.Types
( Cat (..)
, Feed (..)
, Person (..)
, Item (..)
, ItemStatus (..)
, ItemStatusKey (..)
, URL
, Language
, Tag
, Content (..)
, HTTPAuth (..)
, Image (..)
, Sortable (..)
, Unique (..)
) where
import Data.Hashable (Hashable (..))
import Data.Serialize (Serialize (..))
import Database.Muesli.Types
import GHC.Generics (Generic)
type URL = String
type Language = String
type Tag = String
data Content = Text String | HTML String | XHTML String
deriving (Show, Generic, Serialize, Indexable)
data Cat = Cat
{ catName :: Sortable String
, catParent :: Maybe (Reference Cat)
} deriving (Show, Generic, Serialize)
instance Document Cat
data Person = Person
{ personName :: Unique (Sortable String)
, personURL :: URL
, personEmail :: String
} deriving (Show, Generic, Serialize)
instance Document Person
data Image = Image
{ imageURL :: URL
, imageTitle :: String
, imageDescription :: String
, imageLink :: URL
, imageWidth :: Int
, imageHeight :: Int
} deriving (Show, Generic, Serialize, Indexable)
data HTTPAuth = HTTPAuth
{ authUserName :: String
, authPassword :: String
} deriving (Show, Generic, Serialize, Indexable)
data Feed = Feed
{ feedCat :: Maybe (Reference Cat)
, feedURL :: Unique URL
, feedHTTPAuth :: Maybe HTTPAuth
, feedWebURL :: URL
, feedTitle :: Sortable Content
, feedDescription :: Content
, feedLanguage :: Language
, feedAuthors :: [Reference Person]
, feedContributors :: [Reference Person]
, feedRights :: Content
, feedImage :: Maybe Image
, feedUpdated :: Sortable DateTime
, feedUnsubscribed :: Bool
, feedLastError :: Maybe String
} deriving (Show, Generic, Serialize)
-- TODO: Sortable -> Sorted, Reference -> Ref
-- TODO: filter on Sorted columns
-- TODO: File backend: process file locking
-- TODO: optimize getDocument (hash id => multiple caches)
instance Document Feed
data ItemStatusKey = StatusNew | StatusUnread | StatusRead | StatusStarred
deriving (Show, Generic, Serialize, Indexable, Hashable)
data ItemStatus = ItemStatus
{ statusKey :: Unique ItemStatusKey
} deriving (Show, Generic, Serialize)
instance Document ItemStatus
data Item = Item
{ itemFeed :: Reference Feed
, itemURL :: Unique URL
, itemTitle :: Content
, itemSummary :: Content
, itemTags :: [Sortable Tag]
, itemAuthors :: [Reference Person]
, itemContributors :: [Reference Person]
, itemRights :: Content
, itemContent :: Content
, itemPublished :: Sortable DateTime
, itemUpdated :: Sortable DateTime
, itemStatus :: Reference ItemStatus
} deriving (Show, Generic, Serialize)
instance Document Item