diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-12-02 19:32:14 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-12-02 19:32:14 -0800 |
commit | 2356ddad28d50aacc8bbb3e020792d3b92f2fb4d (patch) | |
tree | a881d13d2fcc2e0d0fef2f7d26cfd2d6b044209f /storage | |
parent | 2f1367a8d4c33e7c6ba459cfc6756e079c7a1af4 (diff) |
Add Pinboard integration
Diffstat (limited to 'storage')
-rw-r--r-- | storage/integration.go | 78 | ||||
-rw-r--r-- | storage/migration.go | 2 | ||||
-rw-r--r-- | storage/user.go | 1 |
3 files changed, 80 insertions, 1 deletions
diff --git a/storage/integration.go b/storage/integration.go new file mode 100644 index 0000000..d21b618 --- /dev/null +++ b/storage/integration.go @@ -0,0 +1,78 @@ +// 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 storage + +import ( + "database/sql" + "fmt" + + "github.com/miniflux/miniflux2/model" +) + +// Integration returns user integration settings. +func (s *Storage) Integration(userID int64) (*model.Integration, error) { + query := `SELECT + user_id, + pinboard_enabled, + pinboard_token, + pinboard_tags, + pinboard_mark_as_unread + FROM integrations + WHERE user_id=$1 + ` + var integration model.Integration + err := s.db.QueryRow(query, userID).Scan( + &integration.UserID, + &integration.PinboardEnabled, + &integration.PinboardToken, + &integration.PinboardTags, + &integration.PinboardMarkAsUnread, + ) + switch { + case err == sql.ErrNoRows: + return nil, nil + case err != nil: + return nil, fmt.Errorf("unable to fetch integration row: %v", err) + } + + return &integration, nil +} + +// UpdateIntegration saves user integration settings. +func (s *Storage) UpdateIntegration(integration *model.Integration) error { + query := ` + UPDATE integrations SET + pinboard_enabled=$1, + pinboard_token=$2, + pinboard_tags=$3, + pinboard_mark_as_unread=$4 + WHERE user_id=$5 + ` + _, err := s.db.Exec( + query, + integration.PinboardEnabled, + integration.PinboardToken, + integration.PinboardTags, + integration.PinboardMarkAsUnread, + integration.UserID, + ) + + if err != nil { + return fmt.Errorf("unable to update integration row: %v", err) + } + + return nil +} + +// CreateIntegration creates initial user integration settings. +func (s *Storage) CreateIntegration(userID int64) error { + query := `INSERT INTO integrations (user_id) VALUES ($1)` + _, err := s.db.Exec(query, userID) + if err != nil { + return fmt.Errorf("unable to create integration row: %v", err) + } + + return nil +} diff --git a/storage/migration.go b/storage/migration.go index 9cfde8b..76ad801 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -12,7 +12,7 @@ import ( "github.com/miniflux/miniflux2/sql" ) -const schemaVersion = 4 +const schemaVersion = 5 // Migrate run database migrations. func (s *Storage) Migrate() { diff --git a/storage/user.go b/storage/user.go index 7d296a9..689ed74 100644 --- a/storage/user.go +++ b/storage/user.go @@ -86,6 +86,7 @@ func (s *Storage) CreateUser(user *model.User) (err error) { } s.CreateCategory(&model.Category{Title: "All", UserID: user.ID}) + s.CreateIntegration(user.ID) return nil } |