chore: Stick with old SortDirection

This commit is contained in:
Cristian Ditaputratama 2024-11-03 20:43:43 +07:00
parent f0a10208e2
commit 6e7eccc6b3
Signed by: ditatompel
GPG key ID: 31D3D06D77950979
4 changed files with 13 additions and 25 deletions

View file

@ -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"),

View file

@ -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

View file

@ -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",

View file

@ -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"`