🎨后台接口终于磨磨蹭蹭的写完了
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()
|
||||
}
|
@@ -7,3 +7,24 @@ type SaveNavigationType struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Icon string `json:"icon" form:"icon" binding:"required"`
|
||||
}
|
||||
|
||||
// NavigationList
|
||||
// @description: 导航分页列表查询
|
||||
type NavigationList struct {
|
||||
Type string `json:"type" form:"type" binding:"omitempty"`
|
||||
Title string `json:"title" form:"title" binding:"omitempty"`
|
||||
Link string `json:"link" form:"link" binding:"omitempty"`
|
||||
Page
|
||||
}
|
||||
|
||||
// SaveNavigation
|
||||
// @description: 新增/编辑导航
|
||||
type SaveNavigation struct {
|
||||
Id string `json:"id" form:"id" binding:"omitempty"`
|
||||
TypeId string `json:"typeId" form:"typeId" binding:"required"`
|
||||
Title string `json:"title" form:"title" binding:"required"`
|
||||
Url string `json:"url" form:"url" binding:"required"`
|
||||
Icon string `json:"icon" form:"icon" binding:"omitempty"`
|
||||
Enabled int `json:"enabled" form:"enabled" binding:"required,oneof=0 1"`
|
||||
Description string `json:"description" form:"description" binding:"omitempty"`
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ func adminAPI(r *gin.RouterGroup) {
|
||||
loginAPI(adminApi)
|
||||
userAPI(adminApi)
|
||||
navTypeAPI(adminApi)
|
||||
navigation(adminApi)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,3 +56,16 @@ func navTypeAPI(r *gin.RouterGroup) {
|
||||
navType.DELETE("/:id", admin.NavigationTypeAPI().Delete) // 删除分类
|
||||
}
|
||||
}
|
||||
|
||||
// navigation
|
||||
// @description: 导航相关API
|
||||
// @param r
|
||||
func navigation(r *gin.RouterGroup) {
|
||||
nav := r.Group("/navigation")
|
||||
nav.Use(middleware.Authorization())
|
||||
{
|
||||
nav.GET("/list", admin.NavigationAPI().List) // 导航列表
|
||||
nav.POST("/save", admin.NavigationAPI().Save) // 新增/编辑导航
|
||||
nav.DELETE("/:id", admin.NavigationAPI().Delete) // 删除导航
|
||||
}
|
||||
}
|
||||
|
@@ -11,3 +11,18 @@ type NavigationTypeItem struct {
|
||||
CreatedAt model.JsonTime `json:"createdAt"`
|
||||
UpdatedAt model.JsonTime `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// NavigationItem
|
||||
// @description: 导航
|
||||
type NavigationItem struct {
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
TypeId string `json:"typeId"`
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
Enabled bool `json:"enabled"`
|
||||
CreatedAt model.JsonTime `json:"createdAt"`
|
||||
UpdatedAt model.JsonTime `json:"updatedAt"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user