完成 AI 助手相关接口

This commit is contained in:
李寻欢 2024-02-03 15:58:18 +08:00
parent 9b3f1bb488
commit 08821977b4
3 changed files with 44 additions and 2 deletions

View File

@ -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()
}
}

View File

@ -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助手
}

View File

@ -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
}