|
@@ -8,6 +8,7 @@ import (
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -20,6 +21,32 @@ func Product(r *GinRouter) {
|
|
r.POSTJWT("/product/onOrOffShelves", OnOrOffShelves)
|
|
r.POSTJWT("/product/onOrOffShelves", OnOrOffShelves)
|
|
r.GETJWT("/product/detail/:id", ProductDetail)
|
|
r.GETJWT("/product/detail/:id", ProductDetail)
|
|
r.POSTJWT("/product/delete/:id", ProductDelete)
|
|
r.POSTJWT("/product/delete/:id", ProductDelete)
|
|
|
|
+
|
|
|
|
+ //添加管理端接口
|
|
|
|
+ CreateCRUD(r, "/admin/products", &CRUDOption{
|
|
|
|
+ Collection: repo.CollectionProduct,
|
|
|
|
+ NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
+ entity := &model.Product{}
|
|
|
|
+ c.ShouldBindJSON(entity)
|
|
|
|
+ entity.CreateTime = time.Now()
|
|
|
|
+ if entity.Status == 0 {
|
|
|
|
+ entity.Status = -1
|
|
|
|
+ }
|
|
|
|
+ return entity, nil
|
|
|
|
+ },
|
|
|
|
+ EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
|
|
|
|
+ return &model.Product{}
|
|
|
|
+ },
|
|
|
|
+ SearchSort: bson.M{"createTime": -1},
|
|
|
|
+ SearchFilter: func(c *gin.Context, apictx *ApiSession, query map[string]interface{}) map[string]interface{} {
|
|
|
|
+ if query["supplyId"] != nil {
|
|
|
|
+ query["supplyId"], _ = primitive.ObjectIDFromHex(query["supplyId"].(string))
|
|
|
|
+ }
|
|
|
|
+ return query
|
|
|
|
+ },
|
|
|
|
+ JWT: true,
|
|
|
|
+ SearchProject: []string{"name", "createTime", "type", "unit", "price", "cover", "status"},
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
// 新增产品
|
|
// 新增产品
|