Bearbeiten und Löschen von Gruppen #148

Merged
sneeex merged 20 commits from feature/118-bearbeiten-und-löschen-von-gruppen into development 2026-03-09 20:30:38 +00:00
Showing only changes of commit 2214ea8e7d - Show all commits

View File

@@ -160,42 +160,15 @@ class _CreateGroupViewState extends State<CreateGroupView> {
/// depending on whether the widget is in edit mode.
Future<void> _saveGroup() async {
sneeex marked this conversation as resolved Outdated

gerne die Methode nochmal aufteilen, wie bei mir in CreateMatchView:

  void buttonNavigation(BuildContext context) async {
    if (widget.matchToEdit != null) {
      await updateMatch();
      if (context.mounted) {
        Navigator.pop(context);
      }
    } else {
      final match = await createMatch();

      if (context.mounted) {
        Navigator.pushReplacement(
          context,
          adaptivePageRoute(
            fullscreenDialog: true,
            builder: (context) => MatchResultView(
              match: match,
              onWinnerChanged: widget.onWinnerChanged,
            ),
          ),
        );
      }
    }
  }

gerne die Methode nochmal aufteilen, wie bei mir in `CreateMatchView`: ```dart void buttonNavigation(BuildContext context) async { if (widget.matchToEdit != null) { await updateMatch(); if (context.mounted) { Navigator.pop(context); } } else { final match = await createMatch(); if (context.mounted) { Navigator.pushReplacement( context, adaptivePageRoute( fullscreenDialog: true, builder: (context) => MatchResultView( match: match, onWinnerChanged: widget.onWinnerChanged, ), ), ); } } } ```

final loc = AppLocalizations.of(context);
Group? updatedGroup;
bool successfullNameChange = true;
bool successfullMemberChange = true;
late bool success;
final groupName = _groupNameController.text.trim();
Group? updatedGroup;
if (widget.groupToEdit == null) {
success = await db.groupDao.addGroup(
group: Group(
name: groupName,
description: '',
members: selectedPlayers,
),
);
success = await _createGroup();
} else {
updatedGroup = Group(
id: widget.groupToEdit!.id,
name: groupName,
description: '',
members: selectedPlayers,
);
if (widget.groupToEdit!.name != groupName) {
successfullNameChange = await db.groupDao.updateGroupName(
groupId: widget.groupToEdit!.id,
newName: groupName,
);
}
if (widget.groupToEdit!.members != selectedPlayers) {
successfullMemberChange = await db.groupDao.replaceGroupPlayers(
groupId: widget.groupToEdit!.id,
newPlayers: selectedPlayers,
);
}
success = successfullNameChange && successfullMemberChange;
final result = await _editGroup();
success = result.$1;
updatedGroup = result.$2;
}
if (!mounted) return;
@@ -211,6 +184,51 @@ class _CreateGroupViewState extends State<CreateGroupView> {
}
}
/// Handles creating a new group and returns whether the operation was successful.
Future<bool> _createGroup() async {
final groupName = _groupNameController.text.trim();
final success = await db.groupDao.addGroup(
group: Group(name: groupName, description: '', members: selectedPlayers),
);
sneeex marked this conversation as resolved Outdated

Kurzen doc comment nochmal zu dieser Methode vllt

Kurzen doc comment nochmal zu dieser Methode vllt
sneeex marked this conversation as resolved Outdated

Lieber Methode getMatchesToGroup() in groupDao.dart, kann ggf. später auch noch einmal verwendet werden

Lieber Methode `getMatchesToGroup()` in `groupDao.dart`, kann ggf. später auch noch einmal verwendet werden

hast das auch so gemacht

hast das auch so gemacht

habs von dir kopiert

habs von dir kopiert

wo hab ich das gemacht? File und Zeile

wo hab ich das gemacht? File und Zeile

hast das auch so gemacht, group detail view
grafik.png

hast das auch so gemacht, group detail view <img width="491" alt="grafik.png" src="attachments/ae2ff61f-bc2e-45fc-baa5-62254ff3a2e1">
101 KiB

ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen

ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen
return success;
}
/// Handles editing an existing group and returns a tuple of
/// (success, updatedGroup).
Future<(bool, Group?)> _editGroup() async {
final groupName = _groupNameController.text.trim();
Group? updatedGroup = Group(
id: widget.groupToEdit!.id,
name: groupName,
description: '',
members: selectedPlayers,
);
bool successfullNameChange = true;
bool successfullMemberChange = true;
if (widget.groupToEdit!.name != groupName) {
successfullNameChange = await db.groupDao.updateGroupName(
groupId: widget.groupToEdit!.id,
newName: groupName,
);
}
if (widget.groupToEdit!.members != selectedPlayers) {
successfullMemberChange = await db.groupDao.replaceGroupPlayers(
groupId: widget.groupToEdit!.id,
newPlayers: selectedPlayers,
);
}
final success = successfullNameChange && successfullMemberChange;
return (success, updatedGroup);
}
/// Displays a snackbar with the given message and optional action.
///
/// [message] The message to display in the snackbar.