possibly first working draft
This commit is contained in:
@ -13,6 +13,7 @@ type Storage interface {
|
||||
Delete(id string)
|
||||
Update(id string, n *note.Note)
|
||||
Search(query string) []*note.Note
|
||||
Count() int
|
||||
}
|
||||
|
||||
type NoteStorage struct {
|
||||
@ -23,13 +24,13 @@ func NewNoteStorage() *NoteStorage {
|
||||
return &NoteStorage{Index: make(map[string]*note.Note)}
|
||||
}
|
||||
|
||||
// GetAll returns all notes stored in the index
|
||||
func (ns *NoteStorage) GetAll() []*note.Note {
|
||||
notes := make([]*note.Note, 0, len(ns.Index))
|
||||
var notes []*note.Note
|
||||
|
||||
// Step 3: Iterate over the map
|
||||
for _, value := range ns.Index {
|
||||
notes = append(notes, value)
|
||||
}
|
||||
for _, value := range ns.Index {
|
||||
notes = append(notes, value)
|
||||
}
|
||||
return notes
|
||||
}
|
||||
|
||||
@ -46,6 +47,10 @@ func (ns *NoteStorage) Create(n *note.Note) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ns *NoteStorage) Count() int {
|
||||
return len(ns.Index)
|
||||
}
|
||||
|
||||
func (ns *NoteStorage) Delete(id string) {
|
||||
delete(ns.Index, id)
|
||||
}
|
||||
@ -54,7 +59,7 @@ func (ns *NoteStorage) Update(id string, n *note.Note) {
|
||||
ns.Index[id] = n
|
||||
}
|
||||
|
||||
func (ns *NoteStorage) Search(query string) []*note.Note{
|
||||
func (ns *NoteStorage) Search(query string) []*note.Note {
|
||||
results := []*note.Note{}
|
||||
for _, note := range ns.Index {
|
||||
lowContent := strings.ToLower(string(note.Content))
|
||||
|
||||
@ -35,7 +35,7 @@ func TestNoteStorageDelete(t *testing.T) {
|
||||
ns.Delete(n1.ID)
|
||||
|
||||
if len(ns.Index) > 1 {
|
||||
t.Errorf("Deleting notes should remove from to the storage. Wanted 1, got '%v'", len(ns.Index))
|
||||
t.Errorf("Deleting notes should remove them from to the storage. Wanted 1, got '%v'", len(ns.Index))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user