summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-05-22 20:06:56 +0200
committerewy <ewy0@protonmail.com>2026-05-22 20:06:56 +0200
commit094846c15f4148c166ac297e26a1248bab0ab5c7 (patch)
treed9f671bb0d34b5be52db62636278f5d3e5657283 /api
parent3ea1ed1362984619b182c0ddf9a6b1dc7ba5bcd0 (diff)
add views, expand api, add windows opening thing overridemain
Diffstat (limited to 'api')
-rw-r--r--api/filter.go44
-rw-r--r--api/filter_test.go19
-rw-r--r--api/request.go10
3 files changed, 69 insertions, 4 deletions
diff --git a/api/filter.go b/api/filter.go
index 1130c7c..5fbe6a7 100644
--- a/api/filter.go
+++ b/api/filter.go
@@ -2,8 +2,44 @@
package api
-type Filter struct {
- Win *bool
- ActName *string
- ActIndex *int
+import (
+ "fmt"
+ "reflect"
+ "strings"
+ "sts2stats/spool"
+)
+
+type Filter interface {
+ WhereQuery() string
+}
+
+type RunFilter struct {
+ Win *bool
+ Character *string
+ Ascension *int
+ Version *string
+}
+
+func Query(f any) string {
+ var parts []string
+ for field, value := range reflect.ValueOf(f).Fields() {
+ if !value.IsNil() {
+ elem := value.Elem()
+
+ switch elem.Kind() {
+ case reflect.String:
+ parts = append(parts, fmt.Sprintf("%v = '%v'", field.Name, elem.String()))
+ case reflect.Int:
+ parts = append(parts, fmt.Sprintf("%v = %v", field.Name, elem.Int()))
+ case reflect.Bool:
+ parts = append(parts, fmt.Sprintf("%v = %v", field.Name, elem.Bool()))
+ default:
+ spool.Warn("unsupported filter field kind: %v", elem.Kind())
+ }
+ }
+ }
+ if len(parts) == 0 {
+ return ""
+ }
+ return fmt.Sprintf("WHERE %s", strings.Join(parts, " AND "))
}
diff --git a/api/filter_test.go b/api/filter_test.go
new file mode 100644
index 0000000..dcfa5df
--- /dev/null
+++ b/api/filter_test.go
@@ -0,0 +1,19 @@
+//go:build api
+
+package api
+
+import "testing"
+
+func ptr[T any](obj T) *T {
+ return &obj
+}
+
+func TestFilter(t *testing.T) {
+ f := RunFilter{
+ Win: ptr(true),
+ Character: ptr("guy"),
+ Ascension: ptr(3),
+ Version: ptr("0.333.2"),
+ }
+ Query(f)
+}
diff --git a/api/request.go b/api/request.go
new file mode 100644
index 0000000..0df902a
--- /dev/null
+++ b/api/request.go
@@ -0,0 +1,10 @@
+//go:build api
+
+package api
+
+type Request struct {
+}
+
+type CardRequest struct {
+ Request
+}