Skip to content

Commit

Permalink
Fix pagination for results including total count
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Aug 21, 2017
1 parent 32370de commit c503ff1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Network/GitHub/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ type family ReadHeaders a :: * where
ReadHeaders (Patch cts [res])
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Patch cts (Headers '[Header "Link" Text] [res])
ReadHeaders (Get cts (CountedList name res))
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Get cts (Headers '[Header "Link" Text] (CountedList name res))
ReadHeaders (Post cts (CountedList name res))
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Post cts (Headers '[Header "Link" Text] (CountedList name res))
ReadHeaders (Delete cts (CountedList name res))
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Delete cts (Headers '[Header "Link" Text] (CountedList name res))
ReadHeaders (Put cts (CountedList name res))
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Put cts (Headers '[Header "Link" Text] (CountedList name res))
ReadHeaders (Patch cts (CountedList name res))
= QueryParam "page" Int :> QueryParam "per_page" Int
:> Patch cts (Headers '[Header "Link" Text] (CountedList name res))
ReadHeaders otherwise = otherwise

-- | Client function that returns a single result
Expand Down Expand Up @@ -248,6 +263,29 @@ instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> k -> l -> Paginated
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> k -> l -> m -> Paginated f) where
embedGitHub comp arg = embedGitHub (comp arg)

instance HasGitHub (a -> CountedPaginated name b) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> CountedPaginated name c) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> CountedPaginated name d) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> CountedPaginated name e) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> k -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> k -> l -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)
instance HasGitHub (a -> b -> c -> d -> e -> g -> h -> i -> k -> l -> m -> CountedPaginated name f) where
embedGitHub comp arg = embedGitHub (comp arg)

-- | Wrapper around the servant 'client' function, that takes care of the
-- extra headers that required for the 'GitHub' monad.
github :: (HasClient (AddHeaders api), HasGitHub (Client (AddHeaders api)))
Expand Down

0 comments on commit c503ff1

Please sign in to comment.