Documentation ¶
Overview ¶
Interfaces to be implemented by different providers
Index ¶
- type BaseSyncNoteProvider
- type GoogleProvider
- func (gp *GoogleProvider) CacheIDGet(noteID int) (int, bool)
- func (gp *GoogleProvider) CacheIDSet(noteID int, noteIDx int, nonBlocked bool)
- func (gp *GoogleProvider) CacheIDUnset(noteID int)
- func (gp *GoogleProvider) CacheUpdAtGet(noteID int) (int64, bool)
- func (gp *GoogleProvider) CacheUpdAtSet(noteID int, updAt int64, nonBlocked bool)
- func (gp *GoogleProvider) CacheUpdAtUnset(noteID int)
- func (gp *GoogleProvider) DeleteNote(id int) error
- func (gp *GoogleProvider) DeleteNoteNotifier() observer.Listener
- func (*GoogleProvider) FilterNotes(notes []model.Note, ids []int) []model.Note
- func (gp *GoogleProvider) GetNote(id int) (*model.Note, error)
- func (gp *GoogleProvider) GetNoteIDs(forceRemote bool) (map[int]int, error)
- func (gp *GoogleProvider) GetNotes(ids ...int) ([]model.Note, error)
- func (gp *GoogleProvider) Init() error
- func (*GoogleProvider) ParseSheetRow(row []interface{}) model.Note
- func (gp *GoogleProvider) PutNote(note *model.Note) error
- func (gp *GoogleProvider) SyncNotes(dbNotes []model.Note) (downloaded []model.Note, err error)
- func (gp *GoogleProvider) UpdateNoteNotifier() observer.Listener
- type SyncNoteProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseSyncNoteProvider ¶
type BaseSyncNoteProvider struct { // NoteIDs is the list of note IDs from the provider NoteIDs []int // Notes is the list of notes from the provider Notes []model.Note }
BaseSyncNoteProvider ....
type GoogleProvider ¶
type GoogleProvider struct { BaseSyncNoteProvider // contains filtered or unexported fields }
func NewGoogleProvider ¶
func NewGoogleProvider( sheetName string, sheetID string, credFilePath string, logger *log.Logger, observer observer.Observer, ) (*GoogleProvider, error)
NewGoogleProvider creates a new Google provider
func (*GoogleProvider) CacheIDGet ¶
func (gp *GoogleProvider) CacheIDGet(noteID int) (int, bool)
CacheIDGet returns the note ID from the cache
func (*GoogleProvider) CacheIDSet ¶
func (gp *GoogleProvider) CacheIDSet(noteID int, noteIDx int, nonBlocked bool)
CacheIDSet update the note ID map
func (*GoogleProvider) CacheIDUnset ¶
func (gp *GoogleProvider) CacheIDUnset(noteID int)
CacheIDUnset removes the note ID from the cache
func (*GoogleProvider) CacheUpdAtGet ¶
func (gp *GoogleProvider) CacheUpdAtGet(noteID int) (int64, bool)
CacheUpdAtGet returns the note updAt from the cache
func (*GoogleProvider) CacheUpdAtSet ¶
func (gp *GoogleProvider) CacheUpdAtSet(noteID int, updAt int64, nonBlocked bool)
CacheUpdAtSet update the note updAt map
func (*GoogleProvider) CacheUpdAtUnset ¶
func (gp *GoogleProvider) CacheUpdAtUnset(noteID int)
CacheUpdAtUnset removes the note updAt from the cache
func (*GoogleProvider) DeleteNote ¶
func (gp *GoogleProvider) DeleteNote(id int) error
DeleteNote deletes the note with the given id
func (*GoogleProvider) DeleteNoteNotifier ¶
func (gp *GoogleProvider) DeleteNoteNotifier() observer.Listener
DeleteNoteNotifier creates a new note observer to notify the provider when a note is deleted
func (*GoogleProvider) FilterNotes ¶
FilterNotes filters the notes by the given ids
func (*GoogleProvider) GetNote ¶
func (gp *GoogleProvider) GetNote(id int) (*model.Note, error)
GetNote returns the note with the given id
func (*GoogleProvider) GetNoteIDs ¶
func (gp *GoogleProvider) GetNoteIDs(forceRemote bool) (map[int]int, error)
GetNoteIDs returns a map of the note IDs and their index in the sheet Note: populates another map with the note IDs and their UpdatedAt field to be used for the sync TODO: find a way to use a single api call to get both the note IDs and the UpdatedAt fields
func (*GoogleProvider) GetNotes ¶
func (gp *GoogleProvider) GetNotes(ids ...int) ([]model.Note, error)
GetNotes fetch from the provider notes with given id or all if no ids is given
func (*GoogleProvider) ParseSheetRow ¶
func (*GoogleProvider) ParseSheetRow(row []interface{}) model.Note
ParseSheetRow maps the sheet row to a Note object
func (*GoogleProvider) PutNote ¶
func (gp *GoogleProvider) PutNote(note *model.Note) error
PutNote pushes a note to the provider if the note does not exist, it will be created
func (*GoogleProvider) SyncNotes ¶
SyncNotes syncs the notes from the provider to the local database and vice versa to correctly sync, we need to get all note ID (columb A of the sheet) and UpdatedAt fields (column G of the sheet) from the provider, then we need to get all notes from the local database, then we need to compare the two lists and sync the notes return the notes to be added to the local database
func (*GoogleProvider) UpdateNoteNotifier ¶
func (gp *GoogleProvider) UpdateNoteNotifier() observer.Listener
UpdateNoteNotifier creates a new note observer to notify the provider when a note is created or updated
type SyncNoteProvider ¶
type SyncNoteProvider interface { // GetNotes returns a list of notes from the provider GetNotes(ids ...int) ([]model.Note, error) // GetNoteIDs returns the list of note IDs from the provider GetNoteIDs(forceRemote bool) ([]int, error) // GetNote returns the note with the given id GetNote(id int) (*model.Note, error) // PutNote puts the given note into the provider PutNote(note *model.Note) error // DeleteNote deletes the note with the given id DeleteNote(id int) error // SyncNotes syncs the notes from the provider with the local database SyncNotes(dbNotes []model.Note) error // Init initializes the provider Init() error }
SyncNoteProvider is the interface that must be implemented by a sync-note provider implementation Note: the relative service must be able to get/put/delete/find notes from the provider