diff --git a/internal/models/note.go b/internal/models/note.go index 6edd3a6..76865fe 100644 --- a/internal/models/note.go +++ b/internal/models/note.go @@ -4,8 +4,12 @@ import ( "time" ) +// Note represents a single note with its metadata. type Note struct { - ID int `json:"id"` + // ID is the unique identifier of the note. + ID int `json:"id"` + // LastUpdate is the timestamp of when the note was last modified. LastUpdate time.Time `json:"last_update"` - Content string `json:"content"` + // Content is the actual text content of the note. + Content string `json:"content"` } diff --git a/internal/repository/notes.go b/internal/repository/notes.go index 8f7dc66..2fda77e 100644 --- a/internal/repository/notes.go +++ b/internal/repository/notes.go @@ -7,14 +7,17 @@ import ( "git.hrafn.xyz/aether/notes/internal/models" ) +// NoteRepository manages operations on notes using a data store. type NoteRepository struct { store NoteStore } +// NewNoteRepository creates and returns a new NoteRepository instance. func NewNoteRepository(store NoteStore) *NoteRepository { return &NoteRepository{store: store} } +// CreateNote creates a new note with the given content. func (r *NoteRepository) CreateNote(content string) (models.Note, error) { if content == "" { return models.Note{}, fmt.Errorf("content cannot be empty") @@ -26,14 +29,17 @@ func (r *NoteRepository) CreateNote(content string) (models.Note, error) { return r.store.SaveNote(note) } +// GetNote retrieves a note by its ID. func (r *NoteRepository) GetNote(id int) (models.Note, error) { return r.store.GetNoteByID(id) } +// ListNotes retrieves all notes. func (r *NoteRepository) ListNotes() ([]models.Note, error) { return r.store.GetAllNotes() } +// UpdateNote updates the content of an existing note. func (r *NoteRepository) UpdateNote(id int, content string) (models.Note, error) { if content == "" { return models.Note{}, fmt.Errorf("content cannot be empty") @@ -47,6 +53,7 @@ func (r *NoteRepository) UpdateNote(id int, content string) (models.Note, error) return r.store.SaveNote(note) } +// DeleteNote deletes a note by its ID. func (r *NoteRepository) DeleteNote(id int) error { return r.store.DeleteNoteByID(id) } diff --git a/internal/repository/notestore.go b/internal/repository/notestore.go index cb85546..e60522e 100644 --- a/internal/repository/notestore.go +++ b/internal/repository/notestore.go @@ -4,9 +4,14 @@ import ( "git.hrafn.xyz/aether/notes/internal/models" ) +// NoteStore defines the interface for persisting and retrieving notes. type NoteStore interface { + // SaveNote saves a note to the store and returns the saved note. SaveNote(models.Note) (models.Note, error) + // GetNoteByID retrieves a note by its ID. GetNoteByID(int) (models.Note, error) + // GetAllNotes retrieves all notes from the store. GetAllNotes() ([]models.Note, error) + // DeleteNoteByID deletes a note by its ID. DeleteNoteByID(int) error }