Commit b7bd53ff authored by Adrián Piaček's avatar Adrián Piaček
Browse files

Added sample data for players and team

parent 8e23f5c0
Pipeline #141588 passed with stage
in 1 minute and 1 second
......@@ -16,4 +16,6 @@ public interface TeamFacade {
TeamDTO getTeamById(String uuid);
String createTeam(TeamDTO TeamDTO);
void delete(String uuid);
}
......@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.entity.PlayerEntity;
import cz.muni.fi.pa165.entity.TeamEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.services.player.PlayerService;
import cz.muni.fi.pa165.services.team.TeamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,25 +25,31 @@ public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
@Autowired
private PlayerService playerService;
@Autowired
private TeamService teamService;
@Override
@SuppressWarnings("unused")
public void loadData() throws IOException {
TeamEntity team = new TeamEntity();
team.setName("Autisti");
TeamEntity g2_esports = team("g2_esports", CountryEnum.GERMANY);
TeamEntity skt_t1 = team("skt_t1", CountryEnum.SOUTH_KOREA);
PlayerEntity crimsix = player("9384b466-badf-40ca-bbeb-4d8f6eb98042", "Ian Porter",
CountryEnum.AFGHANISTAN,5,6,7);
CountryEnum.AFGHANISTAN,g2_esports,5,6,7);
PlayerEntity JJoNak = player("6e374a4e-5213-4581-847c-45f9e73ffe90", "Bang Seong-hyun ",
CountryEnum.ALBANIA,5,6,7);
CountryEnum.ALBANIA,skt_t1,5,6,7);
log.info("Loaded Sample Players.");
}
private PlayerEntity player(String uuid, String name, CountryEnum country, int killStat, int deathStat, int assistStat) {
private PlayerEntity player(String uuid, String name, CountryEnum country, TeamEntity team, int killStat, int deathStat, int assistStat) {
PlayerEntity player = new PlayerEntity();
player.setId(uuid);
player.setName(name);
player.setCountry(country);
player.setTeam(team);
player.setKillStat(killStat);
player.setDeathStat(deathStat);
player.setAssistStat(assistStat);
......@@ -50,4 +57,12 @@ public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
return player;
}
private TeamEntity team(String name, CountryEnum country) {
TeamEntity team = new TeamEntity();
team.setName(name);
team.setCountry(country);
teamService.create(team);
return team;
}
}
package cz.muni.fi.pa165.facade;
import cz.muni.fi.pa165.dto.TeamDTO;
import cz.muni.fi.pa165.entity.PlayerEntity;
import cz.muni.fi.pa165.entity.TeamEntity;
import cz.muni.fi.pa165.services.BeanMappingService;
import cz.muni.fi.pa165.services.player.PlayerService;
import cz.muni.fi.pa165.services.team.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
......@@ -13,18 +17,37 @@ import java.util.UUID;
@Service
@Transactional
public class TeamFacadeImpl implements TeamFacade {
@Autowired
private TeamService teamService;
@Autowired
private BeanMappingService beanMappingService;
@Override
public List<TeamDTO> findAllTeams() {
return null;
return beanMappingService.mapTo(teamService.findAll(), TeamDTO.class);
}
@Override
public TeamDTO getTeamById(String uuid) {
return null;
TeamEntity team = teamService.findById(uuid);
return (team == null) ? null : beanMappingService.mapTo(team, TeamDTO.class);
}
@Override
public String createTeam(TeamDTO TeamDTO) {
return null;
TeamEntity team = new TeamEntity();
team.setName(TeamDTO.getName());
team.setCountry(TeamDTO.getCountry());
teamService.create(team);
return team.getId();
}
@Override
public void delete(String uuid) {
var team = new TeamEntity();
team.setId(uuid);
teamService.remove(team);
}
}
package cz.muni.fi.pa165.mvc.controllers;
import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.dto.TournamentDTO;
import cz.muni.fi.pa165.dto.TeamDTO;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.facade.PlayerFacade;
import cz.muni.fi.pa165.facade.TournamentFacade;
import cz.muni.fi.pa165.facade.TeamFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -18,7 +18,6 @@ import org.springframework.web.util.UriComponentsBuilder;
import javax.validation.Valid;
import java.util.List;
import java.util.UUID;
/**
* @author Adrian Piacek
......@@ -29,6 +28,8 @@ public class PlayerController {
@Autowired
private PlayerFacade playerFacade;
@Autowired
private TeamFacade teamFacade;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
......@@ -47,6 +48,11 @@ public class PlayerController {
return CountryEnum.values();
}
@ModelAttribute("teams")
public List<TeamDTO> teams() {
List<TeamDTO> teams = teamFacade.findAllTeams();
return teams;
}
@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
public String view(@PathVariable String id, Model model) {
model.addAttribute("player", playerFacade.getPlayerById(id));
......
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.mvc.controllers;
import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.dto.TeamDTO;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.facade.PlayerFacade;
import cz.muni.fi.pa165.facade.TeamFacade;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -47,6 +48,11 @@ public class TeamController {
return "team/view";
}
@ModelAttribute("countries")
public CountryEnum[] countries() {
return CountryEnum.values();
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Valid @ModelAttribute("playerCreate") TeamDTO formBean, BindingResult bindingResult,
Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) {
......
......@@ -19,6 +19,7 @@
<th>id</th>
<th>name</th>
<th>country</th>
<th>team</th>
<th>killStat</th>
<th>deathStat</th>
<th>assistStat</th>
......@@ -30,6 +31,7 @@
<td><c:out value="${player.id}"/></td>
<td><c:out value="${player.name}"/></td>
<td><c:out value="${player.country}"/></td>
<td><c:out value="${player.team.name}"/></td
<td><c:out value="${player.killStat}"/></td>
<td><c:out value="${player.deathStat}"/></td>
<td><c:out value="${player.assistStat}"/></td>
......
......@@ -28,6 +28,18 @@
<form:errors path="country" cssClass="error"/>
</div>
</div>
<div class="form-group">
<form:label path="team" cssClass="col-sm-2 control-label">Team</form:label>
<div class="col-sm-10">
<form:select path="team" cssClass="form-control">
<c:forEach items="${teams}" var="c">
<form:option value="${c}">${c.name}</form:option>
</c:forEach>
</form:select>
<form:errors path="team" cssClass="error"/>
</div>
</div>
<div class="form-group ${killStat_error?'has-error':''}" >
<form:label path="killStat" cssClass="col-sm-2 control-label">Kill stat</form:label>
<div class="col-sm-10">
......
......@@ -19,6 +19,7 @@
<th>id</th>
<th>name</th>
<th>country</th>
<th>team</th>
<th>killStat</th>
<th>deathStat</th>
<th>assistStat</th>
......@@ -29,6 +30,7 @@
<td><c:out value="${player.id}"/></td>
<td><c:out value="${player.name}"/></td>
<td><c:out value="${player.country}"/></td>
<td><c:out value="${player.team.name}"/></td>
<td><c:out value="${player.killStat}"/></td>
<td><c:out value="${player.deathStat}"/></td>
<td><c:out value="${player.assistStat}"/></td>
......
......@@ -10,23 +10,23 @@
<my:a href="/team/new" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New tournament
New team
</my:a>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>city</th>
<th>name</th>
<th>country</th>
</tr>
</thead>
<tbody>
<c:forEach items="${teams}" var="team">
<tr>
<td>${team.id}</td>
<td><c:out value="${tournament.city}"/></td>
<td><c:out value="${tournament.country}"/></td>
<td><c:out value="${team.id}"/></td>
<td><c:out value="${team.name}"/></td>
<td><c:out value="${team.country}"/></td>
<td>
<my:a href="/team/view/${team.id}" class="btn btn-primary">View</my:a>
</td>
......
......@@ -36,19 +36,25 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.teams"/><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><my:a href="/tournament/list"><f:message key="navigation.coaches"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.ranklist.teams"/></my:a></li>
<li><my:a href="/team/list"><f:message key="navigation.teams"/></my:a></li>
<li><my:a href="/team/list"><f:message key="navigation.ranklist.teams"/></my:a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.players"/><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><my:a href="/player/list"><f:message key="navigation.players"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.ranklist.players"/></my:a></li>
<li><my:a href="/player/list"><f:message key="navigation.coaches"/></my:a></li>
<li><my:a href="/player/list"><f:message key="navigation.ranklist.players"/></my:a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.tournaments"/><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><my:a href="/tournament/list"><f:message key="navigation.tournaments"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.matches"/></my:a></li>
</ul>
</li>
<li><my:a href="/tournament/list"><f:message key="navigation.tournaments"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.matches"/></my:a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment