refactor: standardize filter handling across controllers

- Replaced "conditions" parameter with "filter" in various controller methods to unify the filtering approach.
- Updated related functions to utilize the new filter parameter, enhancing consistency in query handling.
- Improved overall code readability and maintainability by aligning naming conventions and refactoring filter-related logic.
This commit is contained in:
Marvin Zhang
2025-03-26 22:08:01 +08:00
parent 863ba153f6
commit f86173c973
17 changed files with 274 additions and 269 deletions

View File

@@ -35,9 +35,10 @@ const (
DefaultPyenvPath = "/root/.pyenv"
DefaultNodeModulesPath = "/usr/lib/node_modules"
DefaultGoPath = "/root/go"
DefaultMCPServerBaseUrl = "http://localhost:9000"
DefaultMCPClientBaseUrl = "http://localhost:9000/sse"
DefaultOpenAPIUrl = "http://localhost:8000/openapi.json"
DefaultMCPServerHost = "0.0.0.0"
DefaultMCPServerPort = 9777
DefaultMCPClientBaseUrl = "http://localhost:9777/sse"
DefaultOpenAPIUrlPath = "/openapi.json"
)
func IsDev() bool {
@@ -289,11 +290,16 @@ func GetGoPath() string {
return DefaultGoPath
}
func GetMCPServerBaseUrl() string {
if res := viper.GetString("mcp.server.base_url"); res != "" {
return res
func GetMCPServerAddress() string {
host := viper.GetString("mcp.server.host")
if host == "" {
host = DefaultMCPServerHost
}
return DefaultMCPServerBaseUrl
port := viper.GetInt("mcp.server.port")
if port == 0 {
port = DefaultMCPServerPort
}
return fmt.Sprintf("%s:%d", host, port)
}
func GetMCPClientBaseUrl() string {
@@ -307,5 +313,5 @@ func GetOpenAPIUrl() string {
if res := viper.GetString("openapi.url"); res != "" {
return res
}
return DefaultOpenAPIUrl
return GetApiEndpoint() + DefaultOpenAPIUrlPath
}

View File

@@ -1,16 +1,15 @@
package utils
import (
errors2 "errors"
"github.com/crawlab-team/crawlab/core/constants"
"github.com/crawlab-team/crawlab/core/interfaces"
"go.mongodb.org/mongo-driver/bson"
)
// FilterToQuery Translate entity.Filter to bson.M
func FilterToQuery(f interfaces.Filter) (q bson.M, err error) {
func FilterToQuery(f interfaces.Filter) (q bson.M) {
if f == nil || f.IsNil() {
return nil, nil
return nil
}
q = bson.M{}
@@ -42,8 +41,11 @@ func FilterToQuery(f interfaces.Filter) (q bson.M, err error) {
case constants.FilterOpLessThanEqual:
q[key] = bson.M{"$lte": value}
default:
return nil, errors2.New("invalid operation")
// ignore invalid operation
}
}
return q, nil
if len(q) == 0 {
return nil
}
return q
}