From 6e7eccc6b3ba34ce57c1d0c0b7dfdf273cac33cc Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Sun, 3 Nov 2024 20:43:43 +0700 Subject: [PATCH] chore: Stick with old `SortDirection` --- internal/handler/response.go | 6 ++---- internal/monero/monero.go | 9 ++------- internal/monero/monero_test.go | 13 +++++-------- internal/paging/paging.go | 10 ++++------ 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/internal/handler/response.go b/internal/handler/response.go index 279a59a..4a2ae4c 100644 --- a/internal/handler/response.go +++ b/internal/handler/response.go @@ -102,8 +102,7 @@ func (s *fiberServer) remoteNodesHandler(c *fiber.Ctx) error { Limit: c.QueryInt("limit", 10), // rows per page Page: c.QueryInt("page", 1), SortBy: c.Query("sort_by", "id"), - SortDir: c.Query("sort_dir", "desc"), - SortDirection: c.Query("sort_direction", "desc"), // deprecated + SortDirection: c.Query("sort_direction", "desc"), Refresh: c.QueryInt("refresh", 0), }, Host: c.Query("host"), @@ -156,8 +155,7 @@ func Nodes(c *fiber.Ctx) error { Limit: c.QueryInt("limit", 10), // rows per page Page: c.QueryInt("page", 1), SortBy: c.Query("sort_by", "id"), - SortDir: c.Query("sort_dir", "desc"), - SortDirection: c.Query("sort_direction", "desc"), // deprecated + SortDirection: c.Query("sort_direction", "desc"), Refresh: c.QueryInt("refresh", 0), }, Host: c.Query("host"), diff --git a/internal/monero/monero.go b/internal/monero/monero.go index f889547..cad166d 100644 --- a/internal/monero/monero.go +++ b/internal/monero/monero.go @@ -131,13 +131,8 @@ func (q *QueryNodes) toSQL() (args []interface{}, where string) { q.SortBy = "last_checked" } - // deprecated: Use SortDir instead if q.SortDirection != "asc" { - q.SortDir = "DESC" - } - - if q.SortDir != "asc" { - q.SortDir = "DESC" + q.SortDirection = "DESC" } return args, where @@ -183,7 +178,7 @@ func (r *moneroRepo) Nodes(q QueryNodes) (Nodes, error) { %s %s LIMIT ? - OFFSET ?`, where, q.SortBy, q.SortDir) + OFFSET ?`, where, q.SortBy, q.SortDirection) err = r.db.Select(&nodes.Items, query, args...) return nodes, err diff --git a/internal/monero/monero_test.go b/internal/monero/monero_test.go index 2b8d649..544bd71 100644 --- a/internal/monero/monero_test.go +++ b/internal/monero/monero_test.go @@ -54,8 +54,7 @@ func TestQueryNodes_toSQL(t *testing.T) { Limit: 10, Page: 1, SortBy: "last_checked", - SortDir: "desc", - SortDirection: "desc", // deprecated + SortDirection: "desc", }, Host: "", Nettype: "any", @@ -76,8 +75,7 @@ func TestQueryNodes_toSQL(t *testing.T) { Limit: 10, Page: 1, SortBy: "last_checked", - SortDir: "desc", - SortDirection: "desc", // deprecated + SortDirection: "desc", }, Host: "test", Nettype: "any", @@ -104,8 +102,8 @@ func TestQueryNodes_toSQL(t *testing.T) { if tt.query.SortBy != tt.wantSortBy { t.Errorf("QueryNodes.toSQL() gotSortBy = %v, want %v", tt.query.SortBy, tt.wantSortBy) } - if tt.query.SortDir != tt.wantSortDir { - t.Errorf("QueryNodes.toSQL() gotSortDir = %v, want %v", tt.query.SortDir, tt.wantSortDir) + if tt.query.SortDirection != tt.wantSortDir { + t.Errorf("QueryNodes.toSQL() gotSortDir = %v, want %v", tt.query.SortDirection, tt.wantSortDir) } }) } @@ -119,8 +117,7 @@ func Benchmark_QueryNodes_toSQL(b *testing.B) { Limit: 10, Page: 1, SortBy: "last_checked", - SortDir: "desc", - SortDirection: "desc", // deprecated + SortDirection: "desc", }, Host: "test", Nettype: "any", diff --git a/internal/paging/paging.go b/internal/paging/paging.go index 3669e53..1233bff 100644 --- a/internal/paging/paging.go +++ b/internal/paging/paging.go @@ -7,12 +7,10 @@ import ( ) type Paging struct { - Limit int `url:"limit,omitempty"` // rows per page - Page int `url:"page"` - SortBy string `url:"sort_by,omitempty"` - SortDir string `url:"sort_dir,omitempty"` - - SortDirection string `url:"sort_direction,omitempty"` // DEPRECATED: use SortDir + Limit int `url:"limit,omitempty"` // rows per page + Page int `url:"page"` + SortBy string `url:"sort_by,omitempty"` + SortDirection string `url:"sort_direction,omitempty"` // Refresh interval Refresh int `url:"refresh,omitempty"`