🎨 新增域名管理功能
This commit is contained in:
105
api/v1/app/domain.go
Normal file
105
api/v1/app/domain.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/app"
|
||||
"git.echol.cn/loser/lckt/model/app/request"
|
||||
r "git.echol.cn/loser/lckt/model/common/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type DomainApi struct{}
|
||||
|
||||
// Create 创建域名
|
||||
func (d *DomainApi) Create(ctx *gin.Context) {
|
||||
var p app.Domain
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("新建域名参数有误", zap.Error(err))
|
||||
r.FailWithMessage("参数有误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
err := domainService.Create(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("创建域名失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithMessage("创建域名成功", ctx)
|
||||
|
||||
}
|
||||
|
||||
// GetList 获取域名列表
|
||||
func (d *DomainApi) GetList(ctx *gin.Context) {
|
||||
var p request.GetDomainList
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("获取域名列表参数有误", zap.Error(err))
|
||||
r.FailWithMessage("参数有误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := domainService.GetList(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取域名列表失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithDetailed(r.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: p.Page,
|
||||
PageSize: p.PageSize,
|
||||
}, "获取域名列表成功", ctx)
|
||||
}
|
||||
|
||||
// Update 更新域名
|
||||
func (d *DomainApi) Update(ctx *gin.Context) {
|
||||
var p app.Domain
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("更新域名参数有误", zap.Error(err))
|
||||
r.FailWithMessage("参数有误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
err := domainService.Update(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("更新域名失败", ctx)
|
||||
return
|
||||
}
|
||||
r.OkWithMessage("更新域名成功", ctx)
|
||||
}
|
||||
|
||||
// Delete 删除域名
|
||||
func (d *DomainApi) Delete(ctx *gin.Context) {
|
||||
var p app.Domain
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("删除域名参数有误", zap.Error(err))
|
||||
r.FailWithMessage("参数有误", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
err := domainService.Delete(p.ID)
|
||||
if err != nil {
|
||||
r.FailWithMessage("删除域名失败", ctx)
|
||||
return
|
||||
}
|
||||
r.OkWithMessage("删除域名成功", ctx)
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取域名
|
||||
func (d *DomainApi) GetByID(ctx *gin.Context) {
|
||||
id := ctx.Param("id")
|
||||
if id == "" {
|
||||
global.GVA_LOG.Error("获取域名详情参数错误: ID不能为空")
|
||||
r.FailWithMessage("获取域名详情参数错误: ID不能为空", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
domain, err := domainService.GetByID(id)
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取域名失败", ctx)
|
||||
return
|
||||
}
|
||||
r.OkWithDetailed(domain, "获取域名成功", ctx)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ type ApiGroup struct {
|
||||
TeacherVip
|
||||
RedeemCodeApi
|
||||
WithApi
|
||||
DomainApi
|
||||
}
|
||||
|
||||
var userService = service.ServiceGroupApp.UserServiceGroup.UserService
|
||||
@@ -18,3 +19,4 @@ var orderService = service.ServiceGroupApp.AppServiceGroup.OrderService
|
||||
var teacherVipService = service.ServiceGroupApp.AppServiceGroup.TeacherVipService
|
||||
var redeemCodeService = service.ServiceGroupApp.AppServiceGroup.RedeemCodeService
|
||||
var withService = service.ServiceGroupApp.AppServiceGroup.WithService
|
||||
var domainService = service.ServiceGroupApp.AppServiceGroup.DomainService
|
||||
|
||||
Reference in New Issue
Block a user