Contextualise all the things ....
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -18,7 +19,7 @@ func NewNoteRepository(store NoteStore) *NoteRepository {
|
||||
}
|
||||
|
||||
// CreateNote creates a new note with the given content.
|
||||
func (r *NoteRepository) CreateNote(content string) (models.Note, error) {
|
||||
func (r *NoteRepository) CreateNote(ctx context.Context, content string) (models.Note, error) {
|
||||
if content == "" {
|
||||
return models.Note{}, fmt.Errorf("content cannot be empty")
|
||||
}
|
||||
@@ -26,34 +27,34 @@ func (r *NoteRepository) CreateNote(content string) (models.Note, error) {
|
||||
Content: content,
|
||||
LastUpdate: time.Now(),
|
||||
}
|
||||
return r.store.SaveNote(note)
|
||||
return r.store.SaveNote(ctx, note)
|
||||
}
|
||||
|
||||
// GetNote retrieves a note by its ID.
|
||||
func (r *NoteRepository) GetNote(id int) (models.Note, error) {
|
||||
return r.store.GetNoteByID(id)
|
||||
func (r *NoteRepository) GetNote(ctx context.Context, id int) (models.Note, error) {
|
||||
return r.store.GetNoteByID(ctx, id)
|
||||
}
|
||||
|
||||
// ListNotes retrieves all notes.
|
||||
func (r *NoteRepository) ListNotes() ([]models.Note, error) {
|
||||
return r.store.GetAllNotes()
|
||||
func (r *NoteRepository) ListNotes(ctx context.Context) ([]models.Note, error) {
|
||||
return r.store.GetAllNotes(ctx)
|
||||
}
|
||||
|
||||
// UpdateNote updates the content of an existing note.
|
||||
func (r *NoteRepository) UpdateNote(id int, content string) (models.Note, error) {
|
||||
func (r *NoteRepository) UpdateNote(ctx context.Context, id int, content string) (models.Note, error) {
|
||||
if content == "" {
|
||||
return models.Note{}, fmt.Errorf("content cannot be empty")
|
||||
}
|
||||
note, err := r.store.GetNoteByID(id)
|
||||
note, err := r.store.GetNoteByID(ctx, id)
|
||||
if err != nil {
|
||||
return models.Note{}, err
|
||||
}
|
||||
note.Content = content
|
||||
note.LastUpdate = time.Now()
|
||||
return r.store.SaveNote(note)
|
||||
return r.store.SaveNote(ctx, note)
|
||||
}
|
||||
|
||||
// DeleteNote deletes a note by its ID.
|
||||
func (r *NoteRepository) DeleteNote(id int) error {
|
||||
return r.store.DeleteNoteByID(id)
|
||||
func (r *NoteRepository) DeleteNote(ctx context.Context, id int) error {
|
||||
return r.store.DeleteNoteByID(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user