on master help sign in
Added ability to query all users.
9d2df6ciko
denis/src/Data/Query.hs+7
@@ -16,6 +16,7 @@ module Data.Query (
16 getPosts,
16 getPosts,
17 getUser,
17 getUser,
18 getUsers,
18 getUsers,
19+ getAllUsers,
19 getLastPosts,
20 getLastPosts,
20 getPostsForUser,
21 getPostsForUser,
21 Limit,
22 Limit,
@@ -124,6 +125,9 @@ getUsersQ uIds = case idsToColumn uIds of
124 (#ids ! #id .== #users ! #userId))
125 (#ids ! #id .== #users ! #userId))
125 Nothing -> Nothing
126 Nothing -> Nothing
126
127
128+getAllUsersQ :: Query Schema '[] (RowPG User)
129+getAllUsersQ = selectStar $ from $ table #users
130+
127getPostsByIdQ :: [PostId] -> Maybe (Query Schema '[] (RowPG PostRowResponse))
131getPostsByIdQ :: [PostId] -> Maybe (Query Schema '[] (RowPG PostRowResponse))
128getPostsByIdQ pIds = case idsToColumn pIds of
132getPostsByIdQ pIds = case idsToColumn pIds of
129 Just idQ -> Just $ selectDotStar #posts $ from (subquery (idQ `As` #ids) &
133 Just idQ -> Just $ selectDotStar #posts $ from (subquery (idQ `As` #ids) &
@@ -285,6 +289,9 @@ getUser uId = runQueryParams getUserQ (Only uId) >>= getRow 0
285
289
286getUsers :: [UserId] -> StaticPQ (Maybe [User])
290getUsers :: [UserId] -> StaticPQ (Maybe [User])
287getUsers ids = getUsersQ ids `liftMaybe` (fmap Just . (runQuery >=> getRows))
291getUsers ids = getUsersQ ids `liftMaybe` (fmap Just . (runQuery >=> getRows))
292+
293+getAllUsers :: StaticPQ [User]
294+getAllUsers = runQuery getAllUsersQ >>= getRows
288
295
289publishPost :: UserId -> PostCreation -> StaticPQ PostId
296publishPost :: UserId -> PostCreation -> StaticPQ PostId
290publishPost uId pc = transactionally_ $ do
297publishPost uId pc = transactionally_ $ do
denis/src/Server/API.hs+2
@@ -45,6 +45,7 @@ type API =
45 Authentication :> (
45 Authentication :> (
46 "authentication" :> "me" :> Post '[JSON] UserId :<|>
46 "authentication" :> "me" :> Post '[JSON] UserId :<|>
47 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User] :<|>
47 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User] :<|>
48+ "users" :> "all" :> Post '[JSON] [User] :<|>
48 "posts" :> PostApi :<|>
49 "posts" :> PostApi :<|>
49 "channels" :> ChannelsApi
50 "channels" :> ChannelsApi
50 )
51 )
@@ -58,6 +59,7 @@ mkServerAPI l =
58 authenticationAPI :<|> (\uId ->
59 authenticationAPI :<|> (\uId ->
59 return uId :<|>
60 return uId :<|>
60 maybeNotFound . runQnotFound . getUsers :<|>
61 maybeNotFound . runQnotFound . getUsers :<|>
62+ runQnotFound getAllUsers :<|>
61 postApi uId :<|>
63 postApi uId :<|>
62 channelsApi uId
64 channelsApi uId
63 )
65 )