List books (#2)

This commit is contained in:
Mats Rauhala 2018-08-28 23:25:48 +03:00
parent efa7ed7f92
commit a7f75ee20e
2 changed files with 13 additions and 4 deletions

View File

@ -27,8 +27,8 @@ data Index = Index
type API = Get '[HTML] (AppView Index)
:<|> Users.API
:<|> "api" :> Channels.API
:<|> "api" :> Books.API
:<|> "api" :> "current" :> Channels.API
:<|> "api" :> "current" :> Books.API
:<|> "api" :> "1" :> Catalogue.VersionedAPI 1
:<|> "api" :> "current" :> Catalogue.VersionedAPI 1

View File

@ -82,8 +82,17 @@ insertChannel username channel visibility = runMaybeT $ do
return userId
channelBooks :: (MonadSelda m, MonadMask m, MonadIO m) => Username -> ChannelID -> m [Book]
channelBooks _username _channelID = do
return []
channelBooks username identifier = fromRels <$> query q
where
q = do
channelId :*: bookId' <- select (gen bookChannels)
channelId' :*: _ :*: owner :*: _ <- select (gen channels)
userId :*: _ :*: username' :*: _ <- select (gen users)
book@(bookId :*: _) <- select (gen books)
restrict (username' .== literal username .&& owner .== userId)
restrict (channelId .== literal identifier .&& channelId .== channelId')
restrict (bookId .== bookId')
return book
booksChannels :: (MonadSelda m, MonadMask m, MonadIO m) => BookID -> m [Channel]
booksChannels bookId = fromRels <$> query q