on master help sign in
Added channel deletion.
d21bd84iko
denis/src/Data/Query.hs+11−1
@@ -25,7 +25,8 @@ module Data.Query (
25 updateChannel,
25 updateChannel,
26 createNewChannel,
26 createNewChannel,
27 getAllChannels,
27 getAllChannels,
28− getAnonymousChannelPosts
28+ getAnonymousChannelPosts,
29+ deleteNamedChannel
29) where
30) where
30
31
31import Squeal.PostgreSQL
32import Squeal.PostgreSQL
@@ -183,6 +184,9 @@ createNamedChannelQ = insertRow #channels
183 OnConflictDoRaise
184 OnConflictDoRaise
184 (Returning $ #namedChannelFullId `as` #fromOnly)
185 (Returning $ #namedChannelFullId `as` #fromOnly)
185
186
187+deleteNamedChannelQ :: Manipulation Schema (TuplePG (Only NamedChannelId)) '[]
188+deleteNamedChannelQ = deleteFrom_ #channels (#namedChannelFullId .== param @1)
189+
186updateNamedChannelQ :: Manipulation Schema (TuplePG NamedChannelFull) '[]
190updateNamedChannelQ :: Manipulation Schema (TuplePG NamedChannelFull) '[]
187updateNamedChannelQ = update_ #channels
191updateNamedChannelQ = update_ #channels
188 (
192 (
@@ -318,6 +322,12 @@ getAllChannels :: UserId -> StaticPQ [NamedChannel UserId]
318getAllChannels uId = fmap (map removeUserFromChannel) $
322getAllChannels uId = fmap (map removeUserFromChannel) $
319 runQueryParams getAllChannelsForUserQ (Only uId) >>= getRows
323 runQueryParams getAllChannelsForUserQ (Only uId) >>= getRows
320
324
325+deleteNamedChannel :: UserId -> NamedChannelId -> StaticPQ ()
326+deleteNamedChannel uId cId = transactionally_ $ do
327+ _ <- getChannelForUser uId cId
328+ _ <- manipulateParams deleteNamedChannelQ (Only cId)
329+ return ()
330+
321
331
322-- MARK: Utils
332-- MARK: Utils
323
333
denis/src/Server/API/Channels.hs+8−2
@@ -33,10 +33,11 @@ type ChannelsApi = Post '[JSON] [NamedChannel UserId] :<|>
33 "get" :> ReqBody '[JSON] NamedChannelRequest :> Post '[JSON] PostResponse :<|>
33 "get" :> ReqBody '[JSON] NamedChannelRequest :> Post '[JSON] PostResponse :<|>
34 "getAnonymous" :> ReqBody '[JSON] (LimitingRequest AnonymousChannel) :> Post '[JSON] PostResponse :<|>
34 "getAnonymous" :> ReqBody '[JSON] (LimitingRequest AnonymousChannel) :> Post '[JSON] PostResponse :<|>
35 "create" :> ReqBody '[JSON] NamedChannelCreationRequest :> Post '[JSON] NamedChannelId :<|>
35 "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
37
38
38channelsApi :: UserId -> ServerT ChannelsApi App
39channelsApi :: 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
40
41
41
42
42getChannelsApi :: UserId -> App [NamedChannel UserId]
43getChannelsApi :: UserId -> App [NamedChannel UserId]
@@ -54,4 +55,9 @@ createChannelApi uId req = maybeNotFound . runQnotFound $ createNewChannel uId r
54updateChannelApi :: UserId -> NamedChannel UserId -> App NoContent
55updateChannelApi :: UserId -> NamedChannel UserId -> App NoContent
55updateChannelApi uId req = do
56updateChannelApi uId req = do
56 runQnotFound $ updateChannel uId req
57 runQnotFound $ updateChannel uId req
58+ return NoContent
59+
60+deleteChannelApi :: UserId -> NamedChannelId -> App NoContent
61+deleteChannelApi uId cId = do
62+ runQnotFound $ deleteNamedChannel uId cId
57 return NoContent
63 return NoContent