package xyz.danielcortes.controllers.autor;

import java.util.List;
import xyz.danielcortes.framework.BaseTableModel;
import xyz.danielcortes.models.Autor;
import xyz.danielcortes.repository.AutorRepository;
import xyz.danielcortes.views.autor.AutorListPanel;

public class AutorListController {

  private AutorListPanel view;
  private AutorRepository autorRepository;

  public AutorListController(AutorListPanel view) {
    this.view = view;
    this.autorRepository = new AutorRepository();
  }

  public void reload() {
    this.loadAutorTable();
  }

  private void loadAutorTable() {
    List<Autor> autores = this.autorRepository.getAll();
    BaseTableModel<Autor> model = this.view.getAutorModel();
    model.addRows(autores);
  }

  public AutorListPanel getView() {
    return view;
  }
}
