on master help sign in
Resolved #86
70b987aiko
denis/src/Data/Query.hs+23−1
@@ -62,7 +62,8 @@ module Data.Query (
62 UserUpdateRow(..),
62 UserUpdateRow(..),
63 killAllTokens,
63 killAllTokens,
64 channelCountForUser,
64 channelCountForUser,
65− pruneAuth
65+ pruneAuth,
66+ searchChannels
66 ) where
67 ) where
67
68
68import Squeal.PostgreSQL
69import Squeal.PostgreSQL
@@ -309,6 +310,23 @@ getAllChannelsForUserQ = selectStar $
309 where_ (#namedChannelFullOwner .== param @1) &
310 where_ (#namedChannelFullOwner .== param @1) &
310 orderBy [#namedChannelFullId & Desc]
311 orderBy [#namedChannelFullId & Desc]
311
312
313+searchChannelsForUserQ :: Query Schema (TuplePG (UserId, Text)) (RowPG NamedChannelFull)
314+searchChannelsForUserQ = selectStar $
315+ from (table #channels) &
316+ where_ (#namedChannelFullOwner .== param @1 .&&
317+ vector @@ query) &
318+ orderBy [
319+ tsRankCd vector1 query & Desc,
320+ tsRankCd vector query & Desc
321+ ]
322+ where
323+ vector = tsVector' (textArrayToText [
324+ #namedChannelFullName,
325+ unsafeFunction "unnest" #namedChannelFullTags
326+ ])
327+ vector1 = tsVector' #namedChannelFullName
328+ query = tsQuery' (param @2)
329+
312updateFacultyQ :: Manipulation Schema (TuplePG Faculty) '[]
330updateFacultyQ :: Manipulation Schema (TuplePG Faculty) '[]
313updateFacultyQ = insertRow #faculties
331updateFacultyQ = insertRow #faculties
314 (
332 (
@@ -1071,6 +1089,10 @@ pruneAuth = do
1071 _ <- commitedTransactionallyUpdate . manipulate $ pruneGhostUsersQ
1089 _ <- commitedTransactionallyUpdate . manipulate $ pruneGhostUsersQ
1072 return ()
1090 return ()
1073
1091
1092+searchChannels :: UserId -> Text -> StaticPQ [NamedChannel UserId]
1093+searchChannels uId query = fmap (map removeUserFromChannel) $
1094+ runQueryParams searchChannelsForUserQ (uId, queryFromText query) >>= getRows
1095+
1074-- NOTE: Not transactional
1096-- NOTE: Not transactional
1075validateToken :: Token -> StaticPQ ()
1097validateToken :: Token -> StaticPQ ()
1076validateToken token = do
1098validateToken token = do
denis/src/Server/API/Channels.hs+9−2
@@ -23,9 +23,12 @@ import qualified Data.Post as P
23import Server.Query.Pagination
23import Server.Query.Pagination
24import Data.Int
24import Data.Int
25import Server.Error
25import Server.Error
26+import Data.Text (Text)
26
27
27type CreateDescription = Description "Creates a new channel\n\nReturns 406 if the channel limit has been exceeded."
28type CreateDescription = Description "Creates a new channel\n\nReturns 406 if the channel limit has been exceeded."
28
29
30+type SearchDescription = Description "Search for user channels."
31+
29-- MARK: Implementation
32-- MARK: Implementation
30
33
31type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
34type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
@@ -33,10 +36,11 @@ type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
33 "getAnonymous" :> ReqBody '[JSON] (PaginatingRequest P.PostId (Maybe AnonymousChannel)) :> Post '[JSON] (ResponseWithUsers [P.Post]) :<|>
36 "getAnonymous" :> ReqBody '[JSON] (PaginatingRequest P.PostId (Maybe AnonymousChannel)) :> Post '[JSON] (ResponseWithUsers [P.Post]) :<|>
34 "create" :> CreateDescription :> ReqBody '[JSON] NamedChannelCreationRequest :> Post '[JSON] NamedChannelId :<|>
37 "create" :> CreateDescription :> ReqBody '[JSON] NamedChannelCreationRequest :> Post '[JSON] NamedChannelId :<|>
35 "update" :> ReqBody '[JSON] (NamedChannel UserId) :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent :<|>
38 "update" :> ReqBody '[JSON] (NamedChannel UserId) :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent :<|>
36− "delete" :> ReqBody '[JSON] NamedChannelId :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent
39+ "delete" :> ReqBody '[JSON] NamedChannelId :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent :<|>
40+ "search" :> SearchDescription :> ReqBody '[JSON, PlainText] Text :> Post '[JSON] [NamedChannel UserId]
37
41
38channelsApi :: UserId -> ServerT ChannelsApi App
42channelsApi :: UserId -> ServerT ChannelsApi App
39−channelsApi uId = getChannelsApi uId :<|> getChannel uId :<|> getAnonymousChannelsApi :<|> createChannelApi uId :<|> updateChannelApi uId :<|> deleteChannelApi uId
43+channelsApi uId = getChannelsApi uId :<|> getChannel uId :<|> getAnonymousChannelsApi :<|> createChannelApi uId :<|> updateChannelApi uId :<|> deleteChannelApi uId :<|> searchChannelsApi uId
40
44
41
45
42getChannelsApi :: UserId -> App [NamedChannel UserId]
46getChannelsApi :: UserId -> App [NamedChannel UserId]
@@ -67,6 +71,9 @@ deleteChannelApi uId cId = do
67 runQnotFound $ deleteNamedChannel uId cId
71 runQnotFound $ deleteNamedChannel uId cId
68 return NoContent
72 return NoContent
69
73
74+searchChannelsApi :: UserId -> Text -> App [NamedChannel UserId]
75+searchChannelsApi uId = runQerror . searchChannels uId
76+
70-- TODO: Increase
77-- TODO: Increase
71channelCountLimit :: Int64
78channelCountLimit :: Int64
72channelCountLimit = 5
79channelCountLimit = 5