package api import ( "assetcenter/db/model" "assetcenter/db/repo" "time" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) // 注册设计相关接口 func CreateDatabaseDesignSceneRouter(router *GinRouter) { //项目场景列表管理 CreateArrayCRUD(router, "/design/scene", &ArrayCRUDOption{ Collection: repo.CollectionDesigns, NeedsUpdate: true, NeedsRemove: true, NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) { prod := model.ProductHeader{} c.ShouldBindJSON(&prod) sceneProd := &model.SceneProduct{ Id: prod.Id, // Name: prod.Name, // Type: "product", Locked: false, Visible: true, Transform: &model.Transform{ Pos: model.Vect3{0, 0, 0}, Scale: model.Vect3{1, 1, 1}, Rot: model.Vect3{0, 0, 0}, }, } scene := &model.DesignScene{ Id: primitive.NewObjectID().Hex(), Name: prod.Name, Thumbnail: prod.Thumbnail, CreateTime: time.Now(), Product: []*model.SceneProduct{sceneProd}, } return scene, nil }, EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} { return &model.DesignScene{} }, ArrayFieldPath: "scenes", SearchProject: []string{"name", "id", "thumbnail", "createTime"}, }) router.POSTJWT("/design/create/scene/:id", func(c *gin.Context, apictx *ApiSession) (interface{}, error) { projId := c.Param("id") scene := &model.DesignScene{} c.ShouldBindJSON(scene) if len(scene.Name) < 1 { return nil, NewError("场景名称不能为空!") } scene.Id = primitive.NewObjectID().Hex() scene.CreateTime = time.Now() scene.Product = []*model.SceneProduct{} ret, _ := repo.RepoDocArrayAppend(apictx.CreateRepoCtx(), repo.CollectionDesigns, projId, "scenes", scene) if ret.ModifiedCount == 1 { return scene, nil } return nil, NewError("创建失败!") }) }