feat:完善网站信息,增加创新服务数据模型
This commit is contained in:
26
app/api/website/api/about.go
Normal file
26
app/api/website/api/about.go
Normal file
@ -0,0 +1,26 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/controller"
|
||||
"SciencesServer/app/basic/api"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type About struct{}
|
||||
|
||||
func (*About) Instance(c *gin.Context) {
|
||||
form := &struct {
|
||||
NavigationID string `json:"navigation_id" form:"navigation_id"`
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewAbout()().Instance((&api.IDStringForm{ID: form.NavigationID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*About) Navigation(c *gin.Context) {
|
||||
data, err := controller.NewAbout()().Navigation()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
66
app/api/website/controller/about.go
Normal file
66
app/api/website/controller/about.go
Normal file
@ -0,0 +1,66 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type About struct{}
|
||||
|
||||
type AboutHandle func() *About
|
||||
|
||||
type (
|
||||
// AboutInfo 基本信息
|
||||
AboutInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
// AboutNavigationInfo 导航栏信息
|
||||
AboutNavigationInfo struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 关于信息
|
||||
func (c *About) Instance(parentID uint64) (*AboutInfo, error) {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
|
||||
if isExist, err := model2.FirstField(mSysAbout.SysAbout, []string{"id", "title", "content"},
|
||||
model2.NewWhere("parent_id", parentID)); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
return &AboutInfo{ID: mSysAbout.GetEncodeID(), Title: mSysAbout.Title, Content: mSysAbout.Content}, nil
|
||||
}
|
||||
|
||||
// Navigation 导航栏
|
||||
func (c *About) Navigation() ([]*AboutNavigationInfo, error) {
|
||||
mSysAbout := model.NewSysAbout()
|
||||
out := make([]*model2.SysAbout, 0)
|
||||
|
||||
if err := model2.ScanFields(mSysAbout.SysAbout, &out, []string{"id", "title"}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("parent_id", 0),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*AboutNavigationInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &AboutNavigationInfo{
|
||||
ID: v.GetEncodeID(), Title: v.Title,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func NewAbout() AboutHandle {
|
||||
return func() *About {
|
||||
return &About{}
|
||||
}
|
||||
}
|
11
app/api/website/model/sys_about.go
Normal file
11
app/api/website/model/sys_about.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type SysAbout struct {
|
||||
*model.SysAbout
|
||||
}
|
||||
|
||||
func NewSysAbout() *SysAbout {
|
||||
return &SysAbout{model.NewSysAbout()}
|
||||
}
|
Reference in New Issue
Block a user