diff --git a/api/admin/aiassistant/delete.go b/api/admin/aiassistant/delete.go new file mode 100644 index 0000000..4cd8910 --- /dev/null +++ b/api/admin/aiassistant/delete.go @@ -0,0 +1,25 @@ +package aiassistant + +import ( + "github.com/gin-gonic/gin" + "unicode/utf8" + "wechat-robot/pkg/response" + aiAssistantService "wechat-robot/service/aiassistant" +) + +// DeleteById +// @description: 删除AI助手 +// @param ctx +func DeleteById(ctx *gin.Context) { + var id = ctx.Param("id") + if utf8.RuneCountInString(id) != 32 { + response.New(ctx).SetMsg("参数错误").Fail() + return + } + // 删除数据 + if err := aiAssistantService.DeleteById(id); err != nil { + response.New(ctx).SetMsg("删除失败").SetError(err).Fail() + } else { + response.New(ctx).SetMsg("删除成功").Success() + } +} diff --git a/router/admin/aiassistant.go b/router/admin/aiassistant.go index e2df8a4..d5d5a94 100644 --- a/router/admin/aiassistant.go +++ b/router/admin/aiassistant.go @@ -9,6 +9,7 @@ import ( // @description: AI助手相关 // @param g func aiAssistant(g *gin.RouterGroup) { - g.POST("", aiassistantApi.Save) // 保存AI助手 - g.GET("", aiassistantApi.GetAll) // 获取所有AI助手 + g.POST("", aiassistantApi.Save) // 保存AI助手 + g.GET("", aiassistantApi.GetAll) // 获取所有AI助手 + g.DELETE("/:id", aiassistantApi.DeleteById) // 删除AI助手 } diff --git a/service/aiassistant/delete.go b/service/aiassistant/delete.go new file mode 100644 index 0000000..4231193 --- /dev/null +++ b/service/aiassistant/delete.go @@ -0,0 +1,16 @@ +package aiassistant + +import ( + "wechat-robot/internal/database" + "wechat-robot/model/entity" +) + +// DeleteById +// @description: 删除AI助手 +// @param id string id +// @return err error 错误 +func DeleteById(id string) (err error) { + // 删除数据 + err = database.Client.Where("id = ?", id).Delete(&entity.AiAssistant{}).Error + return +}