[go: up one dir, main page]

Skip to content

Commit

Permalink
feat: able to delete all disabled channels
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Oct 14, 2023
1 parent fbe9985 commit 8244442
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions controller/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions model/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion router/api-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions web/src/components/ChannelsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -531,14 +531,14 @@ const ChannelsTable = () => {
<Popup
trigger={
<Button size='small' loading={loading}>
删除所有手动禁用渠道
删除禁用渠道
</Button>
}
on='click'
flowing
hoverable
>
<Button size='small' loading={loading} negative onClick={deleteAllManuallyDisabledChannels}>
<Button size='small' loading={loading} negative onClick={deleteAllDisabledChannels}>
确认删除
</Button>
</Popup>
Expand Down

0 comments on commit 8244442

Please sign in to comment.