Deleting notes
This commit is contained in:
@@ -156,7 +156,20 @@ func (s *SQLiteStore) GetAllNotes(ctx context.Context) ([]models.Note, error) {
|
||||
}
|
||||
|
||||
func (s *SQLiteStore) DeleteNoteByID(ctx context.Context, id int) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
result, err := s.write.ExecContext(ctx, `
|
||||
DELETE FROM notes WHERE id = ?;
|
||||
`, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete note: %w", err)
|
||||
}
|
||||
rowsAffected, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get rows affected: %w", err)
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
return fmt.Errorf("note with ID %d not found", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SQLiteStore) validateSchema(ctx context.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user