Commit 56720823 authored by Dominik Kozubík's avatar Dominik Kozubík
Browse files

Merge remote-tracking branch 'origin/team_frontend' into frontend_match

# Conflicts:
#	gaming-spring-mvc/src/main/webapp/WEB-INF/tags/pagetemplate.tag
parents 4115ff44 db13bd61
......@@ -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));
......
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;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.util.UriComponentsBuilder;
import javax.validation.Valid;
import java.util.List;
/**
* @author Matus Valko
*/
@Controller
@RequestMapping("/team")
public class TeamController {
@Autowired
private TeamFacade teamFacade;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
List<TeamDTO> teams = teamFacade.findAllTeams();
model.addAttribute("teams", teams);
return "team/list";
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String newTeam(Model model) {
model.addAttribute("teamCreate", new TeamDTO());
return "team/new";
}
@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
public String view(@PathVariable String id, Model model) {
model.addAttribute("team", teamFacade.getTeamById(id));
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) {
//in case of validation error forward back to the the form
if (bindingResult.hasErrors()) {
return "team/new";
}
//create product
String id = teamFacade.createTeam(formBean);
//report success
redirectAttributes.addFlashAttribute("alert_success", "Team " + id + " was created");
return "redirect:" + uriBuilder.path("/team/view/{id}").buildAndExpand(id).encode().toUriString();
}
@RequestMapping(value = "/delete/{uuid}", method = RequestMethod.POST)
public String delete(@PathVariable String uuid, UriComponentsBuilder uriBuilder, RedirectAttributes redirectAttributes) {
TeamDTO player = teamFacade.getTeamById(uuid);
try {
teamFacade.delete(uuid);
redirectAttributes.addFlashAttribute("alert_success", "Team \"" + player.getId() + "\" was deleted.");
} catch (Exception ex) {
redirectAttributes.addFlashAttribute("alert_danger", "Team \"" + player.getId() + "\" cannot be deleted.");
}
return "redirect:" + uriBuilder.path("/team/list").toUriString();
}
}
......@@ -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>
......
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" trimDirectiveWhitespaces="false" session="false" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<my:pagetemplate title="Teams">
<jsp:attribute name="body">
<my:a href="/team/new" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New team
</my:a>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>country</th>
</tr>
</thead>
<tbody>
<c:forEach items="${teams}" var="team">
<tr>
<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>
<td>
<form method="post" action="${pageContext.request.contextPath}/team/delete/${team.id}">
<button type="submit" class="btn btn-primary">Delete</button>
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" trimDirectiveWhitespaces="false" session="false" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<my:pagetemplate title="New Team">
<jsp:attribute name="body">
<form:form method="post" action="${pageContext.request.contextPath}/team/create"
modelAttribute="teamCreate" cssClass="form-horizontal">
<div class="form-group ${name_error?'has-error':''}">
<form:label path="name" cssClass="col-sm-2 control-label">Name</form:label>
<div class="col-sm-10">
<form:input path="name" cssClass="form-control"/>
<form:errors path="name" cssClass="help-block"/>
</div>
</div>
<div class="form-group">
<form:label path="country" cssClass="col-sm-2 control-label">Country</form:label>
<div class="col-sm-10">
<form:select path="country" cssClass="form-control">
<c:forEach items="${countries}" var="c">
<form:option value="${c}">${c}</form:option>
</c:forEach>
</form:select>
<form:errors path="country" cssClass="error"/>
</div>
</div>
<button class="btn btn-primary" type="submit">Create Team</button>
</form:form>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" trimDirectiveWhitespaces="false" session="false" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<my:pagetemplate title="Team Administration">
<jsp:attribute name="body">
<td><c:out value="${team.name}"/></td>
<table class="tablePlayers">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>country</th>
</tr>
</thead>
<tbody>
<tr>
<td><c:out value="${team.id}"/></td>
<td><c:out value="${team.name}"/></td>
<td><c:out value="${player.country}"/></td>
</tr>
</tbody>
</table>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
......@@ -18,7 +18,7 @@
<tr>
<th>id</th>
<th>city</th>
<th>county</th>
<th>country</th>
<th>prize pool</th>
<th>format</th>
<th>capacity</th>
......
......@@ -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="/match/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