Refactoring
This commit is contained in:
@@ -117,14 +117,14 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the game with the given [gameId] to [newName].
|
||||
/// Updates the name of the game with the given [gameId] to [name].
|
||||
Future<bool> updateGameName({
|
||||
required String gameId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(name: Value(newName)),
|
||||
GameTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
@@ -132,11 +132,11 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
/// Updates the ruleset of the game with the given [gameId].
|
||||
Future<bool> updateGameRuleset({
|
||||
required String gameId,
|
||||
required Ruleset newRuleset,
|
||||
required Ruleset ruleset,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(ruleset: Value(newRuleset.name)),
|
||||
GameTableCompanion(ruleset: Value(ruleset.name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
@@ -144,11 +144,11 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
/// Updates the description of the game with the given [gameId].
|
||||
Future<bool> updateGameDescription({
|
||||
required String gameId,
|
||||
required String newDescription,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(description: Value(newDescription)),
|
||||
GameTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
@@ -156,11 +156,11 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
/// Updates the color of the game with the given [gameId].
|
||||
Future<bool> updateGameColor({
|
||||
required String gameId,
|
||||
required GameColor newColor,
|
||||
required GameColor color,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(color: Value(newColor.name)),
|
||||
GameTableCompanion(color: Value(color.name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
@@ -168,11 +168,11 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
/// Updates the icon of the game with the given [gameId].
|
||||
Future<bool> updateGameIcon({
|
||||
required String gameId,
|
||||
required String newIcon,
|
||||
required String icon,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(icon: Value(newIcon)),
|
||||
GameTableCompanion(icon: Value(icon)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -213,28 +213,28 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the group with the given [id] to [newName].
|
||||
/// Updates the name of the group with the given [id] to [name].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupName({
|
||||
required String groupId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(name: Value(newName)),
|
||||
GroupTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the description of the group with the given [groupId] to [newDescription].
|
||||
/// Updates the description of the group with the given [groupId] to [description].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupDescription({
|
||||
required String groupId,
|
||||
required String newDescription,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(description: Value(newDescription)),
|
||||
GroupTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -395,30 +395,30 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Changes the name of the match with the given [matchId] to [newName].
|
||||
/// Changes the name of the match with the given [matchId] to [name].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchName({
|
||||
required String matchId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(name: Value(newName)),
|
||||
MatchTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the group of the match with the given [matchId].
|
||||
/// Replaces the existing group association with the new group specified by [newGroupId].
|
||||
/// Replaces the existing group association with the new group specified by [groupId].
|
||||
/// Pass null to remove the group association.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchGroup({
|
||||
required String matchId,
|
||||
required String? newGroupId,
|
||||
required String? groupId,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(groupId: Value(newGroupId)),
|
||||
MatchTableCompanion(groupId: Value(groupId)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -158,10 +158,10 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the player with the given [playerId] to [newName].
|
||||
/// Updates the name of the player with the given [playerId] to [name].
|
||||
Future<bool> updatePlayerName({
|
||||
required String playerId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
// Get previous name and name count for the player before updating
|
||||
final previousPlayerName =
|
||||
@@ -173,13 +173,13 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
|
||||
final rowsAffected =
|
||||
await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
|
||||
PlayerTableCompanion(name: Value(newName)),
|
||||
PlayerTableCompanion(name: Value(name)),
|
||||
);
|
||||
|
||||
// Update name count for the new name
|
||||
final count = await calculateNameCount(name: newName);
|
||||
final count = await calculateNameCount(name: name);
|
||||
if (count > 0) {
|
||||
await (update(playerTable)..where((p) => p.name.equals(newName))).write(
|
||||
await (update(playerTable)..where((p) => p.name.equals(name))).write(
|
||||
PlayerTableCompanion(nameCount: Value(count)),
|
||||
);
|
||||
}
|
||||
@@ -200,15 +200,15 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
}
|
||||
|
||||
/// Updates the description of the player with the given [playerId] to
|
||||
/// [newDescription].
|
||||
/// [description].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updatePlayerDescription({
|
||||
required String playerId,
|
||||
required String newDescription,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(playerTable)..where((g) => g.id.equals(playerId))).write(
|
||||
PlayerTableCompanion(description: Value(newDescription)),
|
||||
PlayerTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -116,18 +116,18 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
}
|
||||
|
||||
/// Updates the players associated with a match based on the provided
|
||||
/// [newPlayer] list. It adds new players and removes players that are no
|
||||
/// [player] list. It adds new players and removes players that are no
|
||||
/// longer associated with the match.
|
||||
Future<bool> updateMatchPlayers({
|
||||
required String matchId,
|
||||
required List<Player> newPlayer,
|
||||
required List<Player> player,
|
||||
}) async {
|
||||
if (newPlayer.isEmpty) return false;
|
||||
if (player.isEmpty) return false;
|
||||
|
||||
final currentPlayers = await getPlayersOfMatch(matchId: matchId);
|
||||
// Create sets of player IDs for easy comparison
|
||||
final currentPlayerIds = currentPlayers.map((p) => p.id).toSet();
|
||||
final newPlayerIdsSet = newPlayer.map((p) => p.id).toSet();
|
||||
final newPlayerIdsSet = player.map((p) => p.id).toSet();
|
||||
|
||||
// Are the current and new player identical?
|
||||
if (currentPlayerIds.containsAll(newPlayerIdsSet) &&
|
||||
|
||||
@@ -162,19 +162,19 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
Future<bool> updateScore({
|
||||
required String playerId,
|
||||
required String matchId,
|
||||
required ScoreEntry newEntry,
|
||||
required ScoreEntry entry,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(scoreEntryTable)..where(
|
||||
(s) =>
|
||||
s.playerId.equals(playerId) &
|
||||
s.matchId.equals(matchId) &
|
||||
s.roundNumber.equals(newEntry.roundNumber),
|
||||
s.roundNumber.equals(entry.roundNumber),
|
||||
))
|
||||
.write(
|
||||
ScoreEntryTableCompanion(
|
||||
score: Value(newEntry.score),
|
||||
change: Value(newEntry.change),
|
||||
score: Value(entry.score),
|
||||
change: Value(entry.change),
|
||||
),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
|
||||
@@ -153,11 +153,11 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
/// Updates the name of the team with the given [teamId].
|
||||
Future<bool> updateTeamName({
|
||||
required String teamId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
|
||||
TeamTableCompanion(name: Value(newName)),
|
||||
TeamTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user