Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(user): add FilterEmptyString function and apply to user ID filtering

LinkinStars57b153c9a9df
diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.go
index be15bbe7..d05ffd4b 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -141,6 +141,7 @@ func (us *UserCommon) UpdateQuestionCount(ctx context.Context, userID string, nu
}
func (us *UserCommon) BatchUserBasicInfoByID(ctx context.Context, userIDs []string) (map[string]*schema.UserBasicInfo, error) {
+ userIDs = checker.FilterEmptyString(userIDs)
userMap := make(map[string]*schema.UserBasicInfo)
if len(userIDs) == 0 {
return userMap, nil
diff --git a/pkg/checker/zero_string.go b/pkg/checker/zero_string.go
index 7b7e3111..7789cf63 100644
--- a/pkg/checker/zero_string.go
+++ b/pkg/checker/zero_string.go
@@ -23,3 +23,14 @@ package checker
func IsNotZeroString(s string) bool {
return len(s) > 0 && s != "0"
}
+
+// FilterEmptyString filter empty string from string slice
+func FilterEmptyString(strs []string) []string {
+ var result []string
+ for _, str := range strs {
+ if IsNotZeroString(str) {
+ result = append(result, str)
+ }
+ }
+ return result
+}