diff --git a/src/API.hs b/src/API.hs index b1ef02c..3186b6a 100644 --- a/src/API.hs +++ b/src/API.hs @@ -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 diff --git a/src/Database/Channel.hs b/src/Database/Channel.hs index 4af4fc3..ef0515a 100644 --- a/src/Database/Channel.hs +++ b/src/Database/Channel.hs @@ -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