on master help sign in
Added channel deletion.
commitd21bd84734baf88a7ab51811aa2386d471abbea4 authoriko <ilyakooo0@gmail.com> dateWed 13 Mar 2019, 00:27 (8 years ago) parent9451b5f
2 files changed+19−3
denis/src/Data/Query.hs+11−1 denis/src/Server/API/Channels.hs+8−2
denis/src/Data/Query.hs+11−1
@@ -25,7 +25,8 @@ module Data.Query (
2525 updateChannel,
2626 createNewChannel,
2727 getAllChannels,
28− getAnonymousChannelPosts
28+ getAnonymousChannelPosts,
29+ deleteNamedChannel
2930) where
3031
3132import Squeal.PostgreSQL
@@ -183,6 +184,9 @@ createNamedChannelQ = insertRow #channels
183184 OnConflictDoRaise
184185 (Returning $ #namedChannelFullId `as` #fromOnly)
185186
187+deleteNamedChannelQ :: Manipulation Schema (TuplePG (Only NamedChannelId)) '[]
188+deleteNamedChannelQ = deleteFrom_ #channels (#namedChannelFullId .== param @1)
189+
186190updateNamedChannelQ :: Manipulation Schema (TuplePG NamedChannelFull) '[]
187191updateNamedChannelQ = update_ #channels
188192 (
@@ -318,6 +322,12 @@ getAllChannels :: UserId -> StaticPQ [NamedChannel UserId]
318322getAllChannels uId = fmap (map removeUserFromChannel) $
319323 runQueryParams getAllChannelsForUserQ (Only uId) >>= getRows
320324
325+deleteNamedChannel :: UserId -> NamedChannelId -> StaticPQ ()
326+deleteNamedChannel uId cId = transactionally_ $ do
327+ _ <- getChannelForUser uId cId
328+ _ <- manipulateParams deleteNamedChannelQ (Only cId)
329+ return ()
330+
321331
322332-- MARK: Utils
323333
denis/src/Server/API/Channels.hs+8−2
@@ -33,10 +33,11 @@ type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
3333 "get" :> ReqBody '[JSON] NamedChannelRequest :> Post '[JSON] PostResponse :<|>
3434 "getAnonymous" :> ReqBody '[JSON] (LimitingRequest AnonymousChannel) :> Post '[JSON] PostResponse :<|>
3535 "create" :> ReqBody '[JSON] NamedChannelCreationRequest :> Post '[JSON] NamedChannelId :<|>
36− "update" :> ReqBody '[JSON] (NamedChannel UserId) :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent
36+ "update" :> ReqBody '[JSON] (NamedChannel UserId) :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent :<|>
37+ "delete" :> ReqBody '[JSON] NamedChannelId :> PostNoContent '[JSON, FormUrlEncoded, PlainText] NoContent
3738
3839channelsApi :: UserId -> ServerT ChannelsApi App
39−channelsApi uId = getChannelsApi uId :<|> getChannel uId :<|> getAnonymousChannelsApi :<|> createChannelApi uId :<|> updateChannelApi uId
40+channelsApi uId = getChannelsApi uId :<|> getChannel uId :<|> getAnonymousChannelsApi :<|> createChannelApi uId :<|> updateChannelApi uId :<|> deleteChannelApi uId
4041
4142
4243getChannelsApi :: UserId -> App [NamedChannel UserId]
@@ -54,4 +55,9 @@ createChannelApi uId req = maybeNotFound . runQnotFound $ createNewChannel uId r
5455updateChannelApi :: UserId -> NamedChannel UserId -> App NoContent
5556updateChannelApi uId req = do
5657 runQnotFound $ updateChannel uId req
58+ return NoContent
59+
60+deleteChannelApi :: UserId -> NamedChannelId -> App NoContent
61+deleteChannelApi uId cId = do
62+ runQnotFound $ deleteNamedChannel uId cId
5763 return NoContent