summaryrefslogtreecommitdiff
path: root/internal/api/util
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/util')
-rw-r--r--internal/api/util/parsequery.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/internal/api/util/parsequery.go b/internal/api/util/parsequery.go
index 5210735a1..90cc30e6f 100644
--- a/internal/api/util/parsequery.go
+++ b/internal/api/util/parsequery.go
@@ -34,13 +34,16 @@ const (
/* Common keys */
- IDKey = "id"
- LimitKey = "limit"
- LocalKey = "local"
- MaxIDKey = "max_id"
- SinceIDKey = "since_id"
- MinIDKey = "min_id"
- UsernameKey = "username"
+ IDKey = "id"
+ LimitKey = "limit"
+ LocalKey = "local"
+ MaxIDKey = "max_id"
+ SinceIDKey = "since_id"
+ MinIDKey = "min_id"
+ UsernameKey = "username"
+ AccountIDKey = "account_id"
+ TargetAccountIDKey = "target_account_id"
+ ResolvedKey = "resolved"
/* AP endpoint keys */
@@ -55,7 +58,6 @@ const (
SearchQueryKey = "q"
SearchResolveKey = "resolve"
SearchTypeKey = "type"
- SearchAccountIDKey = "account_id"
/* Tag keys */
@@ -132,6 +134,10 @@ func ParseLocal(value string, defaultValue bool) (bool, gtserror.WithCode) {
return parseBool(value, defaultValue, LocalKey)
}
+func ParseResolved(value string, defaultValue *bool) (*bool, gtserror.WithCode) {
+ return parseBoolPtr(value, defaultValue, ResolvedKey)
+}
+
func ParseSearchExcludeUnreviewed(value string, defaultValue bool) (bool, gtserror.WithCode) {
return parseBool(value, defaultValue, SearchExcludeUnreviewedKey)
}
@@ -289,6 +295,19 @@ func parseBool(value string, defaultValue bool, key string) (bool, gtserror.With
return i, nil
}
+func parseBoolPtr(value string, defaultValue *bool, key string) (*bool, gtserror.WithCode) {
+ if value == "" {
+ return defaultValue, nil
+ }
+
+ i, err := strconv.ParseBool(value)
+ if err != nil {
+ return defaultValue, parseError(key, value, defaultValue, err)
+ }
+
+ return &i, nil
+}
+
func parseInt(value string, defaultValue int, max int, min int, key string) (int, gtserror.WithCode) {
if value == "" {
return defaultValue, nil