mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
add url sorting option
This commit is contained in:
@@ -18,9 +18,11 @@ const (
|
||||
DefaultSortOrder = "desc"
|
||||
)
|
||||
|
||||
// Valid sortable fields mapped to their database column names
|
||||
// Valid sortable fields mapped to their database column names or expressions
|
||||
// For multi-column sorts, columns are separated by comma (e.g., "host, path")
|
||||
var validSortFields = map[string]string{
|
||||
"timestamp": "timestamp",
|
||||
"url": "host, path", // Sort by host first, then path
|
||||
"host": "host",
|
||||
"path": "path",
|
||||
"method": "method",
|
||||
@@ -40,7 +42,7 @@ type AccessLogFilter struct {
|
||||
PageSize int
|
||||
|
||||
// Sorting parameters
|
||||
SortBy string // Field to sort by: timestamp, host, path, method, status_code, duration, source_ip, user_id, auth_method, reason
|
||||
SortBy string // Field to sort by: timestamp, url, host, path, method, status_code, duration, source_ip, user_id, auth_method, reason
|
||||
SortOrder string // Sort order: asc or desc (default: desc)
|
||||
|
||||
// Filtering parameters
|
||||
|
||||
@@ -381,6 +381,7 @@ func TestAccessLogFilter_ValidSortFields(t *testing.T) {
|
||||
expectedSortByVal string
|
||||
}{
|
||||
{"timestamp", "timestamp", "timestamp", "timestamp"},
|
||||
{"url", "url", "host, path", "url"},
|
||||
{"host", "host", "host", "host"},
|
||||
{"path", "path", "path", "path"},
|
||||
{"method", "method", "method", "method"},
|
||||
|
||||
@@ -5082,9 +5082,17 @@ func (s *SqlStore) GetAccountAccessLogs(ctx context.Context, lockStrength Lockin
|
||||
|
||||
query = s.applyAccessLogFilters(query, filter)
|
||||
|
||||
sortColumn := filter.GetSortColumn()
|
||||
sortOrder := filter.GetSortOrder()
|
||||
orderClause := sortColumn + " " + strings.ToUpper(sortOrder)
|
||||
sortColumns := filter.GetSortColumn()
|
||||
sortOrder := strings.ToUpper(filter.GetSortOrder())
|
||||
|
||||
var orderClauses []string
|
||||
for _, col := range strings.Split(sortColumns, ",") {
|
||||
col = strings.TrimSpace(col)
|
||||
if col != "" {
|
||||
orderClauses = append(orderClauses, col+" "+sortOrder)
|
||||
}
|
||||
}
|
||||
orderClause := strings.Join(orderClauses, ", ")
|
||||
|
||||
query = query.
|
||||
Order(orderClause).
|
||||
|
||||
@@ -7413,9 +7413,9 @@ paths:
|
||||
name: sort_by
|
||||
schema:
|
||||
type: string
|
||||
enum: [timestamp, host, path, method, status_code, duration, source_ip, user_id, auth_method, reason]
|
||||
enum: [timestamp, url, host, path, method, status_code, duration, source_ip, user_id, auth_method, reason]
|
||||
default: timestamp
|
||||
description: Field to sort by
|
||||
description: Field to sort by (url sorts by host then path)
|
||||
- in: query
|
||||
name: sort_order
|
||||
schema:
|
||||
|
||||
Reference in New Issue
Block a user