on master help sign in
Added ability to query all users.
commit9d2df6cec0db216a9279307eb6a5a385f14be356 authoriko <ilyakooo0@gmail.com> dateWed 13 Mar 2019, 14:17 (8 years ago) parent444c4fa
2 files changed+9
denis/src/Data/Query.hs+7 denis/src/Server/API.hs+2
denis/src/Data/Query.hs+7
@@ -16,6 +16,7 @@ module Data.Query (
1616 getPosts,
1717 getUser,
1818 getUsers,
19+ getAllUsers,
1920 getLastPosts,
2021 getPostsForUser,
2122 Limit,
@@ -124,6 +125,9 @@ getUsersQ uIds = case idsToColumn uIds of
124125 (#ids ! #id .== #users ! #userId))
125126 Nothing -> Nothing
126127
128+getAllUsersQ :: Query Schema '[] (RowPG User)
129+getAllUsersQ = selectStar $ from $ table #users
130+
127131getPostsByIdQ :: [PostId] -> Maybe (Query Schema '[] (RowPG PostRowResponse))
128132getPostsByIdQ pIds = case idsToColumn pIds of
129133 Just idQ -> Just $ selectDotStar #posts $ from (subquery (idQ `As` #ids) &
@@ -285,6 +289,9 @@ getUser uId = runQueryParams getUserQ (Only uId) >>= getRow 0
285289
286290getUsers :: [UserId] -> StaticPQ (Maybe [User])
287291getUsers ids = getUsersQ ids `liftMaybe` (fmap Just . (runQuery >=> getRows))
292+
293+getAllUsers :: StaticPQ [User]
294+getAllUsers = runQuery getAllUsersQ >>= getRows
288295
289296publishPost :: UserId -> PostCreation -> StaticPQ PostId
290297publishPost uId pc = transactionally_ $ do
denis/src/Server/API.hs+2
@@ -45,6 +45,7 @@ type API =
4545 Authentication :> (
4646 "authentication" :> "me" :> Post '[JSON] UserId :<|>
4747 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User] :<|>
48+ "users" :> "all" :> Post '[JSON] [User] :<|>
4849 "posts" :> PostApi :<|>
4950 "channels" :> ChannelsApi
5051 )
@@ -58,6 +59,7 @@ mkServerAPI l =
5859 authenticationAPI :<|> (\uId ->
5960 return uId :<|>
6061 maybeNotFound . runQnotFound . getUsers :<|>
62+ runQnotFound getAllUsers :<|>
6163 postApi uId :<|>
6264 channelsApi uId
6365 )