package org.royaldev.thehumanity.server.controllers;
import org.royaldev.thehumanity.TheHumanity;
import org.royaldev.thehumanity.server.services.cardpack.CardPackService;
import org.royaldev.thehumanity.server.services.channel.ChannelService;
import org.royaldev.thehumanity.server.services.client.ClientService;
import org.royaldev.thehumanity.server.services.game.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.stream.Collectors;
@Controller
@RequestMapping(name = "/")
public class IndexController {
@Autowired
private TheHumanity humanity;
@Autowired
private ChannelService channelService;
@Autowired
private GameService gameService;
@Autowired
private CardPackService cardPackService;
@Autowired
private ClientService clientService;
@RequestMapping(method = RequestMethod.GET)
public String index(final Model model) {
model.addAttribute("humanityVersion", this.humanity.getVersion());
model.addAttribute("clients", this.clientService.getClients());
model.addAttribute("channels", this.clientService.getClients().stream().flatMap(client -> this.channelService.getAll(client).stream()).collect(Collectors.toSet()));
model.addAttribute("games", this.gameService.getAll());
model.addAttribute("cardPacks", this.cardPackService.getAll());
return "index";
}
}