From ea28db7f6c8541ec60b8c110268b1f9c4236ee76 Mon Sep 17 00:00:00 2001 From: Smith Date: Sun, 3 May 2026 02:46:31 +0300 Subject: [PATCH 1/3] fix: missing query params in openapi specs --- internal/server/handler.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/server/handler.go b/internal/server/handler.go index 983776fa..d91c1bd2 100644 --- a/internal/server/handler.go +++ b/internal/server/handler.go @@ -3,13 +3,13 @@ package server import ( "bufio" "bytes" - "errors" "compress/gzip" "encoding/json" + "errors" "fmt" - "log/slog" "io" "io/fs" + "log/slog" "net/http" "net/url" "os" @@ -23,6 +23,7 @@ import ( "github.com/OCAP2/web/internal/maptool" "github.com/getkin/kin-openapi/openapi3" "github.com/go-fuego/fuego" + "github.com/go-fuego/fuego/option" "github.com/yohcop/openid-go" ) @@ -59,8 +60,8 @@ type Handler struct { repoAmmo *RepoAmmo setting Setting jwt *JWTManager - conversionTrigger ConversionTrigger // optional, nil if conversion disabled - staticFS fs.FS // optional, nil disables static file serving + conversionTrigger ConversionTrigger // optional, nil if conversion disabled + staticFS fs.FS // optional, nil disables static file serving maptoolMgr *maptool.JobManager // optional, nil if maptool disabled maptoolCfg *maptoolConfig // optional, nil if maptool disabled openIDVerifier openIDVerifier @@ -144,7 +145,12 @@ func NewHandler( fuego.Get(g, "/api/version", hdlr.GetVersion, fuego.OptionTags("Health")) // Recordings (public read) - fuego.Get(g, "/api/v1/operations", hdlr.GetOperations, fuego.OptionTags("Recordings")) + fuego.Get(g, "/api/v1/operations", hdlr.GetOperations, fuego.OptionTags("Recordings"), + option.Query("name", "Return only records matching the specified name (case-insensitive)"), + option.Query("older", "Return only records created before the specified date (YYYY-MM-DD)"), + option.Query("newer", "Return only records created after the specified date (YYYY-MM-DD)"), + option.Query("tag", "Return only records matching the specified tag (case-insensitive)"), + ) fuego.Get(g, "/api/v1/operations/{id}", hdlr.GetOperation, fuego.OptionTags("Recordings")) fuego.Get(g, "/api/v1/operations/{id}/marker-blacklist", hdlr.GetMarkerBlacklist, fuego.OptionTags("Recordings")) fuego.PostStd(g, "/api/v1/operations/add", hdlr.StoreOperation, fuego.OptionTags("Recordings")) From 4a3aa05873a15b1ff5c759d30ee2b45d24d9c834 Mon Sep 17 00:00:00 2001 From: Smith Date: Sun, 3 May 2026 03:21:14 +0300 Subject: [PATCH 2/3] chore: replace query params by auto-generated via context --- internal/server/handler.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/server/handler.go b/internal/server/handler.go index d91c1bd2..2f567061 100644 --- a/internal/server/handler.go +++ b/internal/server/handler.go @@ -23,7 +23,6 @@ import ( "github.com/OCAP2/web/internal/maptool" "github.com/getkin/kin-openapi/openapi3" "github.com/go-fuego/fuego" - "github.com/go-fuego/fuego/option" "github.com/yohcop/openid-go" ) @@ -145,12 +144,7 @@ func NewHandler( fuego.Get(g, "/api/version", hdlr.GetVersion, fuego.OptionTags("Health")) // Recordings (public read) - fuego.Get(g, "/api/v1/operations", hdlr.GetOperations, fuego.OptionTags("Recordings"), - option.Query("name", "Return only records matching the specified name (case-insensitive)"), - option.Query("older", "Return only records created before the specified date (YYYY-MM-DD)"), - option.Query("newer", "Return only records created after the specified date (YYYY-MM-DD)"), - option.Query("tag", "Return only records matching the specified tag (case-insensitive)"), - ) + fuego.Get(g, "/api/v1/operations", hdlr.GetOperations, fuego.OptionTags("Recordings")) fuego.Get(g, "/api/v1/operations/{id}", hdlr.GetOperation, fuego.OptionTags("Recordings")) fuego.Get(g, "/api/v1/operations/{id}/marker-blacklist", hdlr.GetMarkerBlacklist, fuego.OptionTags("Recordings")) fuego.PostStd(g, "/api/v1/operations/add", hdlr.StoreOperation, fuego.OptionTags("Recordings")) @@ -220,7 +214,7 @@ func (*Handler) cacheControl(duration time.Duration) func(http.Handler) http.Han } } -func (h *Handler) GetOperations(c ContextNoBody) ([]Operation, error) { +func (h *Handler) GetOperations(c fuego.Context[any, Filter]) ([]Operation, error) { ctx := c.Context() filter := Filter{ Name: c.QueryParam("name"), From 8b17ecee205c260c66ab9968db873d3254f8912e Mon Sep 17 00:00:00 2001 From: Smith Date: Sun, 3 May 2026 03:36:22 +0300 Subject: [PATCH 3/3] test: fix handler and intergation tests --- internal/server/handler_test.go | 15 +++++++-------- internal/server/integration_test.go | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/server/handler_test.go b/internal/server/handler_test.go index c3eaac4a..d9b224b7 100644 --- a/internal/server/handler_test.go +++ b/internal/server/handler_test.go @@ -84,7 +84,7 @@ func TestGetOperations(t *testing.T) { } t.Run("get all operations", func(t *testing.T) { - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) req := httptest.NewRequest(http.MethodGet, "/api/v1/operations", nil) mockCtx.SetRequest(req) @@ -94,7 +94,7 @@ func TestGetOperations(t *testing.T) { }) t.Run("filter by name", func(t *testing.T) { - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) mockCtx.SetQueryParam("name", "Alpha") result, err := hdlr.GetOperations(mockCtx) @@ -104,7 +104,7 @@ func TestGetOperations(t *testing.T) { }) t.Run("filter by tag", func(t *testing.T) { - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) mockCtx.SetQueryParam("tag", "tvt") result, err := hdlr.GetOperations(mockCtx) @@ -114,7 +114,7 @@ func TestGetOperations(t *testing.T) { }) t.Run("filter by date range", func(t *testing.T) { - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) mockCtx.SetQueryParam("newer", "2026-01-18") mockCtx.SetQueryParam("older", "2026-01-25") @@ -1500,7 +1500,7 @@ func TestGetOperations_Success(t *testing.T) { hdlr := Handler{repoOperation: repo} - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) mockCtx.SetQueryParam("name", "Alpha") mockCtx.SetQueryParam("tag", "coop") @@ -1528,7 +1528,7 @@ func TestGetOperations_WithFilters(t *testing.T) { hdlr := Handler{repoOperation: repo} - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) mockCtx.SetQueryParam("older", "2026-01-15") mockCtx.SetQueryParam("newer", "2026-01-01") @@ -1749,7 +1749,7 @@ func TestGetOperations_BindError(t *testing.T) { // Test the Select error path using closed DB repo.db.Close() - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) _, err = h.GetOperations(mockCtx) assert.Error(t, err) // Should return the DB error } @@ -2365,4 +2365,3 @@ func TestStoreOperation_EmptyFile(t *testing.T) { h.StoreOperation(rec, req) assert.Equal(t, http.StatusInternalServerError, rec.Code) } - diff --git a/internal/server/integration_test.go b/internal/server/integration_test.go index c8a36dcd..5fdaeb92 100644 --- a/internal/server/integration_test.go +++ b/internal/server/integration_test.go @@ -17,8 +17,8 @@ import ( "strings" "testing" - pbv1 "github.com/OCAP2/web/pkg/schemas/protobuf/v1" "github.com/OCAP2/web/internal/storage" + pbv1 "github.com/OCAP2/web/pkg/schemas/protobuf/v1" "github.com/go-fuego/fuego" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -338,7 +338,7 @@ func TestIntegration_UploadWithoutConversion(t *testing.T) { // Step 2: Query operations API and verify the operation is completed t.Run("QueryShowsCompleted", func(t *testing.T) { - mockCtx := fuego.NewMockContextNoBody() + mockCtx := fuego.NewMockContext[any](nil, Filter{}) ops, err := hdlr.GetOperations(mockCtx) require.NoError(t, err)