on master help sign in
Resolved #86
commit70b987af6deb340f6c9e8037cae35689ff6d08ce authoriko <ilyakooo0@gmail.com> dateSun 12 May 2019, 20:01 (7 years ago) parenta8b2e57
2 files changed+32−3
denis/src/Data/Query.hs+23−1 denis/src/Server/API/Channels.hs+9−2
denis/src/Data/Query.hs+23−1
@@ -62,7 +62,8 @@ module Data.Query (
6262 UserUpdateRow(..),
6363 killAllTokens,
6464 channelCountForUser,
65− pruneAuth
65+ pruneAuth,
66+ searchChannels
6667 ) where
6768
6869import Squeal.PostgreSQL
@@ -309,6 +310,23 @@ getAllChannelsForUserQ = selectStar $
309310 where_ (#namedChannelFullOwner .== param @1) &
310311 orderBy [#namedChannelFullId & Desc]
311312
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+
312330updateFacultyQ :: Manipulation Schema (TuplePG Faculty) '[]
313331updateFacultyQ = insertRow #faculties
314332 (
@@ -1071,6 +1089,10 @@ pruneAuth = do
10711089 _ <- commitedTransactionallyUpdate . manipulate $ pruneGhostUsersQ
10721090 return ()
10731091
1092+searchChannels :: UserId -> Text -> StaticPQ [NamedChannel UserId]
1093+searchChannels uId query = fmap (map removeUserFromChannel) $
1094+ runQueryParams searchChannelsForUserQ (uId, queryFromText query) >>= getRows
1095+
10741096-- NOTE: Not transactional
10751097validateToken :: Token -> StaticPQ ()
10761098validateToken token = do
denis/src/Server/API/Channels.hs+9−2
@@ -23,9 +23,12 @@ import qualified Data.Post as P
2323import Server.Query.Pagination
2424import Data.Int
2525import Server.Error
26+import Data.Text (Text)
2627
2728type CreateDescription = Description "Creates a new channel\n\nReturns 406 if the channel limit has been exceeded."
2829
30+type SearchDescription = Description "Search for user channels."
31+
2932-- MARK: Implementation
3033
3134type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
@@ -33,10 +36,11 @@ type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
3336 "getAnonymous" :> ReqBody '[JSON] (PaginatingRequest P.PostId (Maybe AnonymousChannel)) :> Post '[JSON] (ResponseWithUsers [P.Post]) :<|>
3437 "create" :> CreateDescription :> ReqBody '[JSON] NamedChannelCreationRequest :> Post '[JSON] NamedChannelId :<|>
3538 "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]
3741
3842channelsApi :: 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
4044
4145
4246getChannelsApi :: UserId -> App [NamedChannel UserId]
@@ -67,6 +71,9 @@ deleteChannelApi uId cId = do
6771 runQnotFound $ deleteNamedChannel uId cId
6872 return NoContent
6973
74+searchChannelsApi :: UserId -> Text -> App [NamedChannel UserId]
75+searchChannelsApi uId = runQerror . searchChannels uId
76+
7077-- TODO: Increase
7178channelCountLimit :: Int64
7279channelCountLimit = 5