Skip to content
Snippets Groups Projects
Commit 5ea6f2f2 authored by Callum Gran's avatar Callum Gran
Browse files

Merge branch 'fix/team-in-multiple-divisions' into 'main'

fix(teamDAO): teams can now be in multiple divisions

See merge request carljgu/tournament-service!137
parents fe7fa367 a9da221d
No related branches found
No related tags found
No related merge requests found
...@@ -161,7 +161,6 @@ public class Match { ...@@ -161,7 +161,6 @@ public class Match {
public void setFinished() { public void setFinished() {
setFinished(LocalDateTime.now()); setFinished(LocalDateTime.now());
if (isKnockout) { if (isKnockout) {
System.out.println("WTF");
setWinner(); setWinner();
} }
} }
......
...@@ -370,7 +370,7 @@ public class Model { ...@@ -370,7 +370,7 @@ public class Model {
team.setName(teamName); team.setName(teamName);
team.setCompeting(true); team.setCompeting(true);
try { try {
teamDAO.addTeam(team); teamDAO.addTeam(team, currentDivision.getDivisionId());
teamDAO.linkTeamToDivision(teamDAO.getTeamByName(teamName).getTeamId(), currentDivision.getDivisionId()); teamDAO.linkTeamToDivision(teamDAO.getTeamByName(teamName).getTeamId(), currentDivision.getDivisionId());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
result = false; result = false;
......
...@@ -186,7 +186,7 @@ public class TeamDAO { ...@@ -186,7 +186,7 @@ public class TeamDAO {
* *
* @param team Team: the team to be added to the database. * @param team Team: the team to be added to the database.
*/ */
public void addTeam(Team team) throws IllegalArgumentException { public void addTeam(Team team, int divisionId) throws IllegalArgumentException {
String sql = "INSERT INTO teams(teamName, competing) VALUES(?, ?)"; String sql = "INSERT INTO teams(teamName, competing) VALUES(?, ?)";
Team teamFromDb = getTeamByName(team.getName()); Team teamFromDb = getTeamByName(team.getName());
ResultSet resultSet = null; ResultSet resultSet = null;
...@@ -205,7 +205,25 @@ public class TeamDAO { ...@@ -205,7 +205,25 @@ public class TeamDAO {
close(connection, preparedStatement, resultSet); close(connection, preparedStatement, resultSet);
} }
} else { } else {
throw new IllegalArgumentException(); String sqlLink = "SELECT * FROM teams, divisionsteamslink WHERE teams.teamId = divisionsteamslink.teamId AND teams.teamName = ? AND divisionsteamslink.divisionId = ?";
Team newTeamFromDB;
try {
connection = Database.instance().getConnection();
preparedStatement = connection.prepareStatement(sqlLink);
preparedStatement.setString(1, team.getName());
preparedStatement.setInt(2, divisionId);
resultSet = preparedStatement.executeQuery();
newTeamFromDB = getTeamFromResultSet(resultSet);
if (newTeamFromDB == null) {
linkTeamToDivision(teamFromDb.getTeamId(), divisionId);
} else {
throw new IllegalArgumentException();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(connection, preparedStatement, resultSet);
}
} }
} }
......
...@@ -33,7 +33,6 @@ public class MatchDAOTest { ...@@ -33,7 +33,6 @@ public class MatchDAOTest {
expectedFieldList.add("A1"); expectedFieldList.add("A1");
expectedFieldList.add("A2"); expectedFieldList.add("A2");
expectedFieldList.add("A3"); expectedFieldList.add("A3");
System.out.println(actualMatches.size());
assertTrue(actualMatches.size() == expectedFieldList.size() && actualMatches.containsAll(expectedFieldList)); assertTrue(actualMatches.size() == expectedFieldList.size() && actualMatches.containsAll(expectedFieldList));
} }
......
...@@ -64,7 +64,7 @@ public class TeamDAOTest { ...@@ -64,7 +64,7 @@ public class TeamDAOTest {
public void testAddTeam() { public void testAddTeam() {
Team team = new Team("Callums Javaer", true); Team team = new Team("Callums Javaer", true);
try { try {
teamDAO.addTeam(team); teamDAO.addTeam(team, 1);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment