| 70 | } |
| 71 | |
| 72 | func (p *Repository) FindByID(ctx context.Context, id int32) (Pokemon, error) { |
| 73 | res := Pokemon{} |
| 74 | |
| 75 | err := p.db.QueryRow( |
| 76 | ctx, |
| 77 | "SELECT id, name, types, created_at, updated_at FROM pokemon WHERE id = $1", |
| 78 | id, |
| 79 | ).Scan( |
| 80 | &res.ID, |
| 81 | &res.Name, |
| 82 | &res.Types, |
| 83 | &res.CreatedAt, |
| 84 | &res.UpdatedAt, |
| 85 | ) |
| 86 | |
| 87 | if errors.Is(err, pgx.ErrNoRows) { |
| 88 | return Pokemon{}, ErrNotFound |
| 89 | } else if err != nil { |
| 90 | return Pokemon{}, fmt.Errorf("failed to find pokemon by id: %w", err) |
| 91 | } |
| 92 | |
| 93 | return res, nil |
| 94 | } |
| 95 | |
| 96 | func (p *Repository) Update(ctx context.Context, pokemon Pokemon) error { |
| 97 | res, err := p.db.Exec( |