From d4883c1d32a143c5921279322bbbc2312bdf0b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=BCllner?= Date: Wed, 4 Mar 2026 10:48:24 +0100 Subject: [PATCH] feat(validation): record independent discovery votes during catalog adds - Add vote tracking when users add an existing global car entry - Guard against duplicate votes by checking user_id + hw_id first - Keep new-discovery flow voting unchanged while extending repeated-add validation - Align scanner business flow with TPB community verification model --- lib/screens/scan_tab.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/screens/scan_tab.dart b/lib/screens/scan_tab.dart index f901ef4..b238a36 100644 --- a/lib/screens/scan_tab.dart +++ b/lib/screens/scan_tab.dart @@ -340,6 +340,7 @@ class ScanTabState extends State { if (addConfirmed == true) { await _addToCollection(collection.id, hwId); + await _ensureValidationVote(hwId); if (!mounted) return false; showGlobalSnackBar('$hwId added to "${collection.name}"! 🎉'); } @@ -410,6 +411,23 @@ class ScanTabState extends State { 'user_id': supabase.auth.currentUser!.id, }); } + + Future _ensureValidationVote(String hwId) async { + final userId = supabase.auth.currentUser!.id; + final existingVote = await supabase + .from('car_votes') + .select('id') + .eq('hw_id', hwId) + .eq('user_id', userId) + .maybeSingle(); + + if (existingVote != null) return; + + await supabase.from('car_votes').insert({ + 'hw_id': hwId, + 'user_id': userId, + }); + } } class _FoundCarSheet extends StatelessWidget {