aboutsummaryrefslogtreecommitdiffhomepage
path: root/model/entry.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-11-19 21:10:04 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-11-19 22:01:46 -0800
commit8ffb773f43c8dc54801ca1d111854e7e881c93c9 (patch)
tree38133a2fc612597a75fed1d13e5b4042f58a2b7e /model/entry.go
First commit
Diffstat (limited to 'model/entry.go')
-rw-r--r--model/entry.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/model/entry.go b/model/entry.go
new file mode 100644
index 0000000..6858935
--- /dev/null
+++ b/model/entry.go
@@ -0,0 +1,71 @@
+// Copyright 2017 Frédéric Guillot. All rights reserved.
+// Use of this source code is governed by the Apache 2.0
+// license that can be found in the LICENSE file.
+
+package model
+
+import (
+ "fmt"
+ "time"
+)
+
+const (
+ EntryStatusUnread = "unread"
+ EntryStatusRead = "read"
+ EntryStatusRemoved = "removed"
+ DefaultSortingOrder = "published_at"
+ DefaultSortingDirection = "desc"
+)
+
+type Entry struct {
+ ID int64 `json:"id"`
+ UserID int64 `json:"user_id"`
+ FeedID int64 `json:"feed_id"`
+ Status string `json:"status"`
+ Hash string `json:"hash"`
+ Title string `json:"title"`
+ URL string `json:"url"`
+ Date time.Time `json:"published_at"`
+ Content string `json:"content"`
+ Author string `json:"author"`
+ Enclosures EnclosureList `json:"enclosures,omitempty"`
+ Feed *Feed `json:"feed,omitempty"`
+ Category *Category `json:"category,omitempty"`
+}
+
+type Entries []*Entry
+
+func ValidateEntryStatus(status string) error {
+ switch status {
+ case EntryStatusRead, EntryStatusUnread, EntryStatusRemoved:
+ return nil
+ }
+
+ return fmt.Errorf(`Invalid entry status, valid status values are: "%s", "%s" and "%s"`, EntryStatusRead, EntryStatusUnread, EntryStatusRemoved)
+}
+
+func ValidateEntryOrder(order string) error {
+ switch order {
+ case "id", "status", "published_at", "category_title", "category_id":
+ return nil
+ }
+
+ return fmt.Errorf(`Invalid entry order, valid order values are: "id", "status", "published_at", "category_title", "category_id"`)
+}
+
+func ValidateDirection(direction string) error {
+ switch direction {
+ case "asc", "desc":
+ return nil
+ }
+
+ return fmt.Errorf(`Invalid direction, valid direction values are: "asc" or "desc"`)
+}
+
+func GetOppositeDirection(direction string) string {
+ if direction == "asc" {
+ return "desc"
+ }
+
+ return "asc"
+}