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

Added possibility to assign team to player

parent b7bd53ff
Pipeline #141628 passed with stage
in 1 minute and 5 seconds
package cz.muni.fi.pa165.dto;
public class CreatePlayerDTO extends PlayerDTO {
}
......@@ -5,6 +5,7 @@ import cz.muni.fi.pa165.entity.TeamEntity;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;
......@@ -15,8 +16,6 @@ import java.util.Set;
@Setter
public class PlayerDTO extends PersonDTO {
private TeamEntity team;
private Set<MatchEntity> matches = new HashSet<>();
private int killStat;
......@@ -24,4 +23,10 @@ public class PlayerDTO extends PersonDTO {
private int deathStat;
private int assistStat;
private TeamEntity team;
@NotNull
private String teamId;
}
package cz.muni.fi.pa165.rest.controllers;
import cz.muni.fi.pa165.dto.CreatePlayerDTO;
import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.entity.PlayerEntity;
import cz.muni.fi.pa165.facade.PlayerFacade;
import cz.muni.fi.pa165.rest.RootUris;
import cz.muni.fi.pa165.rest.exception.ResourceAlreadyExistsException;
......@@ -14,9 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping(RootUris.restPlayer)
......
......@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.entity.PlayerEntity;
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 org.springframework.transaction.annotation.Transactional;
......@@ -17,6 +18,8 @@ public class PlayerFacadeImpl implements PlayerFacade {
@Autowired
private PlayerService playerService;
@Autowired
private TeamService teamService;
@Autowired
private BeanMappingService beanMappingService;
......@@ -38,6 +41,7 @@ public class PlayerFacadeImpl implements PlayerFacade {
player.setName(playerDTO.getName());
player.setCountry(playerDTO.getCountry());
player.setTeam(teamService.findById(playerDTO.getTeamId()));
player.setKillStat(playerDTO.getKillStat());
player.setDeathStat(playerDTO.getDeathStat());
player.setAssistStat(playerDTO.getAssistStat());
......
......@@ -67,10 +67,10 @@ public class PlayerController {
return "player/new";
}
//create product
String id = playerFacade.createPlayer(formBean);
String playerID = playerFacade.createPlayer(formBean);
//report success
redirectAttributes.addFlashAttribute("alert_success", "Player " + id + " was created");
return "redirect:" + uriBuilder.path("/player/view/{id}").buildAndExpand(id).encode().toUriString();
redirectAttributes.addFlashAttribute("alert_success", "Player " + formBean.getName() + " was created!");
return "redirect:" + uriBuilder.path("/player/view/{id}").buildAndExpand(playerID).encode().toUriString();
}
@RequestMapping(value = "/delete/{uuid}", method = RequestMethod.POST)
......
......@@ -30,16 +30,17 @@
</div>
<div class="form-group">
<form:label path="team" cssClass="col-sm-2 control-label">Team</form:label>
<form:label path="teamId" cssClass="col-sm-2 control-label">Team</form:label>
<div class="col-sm-10">
<form:select path="team" cssClass="form-control">
<form:select path="teamId" cssClass="form-control">
<c:forEach items="${teams}" var="c">
<form:option value="${c}">${c.name}</form:option>
<form:option value="${c.id}">${c.name}</form:option>
</c:forEach>
</form:select>
<form:errors path="team" cssClass="error"/>
<p class="help-block"><form:errors path="teamId" cssClass="error"/></p>
</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">
......
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