132 lines
3.5 KiB
Go
132 lines
3.5 KiB
Go
package app
|
|
|
|
import (
|
|
"git.echol.cn/loser/ai_proxy/server/global"
|
|
"git.echol.cn/loser/ai_proxy/server/model/app/request"
|
|
"git.echol.cn/loser/ai_proxy/server/model/common/response"
|
|
"git.echol.cn/loser/ai_proxy/server/service"
|
|
"git.echol.cn/loser/ai_proxy/server/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type PresetBindingApi struct{}
|
|
|
|
var presetBindingService = service.ServiceGroupApp.AppServiceGroup.PresetBindingService
|
|
|
|
// CreateBinding 创建预设绑定
|
|
// @Tags App
|
|
// @Summary 创建预设绑定
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.CreateBindingRequest true "绑定信息"
|
|
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
|
// @Router /app/binding [post]
|
|
func (a *PresetBindingApi) CreateBinding(c *gin.Context) {
|
|
var req request.CreateBindingRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
err := presetBindingService.CreateBinding(&req)
|
|
if err != nil {
|
|
global.GVA_LOG.Error("创建绑定失败!", zap.Error(err))
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMessage("创建成功", c)
|
|
}
|
|
|
|
// UpdateBinding 更新预设绑定
|
|
// @Tags App
|
|
// @Summary 更新预设绑定
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.UpdateBindingRequest true "绑定信息"
|
|
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
|
// @Router /app/binding [put]
|
|
func (a *PresetBindingApi) UpdateBinding(c *gin.Context) {
|
|
var req request.UpdateBindingRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
err := presetBindingService.UpdateBinding(&req)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMessage("更新成功", c)
|
|
}
|
|
|
|
// DeleteBinding 删除预设绑定
|
|
// @Tags App
|
|
// @Summary 删除预设绑定
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param id path uint true "绑定ID"
|
|
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
|
// @Router /app/binding/:id [delete]
|
|
func (a *PresetBindingApi) DeleteBinding(c *gin.Context) {
|
|
id, err := utils.StringToUint(c.Param("id"))
|
|
if err != nil {
|
|
response.FailWithMessage("无效的ID", c)
|
|
return
|
|
}
|
|
|
|
err = presetBindingService.DeleteBinding(id)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMessage("删除成功", c)
|
|
}
|
|
|
|
// GetBindingList 获取绑定列表
|
|
// @Tags App
|
|
// @Summary 获取绑定列表
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param page query int false "页码"
|
|
// @Param pageSize query int false "每页数量"
|
|
// @Param providerId query uint false "提供商ID"
|
|
// @Param presetId query uint false "预设ID"
|
|
// @Success 200 {object} response.Response{data=response.PageResult} "获取成功"
|
|
// @Router /app/binding/list [get]
|
|
func (a *PresetBindingApi) GetBindingList(c *gin.Context) {
|
|
var req request.GetBindingListRequest
|
|
if err := c.ShouldBindQuery(&req); err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if req.Page == 0 {
|
|
req.Page = 1
|
|
}
|
|
if req.PageSize == 0 {
|
|
req.PageSize = 10
|
|
}
|
|
|
|
list, total, err := presetBindingService.GetBindingList(&req)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithDetailed(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Page,
|
|
PageSize: req.PageSize,
|
|
}, "获取成功", c)
|
|
}
|