ソースを参照

添加装饰、场景、纸张

funeralplay 2 ヶ月 前
コミット
ca7502ce25
6 ファイル変更322 行追加5 行削除
  1. 22 5
      src/api/category.go
  2. 98 0
      src/api/decorate.go
  3. 98 0
      src/api/paper.go
  4. 3 0
      src/api/router.go
  5. 98 0
      src/api/scene.go
  6. 3 0
      src/db/repo/repo.go

+ 22 - 5
src/api/category.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"errors"
+	"fmt"
 	"spu3d/db/repo"
 	"time"
 
@@ -11,6 +12,9 @@ import (
 )
 
 const BOXLIB_SCOPE = "boxlib"
+const DECORATE_SCOPE = "decorate"
+const PAPER_SCOPE = "paper"
+const SCENE_SCOPE = "scene"
 
 func GetSpu3dBoxLibCategory(apictx *ApiSession) (*comm.DbCategory, error) {
 	curr := &comm.DbCategory{}
@@ -24,17 +28,19 @@ func GetSpu3dBoxLibCategory(apictx *ApiSession) (*comm.DbCategory, error) {
 	return nil, err
 }
 
-func CreateCategoryRouter(router *GinRouter) {
-	router.GET("/spu3d/boxlib/category", func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func defGetCategory(router *GinRouter, path string, catType string) {
+	router.GET(fmt.Sprintf("/spu3d/%s/category", path), func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		_, ret := repo.RepoSeachDocMap(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
 			CollectName: repo.CollectionCategories,
-			Query:       repo.Map{"scope": BOXLIB_SCOPE},
+			Query:       repo.Map{"scope": catType},
 		})
 		return ret, nil
 	})
+}
 
+func defUpdateCategory(router *GinRouter, path string, catType string) {
 	// 创建/更新 spu3d资源分类
-	router.POST("/spu3d/boxlib/category", func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	router.POST(fmt.Sprintf("/spu3d/%s/category", path), func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		// roles, _ := getUserRole(c, apictx)
 		// // 公共分类 只有管理员能创建该分类
 		// if !isSysUser(roles) {
@@ -47,7 +53,7 @@ func CreateCategoryRouter(router *GinRouter) {
 			PrintErr(err, "参数错误")
 			return nil, errors.New("参数错误!")
 		}
-		body.Scope = BOXLIB_SCOPE
+		body.Scope = catType
 		body.CreateTime = time.Now()
 		if body.Id.IsZero() {
 			body.CreateTime = time.Now()
@@ -73,5 +79,16 @@ func CreateCategoryRouter(router *GinRouter) {
 		body.Id = primitive.NilObjectID
 		return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionCategories, curr.Id.Hex(), body)
 	})
+}
+
+func CreateCategoryRouter(r *GinRouter) {
+	defGetCategory(r, "boxlib", BOXLIB_SCOPE)
+	defGetCategory(r, "decorate", DECORATE_SCOPE)
+	defGetCategory(r, "paper", PAPER_SCOPE)
+	defGetCategory(r, "scene", SCENE_SCOPE)
 
+	defUpdateCategory(r, "boxlib", BOXLIB_SCOPE)
+	defUpdateCategory(r, "decorate", DECORATE_SCOPE)
+	defUpdateCategory(r, "paper", PAPER_SCOPE)
+	defUpdateCategory(r, "scene", SCENE_SCOPE)
 }

+ 98 - 0
src/api/decorate.go

@@ -0,0 +1,98 @@
+package api
+
+import (
+	"errors"
+	"spu3d/db/model"
+	"spu3d/db/repo"
+	"spu3d/log"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+func Decorate(r *GinRouter) {
+	r.POST("/decorate/create", CreateDecorate)
+	r.POST("/decorate/delete/:id", DeleteDecorate)
+	r.GET("/decorate/list", DecorateList)
+	r.GET("/decorate/detail/:id", DecorateDetail)
+	r.POST("/decorate/update", UpdateDecorate)
+}
+
+func CreateDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var data model.BoxLib
+	err := c.ShouldBindJSON(&data)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	data.CreateTime = time.Now()
+	data.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, &data)
+}
+
+func DeleteDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, _id)
+}
+
+func DecorateList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+
+	page, size, query := UtilQueryPageSize(c)
+	catsConf, err := GetSpu3dBoxLibCategory(apictx)
+	if err != nil {
+		return nil, err
+	}
+	err = ParseCategories(query, apictx.CreateRepoCtx(), catsConf)
+	if err != nil {
+		return nil, err
+	}
+
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionDecorate,
+		Page:        page,
+		Size:        size,
+		Query:       query,
+		Sort:        bson.M{"createTime": -1},
+	})
+}
+
+func DecorateDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	box := &model.BoxLib{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionDecorate,
+		Query:       repo.Map{"_id": id},
+	}, box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+
+	if !found {
+		return nil, errors.New("未找到该数据")
+	}
+	return box, nil
+}
+
+func UpdateDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var box model.BoxLib
+	err := c.ShouldBindJSON(&box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	if box.Id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, box.Id.Hex(), &box)
+}

+ 98 - 0
src/api/paper.go

@@ -0,0 +1,98 @@
+package api
+
+import (
+	"errors"
+	"spu3d/db/model"
+	"spu3d/db/repo"
+	"spu3d/log"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+func Paper(r *GinRouter) {
+	r.POST("/paper/create", CreatePaper)
+	r.POST("/paper/delete/:id", DeletePaper)
+	r.GET("/paper/list", PaperList)
+	r.GET("/paper/detail/:id", PaperDetail)
+	r.POST("/paper/update", UpdatePaper)
+}
+
+func CreatePaper(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var data model.BoxLib
+	err := c.ShouldBindJSON(&data)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	data.CreateTime = time.Now()
+	data.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionPaper, &data)
+}
+
+func DeletePaper(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionPaper, _id)
+}
+
+func PaperList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+
+	page, size, query := UtilQueryPageSize(c)
+	catsConf, err := GetSpu3dBoxLibCategory(apictx)
+	if err != nil {
+		return nil, err
+	}
+	err = ParseCategories(query, apictx.CreateRepoCtx(), catsConf)
+	if err != nil {
+		return nil, err
+	}
+
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionPaper,
+		Page:        page,
+		Size:        size,
+		Query:       query,
+		Sort:        bson.M{"createTime": -1},
+	})
+}
+
+func PaperDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	box := &model.BoxLib{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionPaper,
+		Query:       repo.Map{"_id": id},
+	}, box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+
+	if !found {
+		return nil, errors.New("未找到该数据")
+	}
+	return box, nil
+}
+
+func UpdatePaper(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var box model.BoxLib
+	err := c.ShouldBindJSON(&box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	if box.Id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionPaper, box.Id.Hex(), &box)
+}

+ 3 - 0
src/api/router.go

@@ -34,6 +34,9 @@ func RegRouters(svc *Service) {
 	CreateCategoryRouter(r)
 	// Asset(r)
 	BoxLib(r)
+	Decorate(r)
+	Scene(r)
+	Paper(r)
 
 	r.GET("/printr", Printr)
 }

+ 98 - 0
src/api/scene.go

@@ -0,0 +1,98 @@
+package api
+
+import (
+	"errors"
+	"spu3d/db/model"
+	"spu3d/db/repo"
+	"spu3d/log"
+	"time"
+
+	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+func Scene(r *GinRouter) {
+	r.POST("/scene/create", CreateScene)
+	r.POST("/scene/delete/:id", DeleteScene)
+	r.GET("/scene/list", SceneList)
+	r.GET("/scene/detail/:id", SceneDetail)
+	r.POST("/scene/update", UpdateScene)
+}
+
+func CreateScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var data model.BoxLib
+	err := c.ShouldBindJSON(&data)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	data.CreateTime = time.Now()
+	data.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionScene, &data)
+}
+
+func DeleteScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionScene, _id)
+}
+
+func SceneList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+
+	page, size, query := UtilQueryPageSize(c)
+	catsConf, err := GetSpu3dBoxLibCategory(apictx)
+	if err != nil {
+		return nil, err
+	}
+	err = ParseCategories(query, apictx.CreateRepoCtx(), catsConf)
+	if err != nil {
+		return nil, err
+	}
+
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: repo.CollectionScene,
+		Page:        page,
+		Size:        size,
+		Query:       query,
+		Sort:        bson.M{"createTime": -1},
+	})
+}
+
+func SceneDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	box := &model.BoxLib{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionScene,
+		Query:       repo.Map{"_id": id},
+	}, box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+
+	if !found {
+		return nil, errors.New("未找到该数据")
+	}
+	return box, nil
+}
+
+func UpdateScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var box model.BoxLib
+	err := c.ShouldBindJSON(&box)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	if box.Id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionScene, box.Id.Hex(), &box)
+}

+ 3 - 0
src/db/repo/repo.go

@@ -22,6 +22,9 @@ const (
 	CollectionNav        = "nav"
 	CollectionGallery    = "gallery"
 	CollectionBoxLib     = "boxlib"
+	CollectionDecorate   = "decorate"
+	CollectionScene      = "scene"
+	CollectionPaper      = "paper"
 )
 
 type Map map[string]interface{}