Thought it best to add some comments

This commit is contained in:
Micheal Wilkinson
2026-03-17 21:50:50 +00:00
parent 93ddee80e4
commit dd718c9a73
3 changed files with 18 additions and 2 deletions

View File

@@ -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"`
}

View File

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

View File

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