This commit is contained in:
2026-03-12 02:10:57 +01:00
parent a8e769c73d
commit 3c6dd52d8f
29 changed files with 3323 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package json
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/paramah/ai_devs4/s01e02/internal/domain"
)
// Repository implements domain.PersonRepository
type Repository struct{}
// NewRepository creates a new JSON repository
func NewRepository() *Repository {
return &Repository{}
}
// LoadPersons loads persons from a JSON file
func (r *Repository) LoadPersons(ctx context.Context, filePath string) ([]domain.Person, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("reading file: %w", err)
}
var persons []domain.Person
if err := json.Unmarshal(data, &persons); err != nil {
return nil, fmt.Errorf("parsing JSON: %w", err)
}
return persons, nil
}