possibly first working draft

This commit is contained in:
2026-02-01 16:55:40 +01:00
parent e27aadc603
commit 92a6f84540
18 changed files with 450 additions and 270 deletions

View File

@ -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))