diff --git a/wrestling_scoreboard_server/database/dump/PostgreSQL-wrestling_scoreboard-dump.sql b/wrestling_scoreboard_server/database/dump/PostgreSQL-wrestling_scoreboard-dump.sql index c126d5c3..925dcd7b 100644 --- a/wrestling_scoreboard_server/database/dump/PostgreSQL-wrestling_scoreboard-dump.sql +++ b/wrestling_scoreboard_server/database/dump/PostgreSQL-wrestling_scoreboard-dump.sql @@ -1020,12 +1020,20 @@ ALTER TABLE ONLY public.wrestling_event ALTER COLUMN id SET DEFAULT nextval('pub -- COPY public.bout (id, red_id, blue_id, weight_class_id, winner_role, bout_result, duration_millis) FROM stdin; -22 \N \N 2 \N \N \N -23 25 \N 3 \N \N \N -24 \N 26 4 \N \N \N -25 27 28 7 \N \N \N -26 29 30 10 \N \N \N -21 23 24 1 red vfa 45000 +27 31 32 19 \N \N 0 +28 33 34 20 \N \N 0 +29 35 36 21 \N \N 0 +32 40 41 22 \N \N 0 +34 44 45 23 \N \N 0 +35 46 47 24 \N \N 0 +37 50 51 25 \N \N 0 +38 52 53 26 \N \N 0 +40 56 57 27 \N \N 0 +43 62 \N 28 \N \N 0 +45 65 66 29 \N \N 0 +47 69 70 30 \N \N 0 +49 73 74 31 \N \N 0 +50 75 76 32 \N \N 0 \. @@ -1034,10 +1042,6 @@ COPY public.bout (id, red_id, blue_id, weight_class_id, winner_role, bout_result -- COPY public.bout_action (id, duration_millis, point_count, action_type, bout_role, bout_id) FROM stdin; -1 20000 2 points red 21 -2 25000 1 points red 21 -3 30000 1 points blue 21 -4 36000 \N passivity blue 21 \. @@ -1091,8 +1095,8 @@ COPY public.competition_person (id, competition_id, person_id, person_role) FROM COPY public.league (id, name, start_date, bout_config_id, season_partitions) FROM stdin; 2 Real Pro Wrestling Jn 2021-10-01 1 1 -3 National League 2021-10-01 1 2 -1 Real Pro Wrestling 2021-10-01 1 3 +3 National League 2021-10-01 1 3 +1 Real Pro Wrestling 2021-10-01 1 2 \. @@ -1114,13 +1118,35 @@ COPY public.league_team_participation (id, league_id, team_id) FROM stdin; -- COPY public.league_weight_class (id, league_id, weight_class_id, pos, season_partition) FROM stdin; -1 1 1 1 \N -2 1 3 3 \N -3 1 4 4 \N -4 1 7 7 \N -5 1 2 2 \N -6 1 10 10 \N 7 2 1 5 \N +1 1 1 1 0 +6 1 10 2 0 +5 1 2 3 0 +2 1 3 5 0 +4 1 7 6 0 +3 1 4 7 0 +9 1 12 8 0 +10 1 13 9 0 +11 1 14 10 0 +13 1 16 12 0 +14 1 17 13 0 +15 1 18 14 0 +16 1 19 1 1 +17 1 20 2 1 +18 1 21 3 1 +19 1 22 4 1 +8 1 11 4 0 +12 1 15 11 0 +20 1 23 5 1 +21 1 24 6 1 +22 1 25 7 1 +23 1 26 8 1 +24 1 27 9 1 +25 1 28 10 1 +26 1 29 11 1 +27 1 30 12 1 +29 1 32 14 1 +28 1 31 13 1 \. @@ -1130,9 +1156,9 @@ COPY public.league_weight_class (id, league_id, weight_class_id, pos, season_par COPY public.lineup (id, team_id, leader_id, coach_id) FROM stdin; 3 2 \N \N -2 3 \N \N 4 3 \N \N -1 1 1 \N +2 3 14 8 +1 1 16 4 \. @@ -1145,10 +1171,24 @@ COPY public.membership (id, person_id, club_id, no) FROM stdin; 2 2 2 \N 3 3 2 \N 4 4 2 \N -5 5 1 \N 6 6 1 \N 7 7 1 \N 8 8 1 \N +10 11 1 \N +11 12 1 \N +5 5 1 1234 +9 10 1 \N +12 13 1 \N +13 14 1 \N +14 15 1 \N +15 16 1 \N +16 17 2 \N +17 18 2 \N +18 19 2 \N +19 20 2 \N +20 21 2 \N +21 22 2 \N +22 23 2 \N \. @@ -1157,14 +1197,34 @@ COPY public.membership (id, person_id, club_id, no) FROM stdin; -- COPY public.participant_state (id, participation_id, classification_points) FROM stdin; -25 2 \N 26 6 \N -27 3 \N -28 7 \N -29 4 \N -30 8 \N -24 5 1 -23 1 4 +31 13 \N +32 24 \N +33 14 \N +34 23 \N +35 15 \N +36 26 \N +40 10 \N +41 28 \N +44 9 \N +45 25 \N +46 12 \N +47 30 \N +50 11 \N +51 31 \N +52 1 \N +53 5 \N +56 4 \N +57 8 \N +62 16 \N +65 20 \N +66 27 \N +69 22 \N +70 29 \N +73 3 \N +74 7 \N +75 21 \N +76 6 \N \. @@ -1173,14 +1233,33 @@ COPY public.participant_state (id, participation_id, classification_points) FROM -- COPY public.participation (id, membership_id, lineup_id, weight_class_id, weight) FROM stdin; -2 2 1 3 64.50 4 4 1 10 110.00 -5 5 2 1 55.30 -7 7 2 7 80.20 8 8 2 10 129.80 -3 3 1 7 79.12 -6 6 2 4 70.95 -1 1 1 1 59.12 +13 21 1 19 40.00 +14 4 1 20 110.00 +9 2 1 23 66.00 +10 19 1 22 98.00 +11 20 1 25 75.00 +15 1 1 21 61.00 +12 22 1 24 86.00 +1 1 1 1 50.12 +16 18 1 28 61.00 +20 19 1 29 97.00 +21 17 1 32 75.00 +22 2 1 30 66.00 +3 3 1 31 77.12 +23 8 2 20 130.00 +24 13 2 19 56.00 +25 15 2 23 66.00 +26 10 2 21 61.00 +7 5 2 31 80.20 +27 12 2 29 98.00 +28 12 2 22 98.00 +29 7 2 30 66.00 +5 13 2 26 55.30 +30 5 2 24 86.00 +6 9 2 32 70.95 +31 9 2 25 75.00 \. @@ -1193,11 +1272,25 @@ COPY public.person (id, prename, surname, birth_date, gender) FROM stdin; 2 Bart Simpson 2007-07-08 male 3 March Simpson 1980-07-08 female 4 Homer Simpson 1975-07-08 male -5 Chris Griffin 2005-03-08 male 6 Meg Griffin 2007-03-08 female 7 Lois Griffin 1979-03-08 female 8 Peter Griffin 1975-03-08 male 9 Mr Referee \N other +11 Brian Griffin 2000-03-07 male +12 Joe Swanson 1976-03-08 male +5 Chris Griffin 2005-03-08 male +10 Glenn Quagmire 1982-03-08 male +13 Cleveland Brown 1985-03-08 male +14 Stewie Griffin 2021-03-07 male +15 Adam West 1967-03-08 male +16 Bonnie Swanson 1991-03-08 female +17 Mr. Burns 1925-03-08 male +18 Ned Flanders 1964-03-08 male +19 Milhouse Van Houten 2004-03-07 male +20 Krusty Clown 1983-03-08 male +21 Moe Szyslak 1981-03-08 male +22 Maggie Simpson 2020-03-07 female +23 Nelson Muntz \N male \. @@ -1226,12 +1319,20 @@ COPY public.team_match (id, date, location, visitors_count, comment, no, home_id -- COPY public.team_match_bout (id, team_match_id, bout_id, pos) FROM stdin; -19 1 21 0 -20 1 22 1 -21 1 23 2 -22 1 24 3 -23 1 25 4 -24 1 26 5 +25 1 27 0 +26 1 28 1 +27 1 29 2 +30 1 32 3 +32 1 34 4 +33 1 35 5 +35 1 37 6 +36 1 38 7 +38 1 40 8 +41 1 43 9 +43 1 45 10 +45 1 47 11 +47 1 49 12 +48 1 50 13 \. @@ -1241,15 +1342,37 @@ COPY public.team_match_bout (id, team_match_id, bout_id, pos) FROM stdin; COPY public.weight_class (id, suffix, weight, style, unit) FROM stdin; 6 B 75 greco kilogram -1 \N 57 free kilogram -7 \N 80 free kilogram -2 \N 61 greco kilogram -3 \N 66 free kilogram 8 \N 86 greco kilogram 9 \N 98 free kilogram -4 \N 71 greco kilogram 5 A 75 free kilogram -10 \N 130 greco kilogram +1 57 free kilogram +10 130 free kilogram +2 61 greco kilogram +3 66 free kilogram +7 86 free kilogram +4 75 greco kilogram +12 57 greco kilogram +13 130 greco kilogram +14 61 free kilogram +16 66 greco kilogram +17 86 greco kilogram +18 75 free kilogram +19 57 greco kilogram +20 130 greco kilogram +21 61 free kilogram +22 98 free kilogram +11 98 greco kilogram +15 98 free kilogram +23 66 greco kilogram +24 86 greco kilogram +25 75 free kilogram +26 57 free kilogram +27 130 free kilogram +28 61 greco kilogram +29 98 greco kilogram +30 66 free kilogram +32 75 greco kilogram +31 86 free kilogram \. @@ -1279,7 +1402,7 @@ SELECT pg_catalog.setval('public.bout_config_id_seq', 1, true); -- Name: bout_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.bout_id_seq', 26, true); +SELECT pg_catalog.setval('public.bout_id_seq', 51, true); -- @@ -1328,7 +1451,7 @@ SELECT pg_catalog.setval('public.league_team_participation_id_seq', 1, false); -- Name: league_weight_class_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.league_weight_class_id_seq', 7, true); +SELECT pg_catalog.setval('public.league_weight_class_id_seq', 29, true); -- @@ -1342,28 +1465,28 @@ SELECT pg_catalog.setval('public.lineup_id_seq', 4, true); -- Name: membership_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.membership_id_seq', 8, true); +SELECT pg_catalog.setval('public.membership_id_seq', 22, true); -- -- Name: participant_state_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.participant_state_id_seq', 30, true); +SELECT pg_catalog.setval('public.participant_state_id_seq', 78, true); -- -- Name: participation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.participation_id_seq', 8, true); +SELECT pg_catalog.setval('public.participation_id_seq', 31, true); -- -- Name: person_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.person_id_seq', 9, true); +SELECT pg_catalog.setval('public.person_id_seq', 23, true); -- @@ -1377,7 +1500,7 @@ SELECT pg_catalog.setval('public.team_id_seq', 3, true); -- Name: team_match_bout_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.team_match_bout_id_seq', 24, true); +SELECT pg_catalog.setval('public.team_match_bout_id_seq', 49, true); -- @@ -1391,7 +1514,7 @@ SELECT pg_catalog.setval('public.team_match_id_seq', 1, true); -- Name: weight_class_id_seq; Type: SEQUENCE SET; Schema: public; Owner: wrestling -- -SELECT pg_catalog.setval('public.weight_class_id_seq', 10, true); +SELECT pg_catalog.setval('public.weight_class_id_seq', 32, true); -- diff --git a/wrestling_scoreboard_server/lib/controllers/bout_controller.dart b/wrestling_scoreboard_server/lib/controllers/bout_controller.dart index 0264b8a5..60608587 100644 --- a/wrestling_scoreboard_server/lib/controllers/bout_controller.dart +++ b/wrestling_scoreboard_server/lib/controllers/bout_controller.dart @@ -1,9 +1,10 @@ -import 'package:wrestling_scoreboard_common/common.dart'; import 'package:postgres/postgres.dart' as psql; import 'package:shelf/shelf.dart'; +import 'package:wrestling_scoreboard_common/common.dart'; +import 'package:wrestling_scoreboard_server/controllers/participant_state_controller.dart'; -import 'entity_controller.dart'; import 'bout_action_controller.dart'; +import 'entity_controller.dart'; class BoutController extends EntityController { static final BoutController _singleton = BoutController._internal(); @@ -19,6 +20,17 @@ class BoutController extends EntityController { isRaw: isRaw(request), conditions: ['bout_id = @id'], substitutionValues: {'id': id}); } + @override + Future deleteSingle(int id) async { + final boutRaw = await getSingleRaw(id); + final redParticipantState = boutRaw['red_id'] as int?; + final blueParticipantState = boutRaw['blue_id'] as int?; + if (redParticipantState != null) await ParticipantStateController().deleteSingle(redParticipantState); + if (blueParticipantState != null) await ParticipantStateController().deleteSingle(blueParticipantState); + await BoutActionController().deleteMany(conditions: ['bout_id=@id'], substitutionValues: {'id': id}); + return super.deleteSingle(id); + } + @override Map getPostgresDataTypes() { return { diff --git a/wrestling_scoreboard_server/lib/controllers/team_match_controller.dart b/wrestling_scoreboard_server/lib/controllers/team_match_controller.dart index b161f83f..bcfcf141 100644 --- a/wrestling_scoreboard_server/lib/controllers/team_match_controller.dart +++ b/wrestling_scoreboard_server/lib/controllers/team_match_controller.dart @@ -96,7 +96,6 @@ class TeamMatchController extends EntityController { if (isReset) { await Future.forEach(oldBouts, (Bout bout) async { if (bout.id != null) { - // TODO may also delete boutActions, participantState etc. await TeamMatchBoutController().deleteMany(conditions: ['bout_id=@id'], substitutionValues: {'id': bout.id}); await BoutController().deleteSingle(bout.id!); } @@ -106,7 +105,6 @@ class TeamMatchController extends EntityController { final unusedBouts = oldBouts.where((oldBout) => bouts.every((newBout) => newBout.id != oldBout.id)); await Future.forEach(unusedBouts, (Bout bout) async { if (bout.id != null) { - // TODO may also delete boutActions, participantState etc. await TeamMatchBoutController().deleteMany(conditions: ['bout_id=@id'], substitutionValues: {'id': bout.id}); await BoutController().deleteSingle(bout.id!); }