Newer
Older
pokemon-go-trade / internal / pokemon / pokemon.go
package pokemon

import (
	"fmt"
	"git.ssns.se/git/frozendragon/pokemon-go-trade/internal/db"
)

type Package struct {
	Db db.Interface
}

type Interface interface {
	GetAvailablePokemons() (*Pokemons, error)
}

type Pokemons struct {
	Pokemons []Pokemon `json:"pokemons"`
}

type Pokemon struct {
	ID  int    `json:"id"`
	Url string `json:"url"`
}

func (p *Package) GetAvailablePokemons() (*Pokemons, error) {
	dbPokemons, err := p.Db.GetPokemons()
	if err != nil {
		return nil, err
	}
	var pokemons Pokemons
	for _, pokemon := range dbPokemons {
		pokemons.Pokemons = append(pokemons.Pokemons, Pokemon{
			ID:  pokemon.ID,
			Url: fmt.Sprintf("image/%s", pokemon.DefaultImageName),
		})
	}
	return &pokemons, nil
}