⚡分类接口完成
This commit is contained in:
73
http/api/admin/navigation_type.go
Normal file
73
http/api/admin/navigation_type.go
Normal 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()
|
||||
}
|
9
http/param/navigation.go
Normal file
9
http/param/navigation.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package param
|
||||
|
||||
// SaveNavigationType
|
||||
// @description: 新增/编辑导航分类
|
||||
type SaveNavigationType struct {
|
||||
Id string `json:"id" form:"id" binding:"omitempty"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Icon string `json:"icon" form:"icon" binding:"required"`
|
||||
}
|
@@ -47,5 +47,11 @@ func userAPI(r *gin.RouterGroup) {
|
||||
// @description: 导航分类API
|
||||
// @param r
|
||||
func navTypeAPI(r *gin.RouterGroup) {
|
||||
|
||||
navType := r.Group("/nav-type")
|
||||
navType.Use(middleware.Authorization())
|
||||
{
|
||||
navType.GET("/list", admin.NavigationTypeAPI().List) // 分类列表
|
||||
navType.POST("/save", admin.NavigationTypeAPI().Save) // 新增/编辑分类
|
||||
navType.DELETE("/:id", admin.NavigationTypeAPI().Delete) // 删除分类
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,13 @@
|
||||
package vo
|
||||
|
||||
// TypeItem
|
||||
// @description: 导航分类
|
||||
type TypeItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
import "website-nav/model"
|
||||
|
||||
type NavigationItem struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Url string `json:"url"`
|
||||
Icon string `json:"icon"`
|
||||
Desc string `json:"desc"`
|
||||
Enabled bool `json:"enabled"`
|
||||
// NavigationTypeItem
|
||||
// @description: 导航分类
|
||||
type NavigationTypeItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
CreatedAt model.JsonTime `json:"createdAt"`
|
||||
UpdatedAt model.JsonTime `json:"updatedAt"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user