snote

package
v0.0.0-...-a40ead8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicate    = errors.New("record already exists")
	ErrNotExists    = errors.New("row not exists")
	ErrUpdateFailed = errors.New("update failed")
	ErrDeleteFailed = errors.New("delete failed")
)

Functions

This section is empty.

Types

type Note

type Note struct {
	ID      string `json:"id"`
	Content string `json:"content"`
}

func (*Note) Equal

func (n *Note) Equal(cn *Note) bool

Equal is a utility function to help when comparing two notes.

type NotePingResponse

type NotePingResponse struct {
	Exists    bool      `json:"exists"`
	Deleted   bool      `json:"consumed"`
	DeletedAt time.Time `json:"consumedAt"`
}

NotePingResponse will be the response when calling PingNote

type NoteService

type NoteService struct {
	// contains filtered or unexported fields
}

NoteService works as a wrapper around package specific functionality.

External calls are expected to go through this service

func NewNoteService

func NewNoteService(repo *SQLiteRepository) *NoteService

NewNoteService makes one

func NewNoteServiceWithProductionRepo

func NewNoteServiceWithProductionRepo() *NoteService

func (*NoteService) ConsumeNote

func (svc *NoteService) ConsumeNote(noteID string) (*Note, error)

ConsumeNote will try retrieving the note with the given ID. If it is successful in fetching the note it will also be deleted from the datastore. Meaning that when the note is returned from this function it does no longer exist in the database and cannot be retrieved agian.

func (*NoteService) NewNote

func (svc *NoteService) NewNote(content string) (string, error)

NewNote will create a note with the given content and stor this note in the datastore.

The function returns the ID of the newly created note.

func (*NoteService) PingNote

func (svc *NoteService) PingNote(noteID string) (*NotePingResponse, error)

PingNote checks if the note with the given ID exists and what "state" the note is in.

States:

1. Does not exist

2. Exists and unread

3. Exists and read

type SQLiteRepository

type SQLiteRepository struct {
	// contains filtered or unexported fields
}

func NewSqliteDefaultRepo

func NewSqliteDefaultRepo() *SQLiteRepository

NewSqliteDefaultRepo makes a repo that can be used for storing data.

This function will check if a sqlite DB-file exists. If not it will run the migration process in order to setup the DB accordingly.

func NewSqliteTestRepo

func NewSqliteTestRepo() *SQLiteRepository

func (*SQLiteRepository) ConsumeNote

func (r *SQLiteRepository) ConsumeNote(noteID string) (*Note, error)

func (*SQLiteRepository) CreateNote

func (r *SQLiteRepository) CreateNote(n *Note) error

func (*SQLiteRepository) Migrate

func (r *SQLiteRepository) Migrate() error

func (*SQLiteRepository) PingNote

func (r *SQLiteRepository) PingNote(noteID string) (*sql.NullTime, error)

PingNote will check if a note exists for the given noteID.

If the function returns without error one should check the value of the returned NullTime pointer.

+ If the pointer is nil then there is no note with that id.

+ If NullTime.Valid is true then the note exists and has been "deleted" i.e. read.

+ If NullTime.Valid is false then the note exists and can still be read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL