2019-07-17 05:28:37 +00:00
|
|
|
package browsers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-16 18:31:34 +00:00
|
|
|
|
2024-10-28 20:54:17 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/logutils"
|
2019-07-17 05:28:37 +00:00
|
|
|
)
|
|
|
|
|
2019-07-25 05:35:09 +00:00
|
|
|
func NewAPI(db *Database) *API {
|
|
|
|
return &API{db: db}
|
2019-07-17 05:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// API is class with methods available over RPC.
|
|
|
|
type API struct {
|
2019-07-25 05:35:09 +00:00
|
|
|
db *Database
|
2019-07-17 05:28:37 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 18:31:34 +00:00
|
|
|
func (api *API) GetBookmarks(ctx context.Context) ([]*Bookmark, error) {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("call to get bookmarks")
|
2020-11-16 18:31:34 +00:00
|
|
|
rst, err := api.db.GetBookmarks()
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("result from database for bookmarks", zap.Int("len", len(rst)))
|
2020-11-16 18:31:34 +00:00
|
|
|
return rst, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) StoreBookmark(ctx context.Context, bookmark Bookmark) (Bookmark, error) {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("call to create a bookmark")
|
2020-11-16 18:31:34 +00:00
|
|
|
bookmarkResult, err := api.db.StoreBookmark(bookmark)
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("result from database for creating a bookmark", zap.Error(err))
|
2020-11-16 18:31:34 +00:00
|
|
|
return bookmarkResult, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) UpdateBookmark(ctx context.Context, originalURL string, bookmark Bookmark) error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("call to update a bookmark")
|
2020-11-16 18:31:34 +00:00
|
|
|
err := api.db.UpdateBookmark(originalURL, bookmark)
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("result from database for updating a bookmark", zap.Error(err))
|
2020-11-16 18:31:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (api *API) DeleteBookmark(ctx context.Context, url string) error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("call to remove a bookmark")
|
2020-11-16 18:31:34 +00:00
|
|
|
err := api.db.DeleteBookmark(url)
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("result from database for remove a bookmark", zap.Error(err))
|
2020-11-16 18:31:34 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-01-17 03:42:11 +00:00
|
|
|
|
|
|
|
func (api *API) RemoveBookmark(ctx context.Context, url string) error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("call to remove a bookmark logically")
|
2022-01-17 03:42:11 +00:00
|
|
|
err := api.db.RemoveBookmark(url)
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("result from database for remove a bookmark logically", zap.Error(err))
|
2022-01-17 03:42:11 +00:00
|
|
|
return err
|
|
|
|
}
|