🎨后台接口终于磨磨蹭蹭的写完了
This commit is contained in:
71
http/api/admin/navigation.go
Normal file
71
http/api/admin/navigation.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"website-nav/http/param"
|
||||
"website-nav/http/response"
|
||||
"website-nav/service"
|
||||
)
|
||||
|
||||
type Navigation struct{}
|
||||
|
||||
func NavigationAPI() Navigation {
|
||||
return Navigation{}
|
||||
}
|
||||
|
||||
// List
|
||||
// @description: 分页列表
|
||||
// @receiver Navigation
|
||||
// @param c
|
||||
func (Navigation) List(c *gin.Context) {
|
||||
var p param.NavigationList
|
||||
if err := c.ShouldBind(&p); err != nil {
|
||||
response.R(c).Validator(err)
|
||||
return
|
||||
}
|
||||
|
||||
data, total, err := service.Navigation().List(p)
|
||||
if err != nil {
|
||||
response.R(c).FailedWithError(err)
|
||||
return
|
||||
}
|
||||
response.R(c).Paginate(data, total, p.Current, p.Size)
|
||||
}
|
||||
|
||||
// Save
|
||||
// @description: 新增/编辑
|
||||
// @receiver Navigation
|
||||
// @param c
|
||||
func (Navigation) Save(c *gin.Context) {
|
||||
var p param.SaveNavigation
|
||||
if err := c.ShouldBind(&p); err != nil {
|
||||
response.R(c).Validator(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.Navigation().SaveNavigation(p); err != nil {
|
||||
response.R(c).FailedWithError(err)
|
||||
return
|
||||
}
|
||||
|
||||
response.R(c).OK()
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @description: 删除
|
||||
// @receiver Navigation
|
||||
// @param c
|
||||
func (Navigation) Delete(c *gin.Context) {
|
||||
var id = c.Param("id")
|
||||
if id == "" || id == "undefined" {
|
||||
response.R(c).Validator(errors.New("id不能为空"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := service.Navigation().DeleteNavigation(id); err != nil {
|
||||
response.R(c).FailedWithError(err)
|
||||
return
|
||||
}
|
||||
response.R(c).OK()
|
||||
}
|
Reference in New Issue
Block a user