From c57cafbef28a8a12cae02674b3c36979acb0e576 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 4 Jan 2018 18:11:15 -0800 Subject: Add link to mark everything as read --- storage/entry.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'storage') diff --git a/storage/entry.go b/storage/entry.go index 3be6c92..c6058d0 100644 --- a/storage/entry.go +++ b/storage/entry.go @@ -213,3 +213,16 @@ func (s *Storage) FlushHistory(userID int64) error { return nil } + +// MarkAllAsRead set all entries with the status "unread" to "read". +func (s *Storage) MarkAllAsRead(userID int64) error { + defer timer.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:MarkAllAsRead] userID=%d", userID)) + + query := `UPDATE entries SET status=$1 WHERE user_id=$2 AND status=$3` + _, err := s.db.Exec(query, model.EntryStatusRead, userID, model.EntryStatusUnread) + if err != nil { + return fmt.Errorf("unable to mark all entries as read: %v", err) + } + + return nil +} -- cgit v1.2.3