From 2f1367a8d4c33e7c6ba459cfc6756e079c7a1af4 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 2 Dec 2017 17:04:01 -0800 Subject: Make entries sorting configurable --- model/entry.go | 6 +++--- model/entry_test.go | 6 +++--- model/token.go | 6 ++++++ model/user.go | 19 ++++++++++--------- 4 files changed, 22 insertions(+), 15 deletions(-) (limited to 'model') diff --git a/model/entry.go b/model/entry.go index 79a3bcb..f9a9638 100644 --- a/model/entry.go +++ b/model/entry.go @@ -15,7 +15,7 @@ const ( EntryStatusRead = "read" EntryStatusRemoved = "removed" DefaultSortingOrder = "published_at" - DefaultSortingDirection = "desc" + DefaultSortingDirection = "asc" ) // Entry represents a feed item in the system. @@ -81,8 +81,8 @@ func ValidateRange(offset, limit int) error { return nil } -// GetOppositeDirection returns the opposite sorting direction. -func GetOppositeDirection(direction string) string { +// OppositeDirection returns the opposite sorting direction. +func OppositeDirection(direction string) string { if direction == "asc" { return "desc" } diff --git a/model/entry_test.go b/model/entry_test.go index 2f8c25d..8b92d3f 100644 --- a/model/entry_test.go +++ b/model/entry_test.go @@ -57,15 +57,15 @@ func TestValidateRange(t *testing.T) { } func TestGetOppositeDirection(t *testing.T) { - if GetOppositeDirection("asc") != "desc" { + if OppositeDirection("asc") != "desc" { t.Errorf(`The opposite direction of "asc" should be "desc"`) } - if GetOppositeDirection("desc") != "asc" { + if OppositeDirection("desc") != "asc" { t.Errorf(`The opposite direction of "desc" should be "asc"`) } - if GetOppositeDirection("invalid") != "asc" { + if OppositeDirection("invalid") != "asc" { t.Errorf(`An invalid direction should return "asc"`) } } diff --git a/model/token.go b/model/token.go index 5626a77..3c5c323 100644 --- a/model/token.go +++ b/model/token.go @@ -4,8 +4,14 @@ package model +import "fmt" + // Token represents a CSRF token in the system. type Token struct { ID string Value string } + +func (t Token) String() string { + return fmt.Sprintf(`ID="%s"`, t.ID) +} diff --git a/model/user.go b/model/user.go index c030d52..4889dc4 100644 --- a/model/user.go +++ b/model/user.go @@ -11,15 +11,16 @@ import ( // User represents a user in the system. type User struct { - ID int64 `json:"id"` - Username string `json:"username"` - Password string `json:"password,omitempty"` - IsAdmin bool `json:"is_admin,omitempty"` - Theme string `json:"theme,omitempty"` - Language string `json:"language,omitempty"` - Timezone string `json:"timezone,omitempty"` - LastLoginAt *time.Time `json:"last_login_at,omitempty"` - Extra map[string]string `json:"-"` + ID int64 `json:"id"` + Username string `json:"username"` + Password string `json:"password,omitempty"` + IsAdmin bool `json:"is_admin,omitempty"` + Theme string `json:"theme,omitempty"` + Language string `json:"language,omitempty"` + Timezone string `json:"timezone,omitempty"` + EntryDirection string `json:"entry_sorting_direction,omitempty"` + LastLoginAt *time.Time `json:"last_login_at,omitempty"` + Extra map[string]string `json:"-"` } // NewUser returns a new User. -- cgit v1.2.3