Thought it best to add some comments
This commit is contained in:
@@ -4,8 +4,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Note represents a single note with its metadata.
|
||||||
type Note struct {
|
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"`
|
LastUpdate time.Time `json:"last_update"`
|
||||||
Content string `json:"content"`
|
// Content is the actual text content of the note.
|
||||||
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,17 @@ import (
|
|||||||
"git.hrafn.xyz/aether/notes/internal/models"
|
"git.hrafn.xyz/aether/notes/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NoteRepository manages operations on notes using a data store.
|
||||||
type NoteRepository struct {
|
type NoteRepository struct {
|
||||||
store NoteStore
|
store NoteStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNoteRepository creates and returns a new NoteRepository instance.
|
||||||
func NewNoteRepository(store NoteStore) *NoteRepository {
|
func NewNoteRepository(store NoteStore) *NoteRepository {
|
||||||
return &NoteRepository{store: store}
|
return &NoteRepository{store: store}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateNote creates a new note with the given content.
|
||||||
func (r *NoteRepository) CreateNote(content string) (models.Note, error) {
|
func (r *NoteRepository) CreateNote(content string) (models.Note, error) {
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return models.Note{}, fmt.Errorf("content cannot be empty")
|
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)
|
return r.store.SaveNote(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNote retrieves a note by its ID.
|
||||||
func (r *NoteRepository) GetNote(id int) (models.Note, error) {
|
func (r *NoteRepository) GetNote(id int) (models.Note, error) {
|
||||||
return r.store.GetNoteByID(id)
|
return r.store.GetNoteByID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListNotes retrieves all notes.
|
||||||
func (r *NoteRepository) ListNotes() ([]models.Note, error) {
|
func (r *NoteRepository) ListNotes() ([]models.Note, error) {
|
||||||
return r.store.GetAllNotes()
|
return r.store.GetAllNotes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateNote updates the content of an existing note.
|
||||||
func (r *NoteRepository) UpdateNote(id int, content string) (models.Note, error) {
|
func (r *NoteRepository) UpdateNote(id int, content string) (models.Note, error) {
|
||||||
if content == "" {
|
if content == "" {
|
||||||
return models.Note{}, fmt.Errorf("content cannot be empty")
|
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)
|
return r.store.SaveNote(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteNote deletes a note by its ID.
|
||||||
func (r *NoteRepository) DeleteNote(id int) error {
|
func (r *NoteRepository) DeleteNote(id int) error {
|
||||||
return r.store.DeleteNoteByID(id)
|
return r.store.DeleteNoteByID(id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ import (
|
|||||||
"git.hrafn.xyz/aether/notes/internal/models"
|
"git.hrafn.xyz/aether/notes/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NoteStore defines the interface for persisting and retrieving notes.
|
||||||
type NoteStore interface {
|
type NoteStore interface {
|
||||||
|
// SaveNote saves a note to the store and returns the saved note.
|
||||||
SaveNote(models.Note) (models.Note, error)
|
SaveNote(models.Note) (models.Note, error)
|
||||||
|
// GetNoteByID retrieves a note by its ID.
|
||||||
GetNoteByID(int) (models.Note, error)
|
GetNoteByID(int) (models.Note, error)
|
||||||
|
// GetAllNotes retrieves all notes from the store.
|
||||||
GetAllNotes() ([]models.Note, error)
|
GetAllNotes() ([]models.Note, error)
|
||||||
|
// DeleteNoteByID deletes a note by its ID.
|
||||||
DeleteNoteByID(int) error
|
DeleteNoteByID(int) error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user