github.com/status-im/status-go@v1.1.0/services/browsers/api.go (about)

     1  package browsers
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ethereum/go-ethereum/log"
     7  )
     8  
     9  func NewAPI(db *Database) *API {
    10  	return &API{db: db}
    11  }
    12  
    13  // API is class with methods available over RPC.
    14  type API struct {
    15  	db *Database
    16  }
    17  
    18  func (api *API) GetBookmarks(ctx context.Context) ([]*Bookmark, error) {
    19  	log.Debug("call to get bookmarks")
    20  	rst, err := api.db.GetBookmarks()
    21  	log.Debug("result from database for bookmarks", "len", len(rst))
    22  	return rst, err
    23  }
    24  
    25  func (api *API) StoreBookmark(ctx context.Context, bookmark Bookmark) (Bookmark, error) {
    26  	log.Debug("call to create a bookmark")
    27  	bookmarkResult, err := api.db.StoreBookmark(bookmark)
    28  	log.Debug("result from database for creating a bookmark", "err", err)
    29  	return bookmarkResult, err
    30  }
    31  
    32  func (api *API) UpdateBookmark(ctx context.Context, originalURL string, bookmark Bookmark) error {
    33  	log.Debug("call to update a bookmark")
    34  	err := api.db.UpdateBookmark(originalURL, bookmark)
    35  	log.Debug("result from database for updating a bookmark", "err", err)
    36  	return err
    37  }
    38  
    39  func (api *API) DeleteBookmark(ctx context.Context, url string) error {
    40  	log.Debug("call to remove a bookmark")
    41  	err := api.db.DeleteBookmark(url)
    42  	log.Debug("result from database for remove a bookmark", "err", err)
    43  	return err
    44  }
    45  
    46  func (api *API) RemoveBookmark(ctx context.Context, url string) error {
    47  	log.Debug("call to remove a bookmark logically")
    48  	err := api.db.RemoveBookmark(url)
    49  	log.Debug("result from database for remove a bookmark logically", "err", err)
    50  	return err
    51  }