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

Final touches

parent 400ee397
Pipeline #141926 passed with stage
in 1 minute and 23 seconds
......@@ -15,6 +15,8 @@ public class TournamentDTO extends BaseDTO {
private String city;
private String name;
private CountryEnum country;
private double prizePool;
......@@ -24,4 +26,5 @@ public class TournamentDTO extends BaseDTO {
private int teamCapacity;
private TeamEntity winner;
}
......@@ -21,6 +21,9 @@ public class TournamentEntity extends BaseEntity {
@Column(nullable = false, unique = true)
private String city;
@Column(nullable = false)
private String name;
private CountryEnum country;
private double prizePool;
private TournamentFormat tournamentFormat;
......@@ -56,9 +59,10 @@ public class TournamentEntity extends BaseEntity {
public TournamentEntity() {
}
public TournamentEntity(String city, CountryEnum country,
public TournamentEntity(String name, String city, CountryEnum country,
int pricePool, TournamentFormat format, int capacity) {
this.name = name;
this.city = city;
this.country = country;
this.prizePool = pricePool;
......
......@@ -90,7 +90,7 @@ public class MatchDaoTest extends AbstractTransactionalTestNGSpringContextTests
void update() {
MatchEntity match = new MatchEntity();
matchDao.create(match);
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
match.setTournament(tournament);
TeamEntity teamA = new TeamEntity();
......
......@@ -47,7 +47,7 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void create() {
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
assertThat(tournament.getId()).isNotNull();
Assertions.assertThat(tournamentDao.findAll()).hasSize(1);
......@@ -55,7 +55,7 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void findByIdExisting() {
TournamentEntity tournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournament = new TournamentEntity("MSI 2","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentDao.create(tournament);
var find = tournamentDao.findById(tournament.getId());
assertThat(find).isEqualTo(tournament);
......@@ -72,9 +72,9 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void findAll() {
TournamentEntity tournamentA =
new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournamentB =
new TournamentEntity("Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
new TournamentEntity("MSI 2","Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
tournamentDao.create(tournamentA);
tournamentDao.create(tournamentB);
Assertions.assertThat(tournamentDao.findAll()).hasSize(2);
......@@ -84,6 +84,7 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
void update() {
TournamentEntity tournamentEntity = new TournamentEntity();
tournamentDao.create(tournamentEntity);
tournamentEntity.setName("MSI");
tournamentEntity.setCity("Bratislava");
tournamentEntity.setPrizePool(25.0);
tournamentEntity.setTeamCapacity(7);
......@@ -94,9 +95,9 @@ public class TournamentDaoTest extends AbstractTransactionalTestNGSpringContextT
@Test
void delete() {
TournamentEntity tournamentA =
new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
TournamentEntity tournamentB =
new TournamentEntity("Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
new TournamentEntity("MSI 2","Brno", CountryEnum.CZECH_REPUBLIC, 5, TournamentFormat.DEFAULT, 15);
tournamentDao.create(tournamentA);
tournamentDao.create(tournamentB);
tournamentDao.remove(tournamentA);
......
......@@ -62,7 +62,7 @@ public class MatchEntityTest {
teamE.setMatches(new HashSet<>(List.of(matchB)));
teamF.setMatches(new HashSet<>(List.of(matchC)));
tournamentA = new TournamentEntity("Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
tournamentA = new TournamentEntity("MSI","Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
matchA.setTournament(tournamentA);
matchB.setTournament(tournamentA);
tournamentA.setMatches(new HashSet<>(List.of(matchA, matchB)));
......
......@@ -70,7 +70,7 @@ public class TeamCoachEntityTest {
teamCoachE.setTeam(teamC);
teamCoachF.setTeam(teamC);
teamCoachE.removeCoachFromTheTeam(teamCoachF);
tournamentA = new TournamentEntity("Zilina", CountryEnum.SLOVAKIA,1000, TournamentFormat.DEFAULT,5);
tournamentA = new TournamentEntity("MSI","Zilina", CountryEnum.SLOVAKIA,1000, TournamentFormat.DEFAULT,5);
teamCoachE.signForTournament(tournamentA);
tournamentA.addTeamToTournament(teamC);
......
......@@ -33,8 +33,8 @@ public class TeamEntityTest {
void init() {
teamCoach = new TeamCoachEntity("Foo");
teamEntity = new TeamEntity("Autisti III", new HashSet<>(List.of(teamCoach)));
plannedTournament = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
completedTournament = new TournamentEntity("Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
plannedTournament = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
completedTournament = new TournamentEntity("MSI 2","Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
playerA = new PlayerEntity("Bar");
teamCoach.setTeam(teamEntity);
......
......@@ -30,6 +30,7 @@ public class TournamentEntityTest {
@BeforeAll
void init() {
tournament = new TournamentEntity();
tournament.setName("MSI 2");
tournament.setTournamentFormat(TournamentFormat.DEFAULT);
tournament.setCountry(CountryEnum.SLOVAKIA);
tournament.setCity("Pardubice");
......@@ -37,6 +38,7 @@ public class TournamentEntityTest {
tournament.setTeamCapacity(30);
relational = new TournamentEntity();
relational.setName("MSI");
relational.setCity("Beijing");
relational.setTeamCapacity(20);
relational.setCountry(CountryEnum.CHINA);
......
......@@ -34,6 +34,7 @@ public class TournamentOrganizerEntityTest {
@BeforeAll
void init() {
tournamentA = new TournamentEntity();
tournamentA.setName("MSI");
tournamentA.setTournamentFormat(TournamentFormat.DEFAULT);
tournamentA.setCountry(CountryEnum.SLOVAKIA);
tournamentA.setCity("Zilina");
......@@ -41,6 +42,7 @@ public class TournamentOrganizerEntityTest {
tournamentA.setTeamCapacity(30);
tournamentB = new TournamentEntity();
tournamentB.setName("MSI 2");
tournamentB.setTournamentFormat(TournamentFormat.DEFAULT);
tournamentB.setCountry(CountryEnum.CZECH_REPUBLIC);
tournamentB.setCity("Kolin");
......@@ -48,6 +50,7 @@ public class TournamentOrganizerEntityTest {
tournamentB.setTeamCapacity(2);
tournamentC = new TournamentEntity();
tournamentC.setName("MSI 3");
tournamentC.setTournamentFormat(TournamentFormat.DEFAULT);
tournamentC.setCountry(CountryEnum.ZIMBABWE);
tournamentC.setCity("Zimbibumbo");
......@@ -63,8 +66,8 @@ public class TournamentOrganizerEntityTest {
organizerA.setOrganizedTournaments(new HashSet<>(List.of(tournamentA, tournamentC)));
organizerA.setFutureTournaments(new HashSet<>(List.of(tournamentB)));
tournamentD = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentE = new TournamentEntity("Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
tournamentD = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentE = new TournamentEntity("MSI 2","Osaka", CountryEnum.SLOVAKIA, 1000, TournamentFormat.DEFAULT, 10);
organizerB = new TournamentOrganizerEntity("AutistaSpomaleny");
organizerB.setCountry(CountryEnum.UGANDA);
organizerB.addOrganizedTournament(tournamentD);
......@@ -103,6 +106,7 @@ public class TournamentOrganizerEntityTest {
assertEquals(tournament.getTournamentFormat(), TournamentFormat.DEFAULT);
assertEquals(tournament.getCountry(), CountryEnum.SLOVAKIA);
assertEquals(tournament.getCity(), "Zilina");
assertEquals(tournament.getName(), "MSI");
assertEquals(tournament.getPrizePool(), 50);
assertEquals(tournament.getTeamCapacity(), 30);
......@@ -110,6 +114,7 @@ public class TournamentOrganizerEntityTest {
assertEquals(tournament.getTournamentFormat(), TournamentFormat.DEFAULT);
assertEquals(tournament.getCountry(), CountryEnum.CZECH_REPUBLIC);
assertEquals(tournament.getCity(), "Kolin");
assertEquals(tournament.getName(), "MSI 2");
assertEquals(tournament.getPrizePool(), 15);
assertEquals(tournament.getTeamCapacity(), 2);
......@@ -117,6 +122,7 @@ public class TournamentOrganizerEntityTest {
assertEquals(tournament.getTournamentFormat(), TournamentFormat.DEFAULT);
assertEquals(tournament.getCountry(), CountryEnum.ZIMBABWE);
assertEquals(tournament.getCity(), "Zimbibumbo");
assertEquals(tournament.getName(), "MSI 3");
assertEquals(tournament.getPrizePool(), 5000);
assertEquals(tournament.getTeamCapacity(), 20);
......
......@@ -3,9 +3,12 @@ package cz.muni.fi.pa165.sampledata;
import com.google.common.hash.Hashing;
import cz.muni.fi.pa165.entity.PlayerEntity;
import cz.muni.fi.pa165.entity.TeamEntity;
import cz.muni.fi.pa165.entity.TournamentEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.enums.TournamentFormat;
import cz.muni.fi.pa165.services.player.PlayerService;
import cz.muni.fi.pa165.services.team.TeamService;
import cz.muni.fi.pa165.services.tournament.TournamentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,6 +35,9 @@ public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
@Autowired
private TeamService teamService;
@Autowired
private TournamentService tournamentService;
@Override
@SuppressWarnings("unused")
public void loadData() throws IOException {
......@@ -44,6 +50,9 @@ public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
PlayerEntity JJoNak = player("6e374a4e-5213-4581-847c-45f9e73ffe90", "Bang Seong-hyun ", "bang",
"heslo", true, CountryEnum.ALBANIA, skt_t1, 15, 25, 100);
log.info("Loaded Sample Players.");
TournamentEntity msi = tournament("MSI", "Ottawa" ,CountryEnum.SOUTH_KOREA, 10000, TournamentFormat.DEFAULT, 10);
TournamentEntity worlds = tournament("Worlds", "Zilina", CountryEnum.CHINA, 50000, TournamentFormat.DEFAULT, 6);
}
private PlayerEntity player(String uuid, String name, String username, String password, boolean admin,
......@@ -72,4 +81,17 @@ public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
return team;
}
private TournamentEntity tournament(String name, String city, CountryEnum country, double prizePool, TournamentFormat format,
int teamCapacity) {
TournamentEntity tournament = new TournamentEntity();
tournament.setName(name);
tournament.setCountry(country);
tournament.setCity(city);
tournament.setPrizePool(prizePool);
tournament.setTournamentFormat(format);
tournament.setTeamCapacity(teamCapacity);
tournamentService.create(tournament);
return tournament;
}
}
......@@ -55,6 +55,7 @@ public class TournamentFacadeImpl implements TournamentFacade {
TournamentEntity tournament = new TournamentEntity();
tournament.setCity(tournamentDTO.getCity());
tournament.setName(tournamentDTO.getName());
tournament.setCountry(tournamentDTO.getCountry());
tournament.setTournamentFormat(tournamentDTO.getTournamentFormat());
tournament.setPrizePool(tournamentDTO.getPrizePool());
......
......@@ -53,7 +53,7 @@ public class TournamentServiceTest {
@BeforeMethod
public void createTestTournament() {
tournamentA = new TournamentEntity("Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentA = new TournamentEntity("MSI","Prievidza", CountryEnum.SLOVAKIA, 1, TournamentFormat.DEFAULT, 3);
tournamentA.setId(UUID.randomUUID().toString());
}
......@@ -114,7 +114,7 @@ public class TournamentServiceTest {
@Test
public void findAllTournaments() {
TournamentEntity tournamentB = new TournamentEntity("Brno", CountryEnum.CZECH_REPUBLIC, 1000, TournamentFormat.DEFAULT, 5);
TournamentEntity tournamentB = new TournamentEntity("MSI","Brno", CountryEnum.CZECH_REPUBLIC, 1000, TournamentFormat.DEFAULT, 5);
when(tournamentDao.findAll()).thenReturn(asList(tournamentB, tournamentA));
List<TournamentEntity> result = tournamentService.findAll();
......@@ -137,7 +137,7 @@ public class TournamentServiceTest {
@Test
public void updateTournament() {
TournamentEntity tournamentB = new TournamentEntity(
TournamentEntity tournamentB = new TournamentEntity("MSI",
"Brno II", CountryEnum.CZECH_REPUBLIC, 1000, TournamentFormat.DEFAULT, 5);
tournamentService.update(tournamentB);
......
......@@ -97,7 +97,7 @@ public class PlayerController {
playerFacade.delete(uuid);
redirectAttributes.addFlashAttribute("alert_success", "Player \"" + player.getName() + "\" was deleted.");
} catch (Exception ex) {
redirectAttributes.addFlashAttribute("alert_danger", "Player \"" + player.getName() + "\" cannot be deleted." + ex.getMessage());
redirectAttributes.addFlashAttribute("alert_danger", "Player \"" + player.getName() + "\" cannot be deleted.");
}
return "redirect:" + uriBuilder.path("/player/list").toUriString();
}
......
......@@ -64,18 +64,18 @@ public class TeamController {
//create product
String id = teamFacade.createTeam(formBean);
//report success
redirectAttributes.addFlashAttribute("alert_success", "Team " + id + " was created");
redirectAttributes.addFlashAttribute("alert_success", "Team " + formBean.getName() + " 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);
TeamDTO team = teamFacade.getTeamById(uuid);
try {
teamFacade.delete(uuid);
redirectAttributes.addFlashAttribute("alert_success", "Team \"" + player.getId() + "\" was deleted.");
redirectAttributes.addFlashAttribute("alert_success", "Team \"" + team.getName() + "\" was deleted.");
} catch (Exception ex) {
redirectAttributes.addFlashAttribute("alert_danger", "Team \"" + player.getId() + "\" cannot be deleted.");
redirectAttributes.addFlashAttribute("alert_danger", "Team \"" + team.getName() + "\" cannot be deleted.");
}
return "redirect:" + uriBuilder.path("/team/list").toUriString();
}
......
......@@ -63,9 +63,9 @@ public class TournamentController {
TournamentDTO tournament = tournamentFacade.getTournamentById(uuid);
try {
tournamentFacade.delete(uuid);
redirectAttributes.addFlashAttribute("alert_success", "Tournament \"" + tournament.getId() + "\" was deleted.");
redirectAttributes.addFlashAttribute("alert_success", "Tournament \"" + tournament.getName() + "\" was deleted.");
} catch (Exception ex) {
redirectAttributes.addFlashAttribute("alert_danger", "Tournament \"" + tournament.getId() + "\" cannot be deleted.");
redirectAttributes.addFlashAttribute("alert_danger", "Tournament \"" + tournament.getName() + "\" cannot be deleted.");
}
return "redirect:" + uriBuilder.path("/tournament/list").toUriString();
}
......@@ -80,7 +80,7 @@ public class TournamentController {
//create tournament
String uuid = tournamentFacade.createTournament(formBean);
//report success
redirectAttributes.addFlashAttribute("alert_success", "Tournament " + uuid + " was created");
redirectAttributes.addFlashAttribute("alert_success", "Tournament " + formBean.getName() + " was created");
return "redirect:" + uriBuilder.path("/tournament/view/{id}").buildAndExpand(uuid).encode().toUriString();
}
}
......@@ -18,14 +18,17 @@
</tr>
</thead>
<tbody>
<tr>
<td><c:out value="${team.id}"/></td>
<td><c:out value="${team.name}"/></td>
<td><c:out value="${team.country}"/></td>
</tr>
<c:forEach items="${teamPlayers}" var="player">
<tr>
<td><c:out value="${player.id}"/></td>
<td><c:out value="${player.name}"/></td>
<td><c:out value="${player.country}"/></td>
<td>
<my:a href="/team/view/${team.id}" class="btn btn-primary">View</my:a>
</td>
</tr>
</c:forEach>
</tbody>
......
......@@ -17,6 +17,7 @@
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>city</th>
<th>country</th>
<th>prize pool</th>
......@@ -27,7 +28,9 @@
<tbody>
<c:forEach items="${tournaments}" var="tournament">
<tr>
<td>${tournament.id}</td>
<td><c:out value="${tournament.name}"/></td>
<td><c:out value="${tournament.city}"/></td>
<td><c:out value="${tournament.country}"/></td>
<td><c:out value="${tournament.prizePool}"/></td>
......
......@@ -17,6 +17,13 @@
<form:errors path="city" cssClass="help-block"/>
</div>
</div>
<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">
......
......@@ -17,6 +17,7 @@
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>city</th>
<th>county</th>
<th>prize pool</th>
......@@ -27,6 +28,7 @@
<tbody>
<tr>
<td>${tournament.id}</td>
<td><c:out value="${tournament.name}"/></td>
<td><c:out value="${tournament.city}"/></td>
<td><c:out value="${tournament.country}"/></td>
<td><c:out value="${tournament.prizePool}"/></td>
......
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