animeic 2 years ago
parent
commit
20f2ee2249
3 changed files with 31 additions and 0 deletions
  1. 9 0
      boxcost/api/craft.go
  2. 9 0
      boxcost/api/material.go
  3. 13 0
      boxcost/api/product.go

+ 9 - 0
boxcost/api/craft.go

@@ -82,6 +82,15 @@ func GetCrafts(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
+	if _name, ok := query["name"]; ok {
+		delete(query, "name")
+		query["name"] = bson.M{"$regex": _name.(string)}
+	}
+	if _norm, ok := query["norm"]; ok {
+		delete(query, "norm")
+		query["name"] = bson.M{"$regex": _norm.(string)}
+	}
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionCraft,
 		Query:       query,

+ 9 - 0
boxcost/api/material.go

@@ -82,6 +82,15 @@ func GetMaterials(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 
+	if _name, ok := query["name"]; ok {
+		delete(query, "name")
+		query["name"] = bson.M{"$regex": _name.(string)}
+	}
+	if _norm, ok := query["norm"]; ok {
+		delete(query, "norm")
+		query["name"] = bson.M{"$regex": _norm.(string)}
+	}
+
 	option := &repo.PageSearchOptions{
 		CollectName: repo.CollectionMaterial,
 		Query:       query,

+ 13 - 0
boxcost/api/product.go

@@ -8,6 +8,7 @@ import (
 	"time"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
@@ -28,6 +29,18 @@ func Product(r *GinRouter) {
 		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
 			return &model.Product{}
 		},
+		SearchFilter: func(c *gin.Context, apictx *ApiSession, query map[string]interface{}) map[string]interface{} {
+			if _name, ok := query["name"]; ok {
+				delete(query, "name")
+				query["name"] = bson.M{"$regex": _name.(string)}
+			}
+			if _norm, ok := query["norm"]; ok {
+				delete(query, "norm")
+				query["name"] = bson.M{"$regex": _norm.(string)}
+			}
+
+			return query
+		},
 
 		JWT: true,
 		OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {