@@ -703,6 +703,9 @@ async def load_participant_by_user_id(
703703 ).selectinload (
704704 models_sport_competition .CompetitionUser .user ,
705705 ),
706+ selectinload (
707+ models_sport_competition .CompetitionParticipant .team ,
708+ ),
706709 ),
707710 )
708711 )
@@ -2457,7 +2460,7 @@ async def delete_payment(
24572460# region: Checkouts
24582461
24592462
2460- def create_checkout (
2463+ def add_checkout (
24612464 db : AsyncSession ,
24622465 checkout : schemas_sport_competition .Checkout ,
24632466):
@@ -2500,3 +2503,224 @@ async def get_checkout_by_checkout_id(
25002503
25012504
25022505# endregion: Checkouts
2506+ # region: Volunteers Shifts
2507+
2508+
2509+ async def load_all_volunteer_shifts_by_edition_id (
2510+ edition_id : UUID ,
2511+ db : AsyncSession ,
2512+ ) -> list [schemas_sport_competition .VolunteerShiftComplete ]:
2513+ shifts = await db .execute (
2514+ select (models_sport_competition .VolunteerShift )
2515+ .where (
2516+ models_sport_competition .VolunteerShift .edition_id == edition_id ,
2517+ )
2518+ .options (
2519+ selectinload (
2520+ models_sport_competition .VolunteerShift .registrations ,
2521+ ).selectinload (
2522+ models_sport_competition .VolunteerRegistration .user ,
2523+ ),
2524+ ),
2525+ )
2526+ return [
2527+ schemas_sport_competition .VolunteerShiftComplete (
2528+ id = shift .id ,
2529+ edition_id = shift .edition_id ,
2530+ name = shift .name ,
2531+ description = shift .description ,
2532+ value = shift .value ,
2533+ start_time = shift .start_time ,
2534+ end_time = shift .end_time ,
2535+ max_volunteers = shift .max_volunteers ,
2536+ location = shift .location ,
2537+ registrations = [
2538+ schemas_sport_competition .VolunteerRegistrationWithUser (
2539+ user_id = registration .user_id ,
2540+ shift_id = registration .shift_id ,
2541+ edition_id = registration .edition_id ,
2542+ validated = registration .validated ,
2543+ registered_at = registration .registered_at ,
2544+ user = competition_user_model_to_schema (registration .user ),
2545+ )
2546+ for registration in shift .registrations
2547+ ],
2548+ )
2549+ for shift in shifts .scalars ().all ()
2550+ ]
2551+
2552+
2553+ async def load_volunteer_shift_by_id (
2554+ shift_id : UUID ,
2555+ db : AsyncSession ,
2556+ ) -> schemas_sport_competition .VolunteerShiftComplete | None :
2557+ shift = (
2558+ (
2559+ await db .execute (
2560+ select (models_sport_competition .VolunteerShift )
2561+ .where (
2562+ models_sport_competition .VolunteerShift .id == shift_id ,
2563+ )
2564+ .options (
2565+ selectinload (
2566+ models_sport_competition .VolunteerShift .registrations ,
2567+ ).selectinload (
2568+ models_sport_competition .VolunteerRegistration .user ,
2569+ ),
2570+ ),
2571+ )
2572+ )
2573+ .scalars ()
2574+ .first ()
2575+ )
2576+ return (
2577+ schemas_sport_competition .VolunteerShiftComplete (
2578+ id = shift .id ,
2579+ edition_id = shift .edition_id ,
2580+ name = shift .name ,
2581+ description = shift .description ,
2582+ value = shift .value ,
2583+ start_time = shift .start_time ,
2584+ end_time = shift .end_time ,
2585+ max_volunteers = shift .max_volunteers ,
2586+ location = shift .location ,
2587+ registrations = [
2588+ schemas_sport_competition .VolunteerRegistrationWithUser (
2589+ user_id = registration .user_id ,
2590+ shift_id = registration .shift_id ,
2591+ edition_id = registration .edition_id ,
2592+ validated = registration .validated ,
2593+ registered_at = registration .registered_at ,
2594+ user = competition_user_model_to_schema (registration .user ),
2595+ )
2596+ for registration in shift .registrations
2597+ ],
2598+ )
2599+ if shift
2600+ else None
2601+ )
2602+
2603+
2604+ async def add_volunteer_shift (
2605+ shift : schemas_sport_competition .VolunteerShift ,
2606+ db : AsyncSession ,
2607+ ):
2608+ db .add (
2609+ models_sport_competition .VolunteerShift (
2610+ id = shift .id ,
2611+ edition_id = shift .edition_id ,
2612+ name = shift .name ,
2613+ description = shift .description ,
2614+ value = shift .value ,
2615+ start_time = shift .start_time ,
2616+ end_time = shift .end_time ,
2617+ max_volunteers = shift .max_volunteers ,
2618+ location = shift .location ,
2619+ ),
2620+ )
2621+
2622+
2623+ async def update_volunteer_shift (
2624+ shift_id : UUID ,
2625+ shift : schemas_sport_competition .VolunteerShiftEdit ,
2626+ db : AsyncSession ,
2627+ ):
2628+ await db .execute (
2629+ update (models_sport_competition .VolunteerShift )
2630+ .where (models_sport_competition .VolunteerShift .id == shift_id )
2631+ .values (** shift .model_dump (exclude_unset = True )),
2632+ )
2633+
2634+
2635+ async def delete_volunteer_shift_by_id (
2636+ shift_id : UUID ,
2637+ db : AsyncSession ,
2638+ ):
2639+ await db .execute (
2640+ delete (models_sport_competition .VolunteerShift ).where (
2641+ models_sport_competition .VolunteerShift .id == shift_id ,
2642+ ),
2643+ )
2644+
2645+
2646+ # endregion: Volunteers Shifts
2647+ # region: Volunteers Registrations
2648+
2649+
2650+ async def load_volunteer_registrations_by_user_id (
2651+ user_id : str ,
2652+ edition_id : UUID ,
2653+ db : AsyncSession ,
2654+ ) -> list [schemas_sport_competition .VolunteerRegistrationComplete ]:
2655+ registrations = await db .execute (
2656+ select (models_sport_competition .VolunteerRegistration )
2657+ .where (
2658+ models_sport_competition .VolunteerRegistration .user_id == user_id ,
2659+ models_sport_competition .VolunteerRegistration .edition_id == edition_id ,
2660+ )
2661+ .options (
2662+ selectinload (models_sport_competition .VolunteerRegistration .shift ),
2663+ ),
2664+ )
2665+ return [
2666+ schemas_sport_competition .VolunteerRegistrationComplete (
2667+ user_id = registration .user_id ,
2668+ shift_id = registration .shift_id ,
2669+ edition_id = registration .edition_id ,
2670+ validated = registration .validated ,
2671+ registered_at = registration .registered_at ,
2672+ shift = schemas_sport_competition .VolunteerShift (
2673+ id = registration .shift .id ,
2674+ edition_id = registration .shift .edition_id ,
2675+ name = registration .shift .name ,
2676+ description = registration .shift .description ,
2677+ value = registration .shift .value ,
2678+ start_time = registration .shift .start_time ,
2679+ end_time = registration .shift .end_time ,
2680+ max_volunteers = registration .shift .max_volunteers ,
2681+ location = registration .shift .location ,
2682+ )
2683+ if registration .shift
2684+ else None ,
2685+ )
2686+ for registration in registrations .scalars ().all ()
2687+ ]
2688+
2689+
2690+ async def add_volunteer_registration (
2691+ registration : schemas_sport_competition .VolunteerRegistration ,
2692+ db : AsyncSession ,
2693+ ):
2694+ db .add (
2695+ models_sport_competition .VolunteerRegistration (
2696+ user_id = registration .user_id ,
2697+ shift_id = registration .shift_id ,
2698+ edition_id = registration .edition_id ,
2699+ validated = registration .validated ,
2700+ registered_at = registration .registered_at ,
2701+ ),
2702+ )
2703+
2704+
2705+ async def delete_volunteer_registration (
2706+ user_id : str ,
2707+ shift_id : UUID ,
2708+ db : AsyncSession ,
2709+ ):
2710+ await db .execute (
2711+ delete (models_sport_competition .VolunteerRegistration ).where (
2712+ models_sport_competition .VolunteerRegistration .user_id == user_id ,
2713+ models_sport_competition .VolunteerRegistration .shift_id == shift_id ,
2714+ ),
2715+ )
2716+
2717+
2718+ async def delete_volunteer_registrations_for_shift (
2719+ shift_id : UUID ,
2720+ db : AsyncSession ,
2721+ ):
2722+ await db .execute (
2723+ delete (models_sport_competition .VolunteerRegistration ).where (
2724+ models_sport_competition .VolunteerRegistration .shift_id == shift_id ,
2725+ ),
2726+ )
0 commit comments