From 824444244bafa5266d7ce0a59cc9b26089a57077 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 14 Oct 2023 17:25:48 +0800 Subject: [PATCH] feat: able to delete all disabled channels --- controller/channel.go | 4 ++-- model/channel.go | 5 +++++ router/api-router.go | 2 +- web/src/components/ChannelsTable.js | 10 +++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/controller/channel.go b/controller/channel.go index 41a5555..904abc2 100644 --- a/controller/channel.go +++ b/controller/channel.go @@ -127,8 +127,8 @@ func DeleteChannel(c *gin.Context) { return } -func DeleteManuallyDisabledChannel(c *gin.Context) { - rows, err := model.DeleteChannelByStatus(common.ChannelStatusManuallyDisabled) +func DeleteDisabledChannel(c *gin.Context) { + rows, err := model.DeleteDisabledChannel() if err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, diff --git a/model/channel.go b/model/channel.go index 36bb78a..091a0d7 100644 --- a/model/channel.go +++ b/model/channel.go @@ -181,3 +181,8 @@ func DeleteChannelByStatus(status int64) (int64, error) { result := DB.Where("status = ?", status).Delete(&Channel{}) return result.RowsAffected, result.Error } + +func DeleteDisabledChannel() (int64, error) { + result := DB.Where("status = ? or status = ?", common.ChannelStatusAutoDisabled, common.ChannelStatusManuallyDisabled).Delete(&Channel{}) + return result.RowsAffected, result.Error +} diff --git a/router/api-router.go b/router/api-router.go index 5ec385d..da3f9e6 100644 --- a/router/api-router.go +++ b/router/api-router.go @@ -74,7 +74,7 @@ func SetApiRouter(router *gin.Engine) { channelRoute.GET("/update_balance/:id", controller.UpdateChannelBalance) channelRoute.POST("/", controller.AddChannel) channelRoute.PUT("/", controller.UpdateChannel) - channelRoute.DELETE("/manually_disabled", controller.DeleteManuallyDisabledChannel) + channelRoute.DELETE("/disabled", controller.DeleteDisabledChannel) channelRoute.DELETE("/:id", controller.DeleteChannel) } tokenRoute := apiRouter.Group("/token") diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index b9eb3c0..732189c 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -240,11 +240,11 @@ const ChannelsTable = () => { } }; - const deleteAllManuallyDisabledChannels = async () => { - const res = await API.delete(`/api/channel/manually_disabled`); + const deleteAllDisabledChannels = async () => { + const res = await API.delete(`/api/channel/disabled`); const { success, message, data } = res.data; if (success) { - showSuccess(`已删除所有手动禁用渠道,共计 ${data} 个`); + showSuccess(`已删除所有禁用渠道,共计 ${data} 个`); await refresh(); } else { showError(message); @@ -531,14 +531,14 @@ const ChannelsTable = () => { - 删除所有手动禁用渠道 + 删除禁用渠道 } on='click' flowing hoverable > -