Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Matúš Valko
Online Gaming Management System
Commits
e682f12b
Commit
e682f12b
authored
May 20, 2022
by
Adrián Piaček
Browse files
Merge branch 'frontend_players' into 'main'
Frontend players See merge request
!27
parents
296253f4
58bf1cdf
Pipeline
#141785
passed with stage
in 1 minute and 3 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gaming-api/src/main/java/cz/muni/fi/pa165/dto/CreatePlayerDTO.java
deleted
100644 → 0
View file @
296253f4
package
cz.muni.fi.pa165.dto
;
public
class
CreatePlayerDTO
extends
PlayerDTO
{
}
gaming-api/src/main/java/cz/muni/fi/pa165/dto/PlayerDTO.java
View file @
e682f12b
...
...
@@ -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
;
}
gaming-api/src/main/java/cz/muni/fi/pa165/facade/PlayerFacade.java
View file @
e682f12b
...
...
@@ -15,5 +15,7 @@ public interface PlayerFacade {
String
createPlayer
(
PlayerDTO
playerDTO
);
String
editPlayer
(
PlayerDTO
playerDTO
);
void
delete
(
String
uuid
);
}
gaming-persistence/src/main/java/cz/muni/fi/pa165/dao/BaseDaoImpl.java
View file @
e682f12b
...
...
@@ -67,7 +67,7 @@ public class BaseDaoImpl<Entity extends BaseEntity> implements BaseDao<Entity> {
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
);
}
...
...
gaming-persistence/src/main/java/cz/muni/fi/pa165/entity/PlayerEntity.java
View file @
e682f12b
...
...
@@ -37,7 +37,7 @@ public class PlayerEntity extends PersonEntity {
public
PlayerEntity
()
{
}
public
PlayerEntity
(
String
name
){
super
(
name
);
public
PlayerEntity
(
String
id
){
super
(
id
);
}
}
gaming-rest/src/main/java/cz/muni/fi/pa165/rest/controllers/PlayerController.java
View file @
e682f12b
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
)
...
...
gaming-service/src/main/java/cz/muni/fi/pa165/facade/PlayerFacadeImpl.java
View file @
e682f12b
...
...
@@ -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
());
...
...
@@ -45,6 +49,23 @@ public class PlayerFacadeImpl implements PlayerFacade {
playerService
.
create
(
player
);
return
player
.
getId
();
}
@Override
public
String
editPlayer
(
PlayerDTO
playerDTO
)
{
PlayerEntity
player
=
playerService
.
findById
(
playerDTO
.
getId
());
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
());
playerService
.
update
(
player
);
return
player
.
getId
();
}
@Override
public
void
delete
(
String
uuid
)
{
var
player
=
new
PlayerEntity
();
...
...
gaming-spring-mvc/src/main/java/cz/muni/fi/pa165/mvc/controllers/PlayerController.java
View file @
e682f12b
...
...
@@ -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.entity.PlayerEntity
;
import
cz.muni.fi.pa165.enums.CountryEnum
;
import
cz.muni.fi.pa165.facade.PlayerFacade
;
import
cz.muni.fi.pa165.facade.TeamFacade
;
...
...
@@ -43,6 +44,7 @@ public class PlayerController {
model
.
addAttribute
(
"playerCreate"
,
new
PlayerDTO
());
return
"player/new"
;
}
@ModelAttribute
(
"countries"
)
public
CountryEnum
[]
countries
()
{
return
CountryEnum
.
values
();
...
...
@@ -50,8 +52,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
)
{
...
...
@@ -59,6 +60,22 @@ public class PlayerController {
return
"player/view"
;
}
@RequestMapping
(
value
=
"/edit/{id}"
,
method
=
{
RequestMethod
.
POST
,
RequestMethod
.
GET
})
public
String
edit
(
@PathVariable
String
id
,
@Valid
@ModelAttribute
(
"playerEdit"
)
PlayerDTO
formBean
,
BindingResult
bindingResult
,
Model
model
,
RedirectAttributes
redirectAttributes
,
UriComponentsBuilder
uriBuilder
)
{
model
.
addAttribute
(
"player"
,
playerFacade
.
getPlayerById
(
id
));
if
(
bindingResult
.
hasErrors
())
{
return
"player/edit"
;
}
//create product
String
playerID
=
playerFacade
.
editPlayer
(
formBean
);
//report success
redirectAttributes
.
addFlashAttribute
(
"alert_success"
,
"Player "
+
formBean
.
getName
()
+
" was edited!"
);
return
"redirect:"
+
uriBuilder
.
path
(
"/player/view/{id}"
).
buildAndExpand
(
playerID
).
encode
().
toUriString
();
}
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
public
String
create
(
@Valid
@ModelAttribute
(
"playerCreate"
)
PlayerDTO
formBean
,
BindingResult
bindingResult
,
Model
model
,
RedirectAttributes
redirectAttributes
,
UriComponentsBuilder
uriBuilder
)
{
...
...
@@ -67,10 +84,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
)
...
...
@@ -78,9 +95,9 @@ public class PlayerController {
PlayerDTO
player
=
playerFacade
.
getPlayerById
(
uuid
);
try
{
playerFacade
.
delete
(
uuid
);
redirectAttributes
.
addFlashAttribute
(
"alert_success"
,
"Player \""
+
player
.
get
Id
()
+
"\" was deleted."
);
redirectAttributes
.
addFlashAttribute
(
"alert_success"
,
"Player \""
+
player
.
get
Name
()
+
"\" was deleted."
);
}
catch
(
Exception
ex
)
{
redirectAttributes
.
addFlashAttribute
(
"alert_danger"
,
"Player \""
+
player
.
get
Id
()
+
"\" cannot be deleted."
);
redirectAttributes
.
addFlashAttribute
(
"alert_danger"
,
"Player \""
+
player
.
get
Name
()
+
"\" cannot be deleted."
+
ex
.
getMessage
()
);
}
return
"redirect:"
+
uriBuilder
.
path
(
"/player/list"
).
toUriString
();
}
...
...
gaming-spring-mvc/src/main/webapp/WEB-INF/jsp/player/edit.jsp
0 → 100644
View file @
e682f12b
<%@ 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=
"Player Administration"
>
<jsp:attribute
name=
"body"
>
<form:form
method=
"post"
action=
"
${
pageContext
.
request
.
contextPath
}
/player/edit/${player.id}"
modelAttribute=
"playerEdit"
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"
value=
"
${
player
.
name
}
"
/>
<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
}
"
>
${playerEdit.country}
</form:option>
</c:forEach>
</form:select>
<form:errors
path=
"country"
cssClass=
"error"
/>
</div>
</div>
<div
class=
"form-group"
>
<form:label
path=
"teamId"
cssClass=
"col-sm-2 control-label"
>
Team
</form:label>
<div
class=
"col-sm-10"
>
<form:select
path=
"teamId"
cssClass=
"form-control"
value=
"
${
player
.
team
.
name
}
"
>
<c:forEach
items=
"
${
teams
}
"
var=
"c"
>
<form:option
value=
"
${
c
.
id
}
"
>
${c.name}
</form:option>
</c:forEach>
</form:select>
<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"
>
<form:input
path=
"killStat"
cssClass=
"form-control"
value=
"
${
player
.
killStat
}
"
/>
<form:errors
path=
"killStat"
cssClass=
"help-block"
/>
</div>
</div>
<div
class=
"form-group ${deathStat_error?'has-error':''}"
>
<form:label
path=
"deathStat"
cssClass=
"col-sm-2 control-label"
>
Death stat
</form:label>
<div
class=
"col-sm-10"
>
<form:input
path=
"deathStat"
cssClass=
"form-control"
value=
"
${
player
.
deathStat
}
"
/>
<form:errors
path=
"deathStat"
cssClass=
"help-block"
/>
</div>
</div>
<div
class=
"form-group ${assistStat_error?'has-error':''}"
>
<form:label
path=
"assistStat"
cssClass=
"col-sm-2 control-label"
>
Assist stat
</form:label>
<div
class=
"col-sm-10"
>
<form:input
path=
"assistStat"
cssClass=
"form-control"
value=
"
${
player
.
assistStat
}
"
/>
<form:errors
path=
"assistStat"
cssClass=
"help-block"
/>
</div>
</div>
<button
class=
"btn btn-primary"
type=
"submit"
>
Update Player
</button>
</form:form>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
gaming-spring-mvc/src/main/webapp/WEB-INF/jsp/player/list.jsp
View file @
e682f12b
...
...
@@ -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>
...
...
gaming-spring-mvc/src/main/webapp/WEB-INF/jsp/player/new.jsp
View file @
e682f12b
...
...
@@ -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=
"team
Id
"
cssClass=
"col-sm-2 control-label"
>
Team
</form:label>
<div
class=
"col-sm-10"
>
<form:select
path=
"team"
cssClass=
"form-control"
>
<form:select
path=
"team
Id
"
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=
"team
Id
"
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"
>
...
...
gaming-spring-mvc/src/main/webapp/WEB-INF/jsp/player/view.jsp
View file @
e682f12b
...
...
@@ -7,11 +7,22 @@
<my:pagetemplate
title=
"Player Administration"
>
<jsp:attribute
name=
"body"
>
<form
method=
"post"
action=
"${pageContext.request.contextPath}/player/delete/${player.id}"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
Delete
</button>
</form>
<div
class=
"row"
>
<div
class=
"col-xs-12 col-sm-6 col-md-2 col-lg-1"
>
<form
method=
"post"
action=
"${pageContext.request.contextPath}/player/delete/${player.id}"
>
<button
type=
"submit"
class=
"btn btn-primary "
>
<span
class=
"glyphicon glyphicon-minus"
></span>
Delete
</button>
</form>
</div>
<div
class=
"col-xs-12 col-sm-6 col-md-2 col-lg-1"
>
<form
method=
"post"
action=
"${pageContext.request.contextPath}/player/edit/${player.id}"
>
<button
type=
"submit"
class=
"btn btn-primary "
>
<span
class=
"glyphicon glyphicon-asterisk"
></span>
Edit
</button>
</form>
</div>
</div>
<table
class=
"table"
>
<thead>
...
...
@@ -38,5 +49,10 @@
</tbody>
</table>
<my:a
href=
"/player/list"
class=
"btn btn-primary"
>
<span
class=
"glyphicon glyphicon-user"
aria-hidden=
"true"
></span>
List all players
</my:a>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
gaming-spring-mvc/src/main/webapp/WEB-INF/tags/pagetemplate.tag
View file @
e682f12b
...
...
@@ -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>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment