分类接口完成

This commit is contained in:
coward
2024-10-24 16:55:31 +08:00
parent f66fef2ce0
commit 980c81af11
5 changed files with 151 additions and 15 deletions

View File

@@ -0,0 +1,73 @@
package admin
import (
"errors"
"github.com/gin-gonic/gin"
"website-nav/http/param"
"website-nav/http/response"
"website-nav/service"
)
type NavigationType struct{}
func NavigationTypeAPI() NavigationType {
return NavigationType{}
}
// List
// @description: 分页列表
// @receiver NavigationType
// @param c
func (NavigationType) List(c *gin.Context) {
var p param.Page
if err := c.ShouldBind(&p); err != nil {
response.R(c).Validator(err)
return
}
data, total, err := service.NavigationType().List(p)
if err != nil {
response.R(c).FailedWithError(err)
return
}
response.R(c).Paginate(data, total, p.Current, p.Size)
}
// Save
// @description: 新增/保存分类
// @receiver NavigationType
// @param c
func (NavigationType) Save(c *gin.Context) {
var p param.SaveNavigationType
if err := c.ShouldBind(&p); err != nil {
response.R(c).Validator(err)
return
}
if err := service.NavigationType().CreateType(p); err != nil {
response.R(c).FailedWithError(err)
return
}
response.R(c).OK()
}
// Delete
// @description: 删除分类
// @receiver NavigationType
// @param c
func (NavigationType) Delete(c *gin.Context) {
var id = c.Param("id")
if id == "" || id == "undefined" {
response.R(c).Validator(errors.New("id不能为空"))
return
}
if err := service.NavigationType().Delete(id); err != nil {
response.R(c).FailedWithError(err)
return
}
response.R(c).OK()
}