| 40 | } |
| 41 | |
| 42 | func (p *Repository) FindAll(ctx context.Context) ([]Pokemon, error) { |
| 43 | rows, err := p.db.Query(ctx, "SELECT id, name, types, created_at, updated_at FROM pokemon") |
| 44 | if err != nil { |
| 45 | return nil, fmt.Errorf("failed to find all pokemon: %w", err) |
| 46 | } |
| 47 | |
| 48 | defer rows.Close() |
| 49 | res := make([]Pokemon, 0) |
| 50 | |
| 51 | for rows.Next() { |
| 52 | var pokemon Pokemon |
| 53 | |
| 54 | err := rows.Scan( |
| 55 | &pokemon.ID, |
| 56 | &pokemon.Name, |
| 57 | &pokemon.Types, |
| 58 | &pokemon.CreatedAt, |
| 59 | &pokemon.UpdatedAt, |
| 60 | ) |
| 61 | |
| 62 | if err != nil { |
| 63 | return nil, fmt.Errorf("failed to scan pokemon: %w", err) |
| 64 | } |
| 65 | |
| 66 | res = append(res, pokemon) |
| 67 | } |
| 68 | |
| 69 | return res, nil |
| 70 | } |
| 71 | |
| 72 | func (p *Repository) FindByID(ctx context.Context, id int32) (Pokemon, error) { |
| 73 | res := Pokemon{} |