Move the book to have an id as well
This commit is contained in:
parent
881c53493f
commit
5dac8374fd
@ -49,6 +49,6 @@ listBooksHandler :: AuthResult SafeUser -> AppM [JsonBook]
|
|||||||
listBooksHandler = requireLoggedIn $ \user -> do
|
listBooksHandler = requireLoggedIn $ \user -> do
|
||||||
runDB (usersBooks (view (field @"username") user) >>= mapM augment)
|
runDB (usersBooks (view (field @"username") user) >>= mapM augment)
|
||||||
where
|
where
|
||||||
augment Book{..} = do
|
augment Book{identifier=bookId,..} = do
|
||||||
channels <- fmap (\Channel{..} -> JsonChannel{..}) <$> booksChannels contentHash
|
channels <- fmap (\Channel{..} -> JsonChannel{..}) <$> booksChannels bookId
|
||||||
pure JsonBook{..}
|
pure JsonBook{..}
|
||||||
|
@ -34,7 +34,7 @@ insertChannel username channel = do
|
|||||||
restrict (user .== literal username)
|
restrict (user .== literal username)
|
||||||
return userId
|
return userId
|
||||||
|
|
||||||
booksChannels :: (MonadMask m, MonadIO m) => HashDigest -> SeldaT m [Channel]
|
booksChannels :: (MonadMask m, MonadIO m) => BookID -> SeldaT m [Channel]
|
||||||
booksChannels contentHash = fromRels <$> query q
|
booksChannels contentHash = fromRels <$> query q
|
||||||
where
|
where
|
||||||
q = do
|
q = do
|
||||||
|
@ -97,7 +97,8 @@ users = genTable "users" [ (email :: User HashedPassword -> Email) :- uniqueGen
|
|||||||
-- | Book type
|
-- | Book type
|
||||||
newtype HashDigest = HashDigest { unHex :: Text } deriving Show
|
newtype HashDigest = HashDigest { unHex :: Text } deriving Show
|
||||||
-- XXX: Add an identifier for the book
|
-- XXX: Add an identifier for the book
|
||||||
data Book = Book { contentHash :: HashDigest
|
data Book = Book { identifier :: BookID
|
||||||
|
, contentHash :: HashDigest
|
||||||
, contentType :: Text
|
, contentType :: Text
|
||||||
, title :: Maybe Text
|
, title :: Maybe Text
|
||||||
, description :: Maybe Text }
|
, description :: Maybe Text }
|
||||||
@ -110,15 +111,15 @@ instance SqlType HashDigest where
|
|||||||
defaultValue = mkLit (HashDigest "") -- Doesn't really make sense
|
defaultValue = mkLit (HashDigest "") -- Doesn't really make sense
|
||||||
|
|
||||||
books :: GenTable Book
|
books :: GenTable Book
|
||||||
books = genTable "books" [ contentHash :- primaryGen ]
|
books = genTable "books" [ (identifier :: Book -> BookID) :- primaryGen ]
|
||||||
|
|
||||||
data UserBook = UserBook { user :: UserID
|
data UserBook = UserBook { user :: UserID
|
||||||
, book :: HashDigest }
|
, book :: BookID }
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
userBooks :: GenTable UserBook
|
userBooks :: GenTable UserBook
|
||||||
userBooks = genTable "user_book" [ (user :: UserBook -> UserID) :- fkGen (gen users) userId
|
userBooks = genTable "user_book" [ (user :: UserBook -> UserID) :- fkGen (gen users) userId
|
||||||
, (book :: UserBook -> HashDigest) :- fkGen (gen books) bookHash ]
|
, (book :: UserBook -> BookID) :- fkGen (gen books) bookHash ]
|
||||||
where
|
where
|
||||||
userId :*: _ = selectors (gen users)
|
userId :*: _ = selectors (gen users)
|
||||||
bookHash :*: _ = selectors (gen books)
|
bookHash :*: _ = selectors (gen books)
|
||||||
@ -147,23 +148,23 @@ channels = genTable "channels" [ (identifier :: Channel -> ChannelID) :- autoPri
|
|||||||
i :*: _ = selectors (gen users)
|
i :*: _ = selectors (gen users)
|
||||||
|
|
||||||
data BookTag = BookTag { tag :: TagID
|
data BookTag = BookTag { tag :: TagID
|
||||||
, book :: HashDigest }
|
, book :: BookID }
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
data BookChannel = BookChannel { channel :: ChannelID
|
data BookChannel = BookChannel { channel :: ChannelID
|
||||||
, book :: HashDigest }
|
, book :: BookID }
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
bookTags :: GenTable BookTag
|
bookTags :: GenTable BookTag
|
||||||
bookTags = genTable "book_tags" [ (tag :: BookTag -> TagID) :- fkGen (gen tags) i
|
bookTags = genTable "book_tags" [ (tag :: BookTag -> TagID) :- fkGen (gen tags) i
|
||||||
, (book :: BookTag -> HashDigest) :- fkGen (gen books) h ]
|
, (book :: BookTag -> BookID) :- fkGen (gen books) h ]
|
||||||
where
|
where
|
||||||
i :*: _ = selectors (gen tags)
|
i :*: _ = selectors (gen tags)
|
||||||
h :*: _ = selectors (gen books)
|
h :*: _ = selectors (gen books)
|
||||||
|
|
||||||
bookChannels :: GenTable BookChannel
|
bookChannels :: GenTable BookChannel
|
||||||
bookChannels = genTable "book_channels" [ (channel :: BookChannel -> ChannelID) :- fkGen (gen channels) i
|
bookChannels = genTable "book_channels" [ (channel :: BookChannel -> ChannelID) :- fkGen (gen channels) i
|
||||||
, (book :: BookChannel -> HashDigest) :- fkGen (gen books) h ]
|
, (book :: BookChannel -> BookID) :- fkGen (gen books) h ]
|
||||||
where
|
where
|
||||||
i :*: _ = selectors (gen channels)
|
i :*: _ = selectors (gen channels)
|
||||||
h :*: _ = selectors (gen books)
|
h :*: _ = selectors (gen books)
|
||||||
|
Loading…
Reference in New Issue
Block a user