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

Fixed delete funcitonality on players

parent fda2af20
Pipeline #141692 passed with stage
in 1 minute and 24 seconds
......@@ -63,11 +63,7 @@ public class BaseDaoImpl<Entity extends BaseEntity> implements BaseDao<Entity> {
@Override
public void remove(Entity entity) {
try {
var attached = findById(entity.getId());
if (attached == null) {
throw new IllegalArgumentException("Cannot delete a record. Given entity does not exist.");
}
em.remove(entity);
em.remove(findById(entity.getId()));
} catch (Exception e) {
throw new DaoDataAccessException(e.getMessage(), e);
}
......
......@@ -37,7 +37,7 @@ public class PlayerEntity extends PersonEntity {
public PlayerEntity() {
}
public PlayerEntity(String name){
super(name);
public PlayerEntity(String id){
super(id);
}
}
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
@Service
@Transactional
......
......@@ -50,8 +50,7 @@ public class PlayerController {
@ModelAttribute("teams")
public List<TeamDTO> teams() {
List<TeamDTO> teams = teamFacade.findAllTeams();
return teams;
return teamFacade.findAllTeams();
}
@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
public String view(@PathVariable String id, Model model) {
......@@ -80,7 +79,7 @@ public class PlayerController {
playerFacade.delete(uuid);
redirectAttributes.addFlashAttribute("alert_success", "Player \"" + player.getId() + "\" was deleted.");
} catch (Exception ex) {
redirectAttributes.addFlashAttribute("alert_danger", "Player \"" + player.getId() + "\" cannot be deleted.");
redirectAttributes.addFlashAttribute("alert_danger", "Player \"" + player.getId() + "\" cannot be deleted." + ex.getMessage());
}
return "redirect:" + uriBuilder.path("/player/list").toUriString();
}
......
......@@ -31,10 +31,18 @@
<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.team.name}"/></td>
<td><c:out value="${player.killStat}"/></td>
<td><c:out value="${player.deathStat}"/></td>
<td><c:out value="${player.assistStat}"/></td>
<td>
<my:a href="/player/view/${player.id}" class="btn btn-primary">View</my:a>
</td>
<td>
<form method="post" action="${pageContext.request.contextPath}/player/delete/${player.id}">
<button type="submit" class="btn btn-primary">Delete</button>
</form>
</td>
</tr>
</c:forEach>
</tbody>
......
......@@ -37,6 +37,7 @@
<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="/team/list"><f:message key="navigation.teams"/></my:a></li>
<li><my:a href="/team/list"><f:message key="navigation.coaches"/></my:a></li>
<li><my:a href="/team/list"><f:message key="navigation.ranklist.teams"/></my:a></li>
</ul>
</li>
......@@ -44,7 +45,6 @@
<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="/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>
......
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