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

match fixes

parent 56720823
Pipeline #141746 passed with stage
in 1 minute and 26 seconds
......@@ -5,6 +5,8 @@ import cz.muni.fi.pa165.entity.MatchEntity;
import cz.muni.fi.pa165.entity.TournamentEntity;
import cz.muni.fi.pa165.services.BeanMappingService;
import cz.muni.fi.pa165.services.match.MatchService;
import cz.muni.fi.pa165.services.team.TeamService;
import cz.muni.fi.pa165.services.tournament.TournamentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -25,6 +27,11 @@ public class MatchFacadeImpl implements MatchFacade {
@Autowired
private BeanMappingService beanMappingService;
@Autowired
private TeamService teamService;
@Autowired
private TournamentService tournamentService;
@Override
public List<MatchDTO> findAllMatches() {
......@@ -44,7 +51,7 @@ public class MatchFacadeImpl implements MatchFacade {
match.setPlayerList(matchDTO.getPlayerList());
match.setPlayers(matchDTO.getPlayers());
match.setTeams(matchDTO.getTeams());
match.setTournament(matchDTO.getTournament());
match.setTournament(tournamentService.findById(matchDTO.getTournament().getId()));
matchService.create(match);
......
......@@ -37,7 +37,7 @@ public class MatchController {
private TeamFacade teamFacade;
@ModelAttribute("tournaments")
public List<TournamentDTO> countries() {
public List<TournamentDTO> tournaments() {
return tournamentFacade.findAllTournament();
}
......@@ -55,7 +55,7 @@ public class MatchController {
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String newMatch(Model model) {
model.addAttribute("createMatch", new MatchDTO());
model.addAttribute("matchCreate", new MatchDTO());
return "match/new";
}
......@@ -80,15 +80,12 @@ public class MatchController {
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Valid @ModelAttribute("matchCreate") MatchDTO formBean, BindingResult bindingResult,
Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) {
//in case of validation error forward back to the the form
//in case of validation error forward back to the form
if (bindingResult.hasErrors()) {
System.err.println("tu som 0");
return "match/new";
}
//create tournament
System.err.println("tu som 1");
//create match
String uuid = matchFacade.createMatch(formBean);
System.err.println("tu som 2");
//report success
redirectAttributes.addFlashAttribute("alert_success", "Match " + uuid + " was created");
return "redirect:" + uriBuilder.path("/match/view/{id}").buildAndExpand(uuid).encode().toUriString();
......
......@@ -9,13 +9,13 @@
<jsp:attribute name="body">
<form:form method="post" action="${pageContext.request.contextPath}/match/create"
modelAttribute="createMatch" cssClass="form-horizontal">
modelAttribute="matchCreate" cssClass="form-horizontal">
<div class="form-group">
<form:label path="tournament" cssClass="col-sm-2 control-label">Tournament</form:label>
<div class="col-sm-10">
<form:select path="tournament" required="required" cssClass="form-control">
<c:forEach items="${tournaments}" var="tournament">
<form:option value="${tournament.id}">${tournament.id}</form:option>
<c:forEach items="${tournaments}" var="t">
<form:option value="${t}">${t.id}</form:option>
</c:forEach>
</form:select>
<form:errors path="tournament" cssClass="error"/>
......@@ -26,7 +26,7 @@
<div class="col-sm-10">
<form:select path="teams" required="required" cssClass="form-control">
<c:forEach items="${teams}" var="team">
<form:option value="${team.name}">${team.name}</form:option>
<form:option value="${team}">${team.name}</form:option>
</c:forEach>
</form:select>
<form:errors path="teams" cssClass="error"/>
......
......@@ -52,7 +52,7 @@
<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>
<li><my:a href="/match/list"><f:message key="navigation.matches"/></my:a></li>
</ul>
</li>
</ul>
......
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