Created
March 29, 2020 19:51
-
-
Save pnalvarez/4709b861540d724fa3b01b9145b2f25a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol PokemonListInteractorInput { | |
func fetch() | |
func findSortOptions() | |
} | |
protocol PokemonListInteractorOutput: class { | |
func fetched(pokemons: [PokemonEntity]) | |
func foundSortOptions(_ options: [SortType]) | |
} | |
enum SortType: String { | |
case alphabetically = "Alfabetica" | |
case byId = "Por Id" | |
} | |
class PokemonListInteractor: PokemonListInteractorInput { | |
weak var output: PokemonListInteractorOutput? | |
var manager: PokemonListManagerInput | |
var entities: [PokemonEntity] = [] | |
init(manager: PokemonListManagerInput) { | |
self.manager = manager | |
} | |
func fetch() { | |
manager.getPokemons { | |
pokemons in | |
self.entities = PokemonMapper.parse(from: pokemons) | |
self.output?.fetched(pokemons: self.entities) | |
} | |
} | |
func findSortOptions() { | |
output?.foundSortOptions([.alphabetically, .byId]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment