From 08821977b41a3113555a2c719cba3c57ebca290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Sat, 3 Feb 2024 15:58:18 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=AE=8C=E6=88=90=20AI=20?= =?UTF-8?q?=E5=8A=A9=E6=89=8B=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/admin/aiassistant/delete.go | 25 +++++++++++++++++++++++++ router/admin/aiassistant.go | 5 +++-- service/aiassistant/delete.go | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 api/admin/aiassistant/delete.go create mode 100644 service/aiassistant/delete.go diff --git a/api/admin/aiassistant/delete.go b/api/admin/aiassistant/delete.go new file mode 100644 index 00000000..4cd89102 --- /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 e2df8a41..d5d5a945 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 00000000..42311934 --- /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 +}