feat:完善项目
This commit is contained in:
@ -1,26 +0,0 @@
|
||||
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)
|
||||
}
|
@ -18,7 +18,7 @@ func (*Activity) Instance(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewActivity()(getSession(c)).Instance(form.Title, form.Mode, form.Page, form.PageSize)
|
||||
data, err := controller.NewActivity()(getSession(c), api.GetTenantID()(c).(uint64)).Instance(form.Title, form.Mode, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ func (*Activity) Detail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := controller.NewActivity()(getSession(c)).Detail(form.Convert())
|
||||
data, err := controller.NewActivity()(getSession(c), api.GetTenantID()(c).(uint64)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -42,6 +42,6 @@ func (*Activity) Join(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := controller.NewActivity()(getSession(c)).Join(form.Convert())
|
||||
err := controller.NewActivity()(getSession(c), api.GetTenantID()(c).(uint64)).Join(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -15,12 +15,29 @@ func (*Sys) Platform(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (*Sys) Navigation(c *gin.Context) {
|
||||
data, err := controller.NewNavigation()().Instance()
|
||||
data, err := sys.NewNavigation()(api.GetTenantID()(c).(uint64)).Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) About(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 := sys.NewAbout()(api.GetTenantID()(c).(uint64)).Instance((&api.IDStringForm{ID: form.NavigationID}).Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) AboutNavigation(c *gin.Context) {
|
||||
data, err := sys.NewAbout()(api.GetTenantID()(c).(uint64)).Navigation()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Sys) Agreement(c *gin.Context) {
|
||||
data, err := sys.NewAgreement()(getSession(c), api.GetTenantID()(c).(uint64)).Instance()
|
||||
data, err := sys.NewAgreement()(api.GetTenantID()(c).(uint64)).Instance()
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
@ -31,6 +48,6 @@ func (*Sys) AgreementDetail(c *gin.Context) {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := sys.NewAgreement()(getSession(c), api.GetTenantID()(c).(uint64)).Detail(form.Convert())
|
||||
data, err := sys.NewAgreement()(api.GetTenantID()(c).(uint64)).Detail(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
@ -12,9 +12,10 @@ import (
|
||||
|
||||
type Activity struct {
|
||||
*session.Enterprise
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type ActivityHandle func(session *session.Enterprise) *Activity
|
||||
type ActivityHandle func(session *session.Enterprise, tenantID uint64) *Activity
|
||||
|
||||
type (
|
||||
// ActivityInfo 活动信息
|
||||
@ -37,7 +38,7 @@ func (c *Activity) Instance(title string, mode, page, pageSize int) (*controller
|
||||
|
||||
var count int64
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
where := []*model2.ModelWhere{model2.NewWhere("a.tenant_id", c.tenantID)}
|
||||
|
||||
if title != "" {
|
||||
where = append(where, model2.NewWhereLike("a.title", title))
|
||||
@ -82,7 +83,7 @@ func (c *Activity) Join(id uint64) error {
|
||||
mActivityInstance := model.NewActivityInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mActivityInstance.ActivityInstance, []string{"id", "mode", "join_deadline"},
|
||||
model2.NewWhere("status", model2.NewWhere("id", id)),
|
||||
model2.NewWhere("id", id), model2.NewWhere("tenant_id", c.tenantID),
|
||||
model2.NewWhere("status", model2.ActivityInstanceStatusForShow))
|
||||
|
||||
if err != nil {
|
||||
@ -115,7 +116,7 @@ func (c *Activity) Join(id uint64) error {
|
||||
}
|
||||
|
||||
func NewActivity() ActivityHandle {
|
||||
return func(session *session.Enterprise) *Activity {
|
||||
return &Activity{session}
|
||||
return func(session *session.Enterprise, tenantID uint64) *Activity {
|
||||
return &Activity{Enterprise: session, tenantID: tenantID}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package controller
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type About struct{}
|
||||
type About struct {
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type AboutHandle func() *About
|
||||
type AboutHandle func(tenantID uint64) *About
|
||||
|
||||
type (
|
||||
// AboutInfo 基本信息
|
||||
@ -45,6 +47,7 @@ func (c *About) Navigation() ([]*AboutNavigationInfo, error) {
|
||||
Where: model2.NewWhere("parent_id", 0),
|
||||
Order: model2.NewOrder("sort", model2.OrderModeToDesc),
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.tenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@ -60,7 +63,7 @@ func (c *About) Navigation() ([]*AboutNavigationInfo, error) {
|
||||
}
|
||||
|
||||
func NewAbout() AboutHandle {
|
||||
return func() *About {
|
||||
return &About{}
|
||||
return func(tenantID uint64) *About {
|
||||
return &About{tenantID: tenantID}
|
||||
}
|
||||
}
|
@ -3,17 +3,15 @@ package sys
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Agreement 协议信息
|
||||
type Agreement struct {
|
||||
*session.Enterprise
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type AgreementHandle func(session *session.Enterprise, tenantID uint64) *Agreement
|
||||
type AgreementHandle func(tenantID uint64) *Agreement
|
||||
|
||||
type (
|
||||
// AgreementInfo 协议信息
|
||||
@ -68,10 +66,9 @@ func (c *Agreement) Detail(id uint64) (*AgreementDetailInfo, error) {
|
||||
}
|
||||
|
||||
func NewAgreement() AgreementHandle {
|
||||
return func(session *session.Enterprise, tenantID uint64) *Agreement {
|
||||
return func(tenantID uint64) *Agreement {
|
||||
return &Agreement{
|
||||
Enterprise: session,
|
||||
tenantID: tenantID,
|
||||
tenantID: tenantID,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,15 @@
|
||||
package controller
|
||||
package sys
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/website/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
)
|
||||
|
||||
type Navigation struct{}
|
||||
type Navigation struct {
|
||||
tenantID uint64
|
||||
}
|
||||
|
||||
type NavigationHandle func() *Navigation
|
||||
type NavigationHandle func(tenantID uint64) *Navigation
|
||||
|
||||
type NavigationInfo struct {
|
||||
Title string `json:"title"`
|
||||
@ -36,7 +38,7 @@ func (c *Navigation) tree(src []*model2.SysNavigation, parentID uint64) []*Navig
|
||||
// Instance 导航栏信息
|
||||
func (c *Navigation) Instance() ([]*NavigationInfo, error) {
|
||||
mSysNavigation := model.NewSysNavigation()
|
||||
out, err := mSysNavigation.Navigation()
|
||||
out, err := mSysNavigation.Navigation(model2.NewWhere("tenant_id", c.tenantID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -45,7 +47,7 @@ func (c *Navigation) Instance() ([]*NavigationInfo, error) {
|
||||
}
|
||||
|
||||
func NewNavigation() NavigationHandle {
|
||||
return func() *Navigation {
|
||||
return &Navigation{}
|
||||
return func(tenantID uint64) *Navigation {
|
||||
return &Navigation{tenantID: tenantID}
|
||||
}
|
||||
}
|
@ -10,15 +10,20 @@ type SysNavigation struct {
|
||||
}
|
||||
|
||||
// Navigation 导航信息
|
||||
func (m *SysNavigation) Navigation() ([]*model.SysNavigation, error) {
|
||||
func (m *SysNavigation) Navigation(where ...*model.ModelWhere) ([]*model.SysNavigation, error) {
|
||||
out := make([]*model.SysNavigation, 0)
|
||||
|
||||
err := orm.GetDB().Table(m.TableName()).
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Select("id", "parent_id", "title", "link").
|
||||
Where("status = ?", model.SysNavigationStatusForShow).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot).
|
||||
Order("sort " + model.OrderModeToDesc).
|
||||
Scan(&out).Error
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
err := db.Order("sort " + model.OrderModeToDesc).Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ func (this *Instance) Handle() {
|
||||
}
|
||||
return out
|
||||
}},
|
||||
&synchronized{iModel: model.NewSysNavigation()},
|
||||
&synchronized{iModel: model.NewSysNavigation()}, &synchronized{iModel: model.NewSysAbout()},
|
||||
&synchronized{iModel: model.NewSysBanner()}, &synchronized{iModel: model.NewSysAgreement()},
|
||||
// 日志管理
|
||||
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
||||
|
@ -65,6 +65,8 @@ func registerAPI(app *gin.Engine) {
|
||||
sysV1.GET("/navigation", _api.Navigation)
|
||||
sysV1.GET("/agreement", _api.Agreement)
|
||||
sysV1.GET("/agreement/detail", _api.AgreementDetail)
|
||||
sysV1.POST("/about", _api.About)
|
||||
sysV1.GET("/about/navigation", _api.AboutNavigation)
|
||||
}
|
||||
// Docking 对接信息管理
|
||||
dockingV1 := v1.Group("/docking")
|
||||
@ -123,13 +125,6 @@ func registerAPI(app *gin.Engine) {
|
||||
technologyV1.POST("/achievement", _api.Achievement)
|
||||
technologyV1.POST("/achievement/detail", _api.AchievementDetail)
|
||||
}
|
||||
// About 关于我们管理
|
||||
aboutV1 := v1.Group("/about")
|
||||
{
|
||||
_api := new(api2.About)
|
||||
aboutV1.POST("", _api.Instance)
|
||||
aboutV1.GET("/navigation", _api.Navigation)
|
||||
}
|
||||
}
|
||||
|
||||
// registerAdminAPI 注册API
|
||||
|
Reference in New Issue
Block a user