Compétences supprimées de bout en bout :
- tables `skill`, `volunteer_skill`, `shift_required_skill` ;
- `Volunteer.skill_codes`, `Shift.required_skill_codes`, colonne `skills`
de l'import, règle de validation `MISSING_REQUIRED_SKILL`, jeu de démo.
Disponibilités repensées : `Availability` passe de (`day_part_id`,
`status` tri-état) à une **fenêtre horaire libre** (`date`, `start_time`,
`end_time` ; `end <= start` ⇒ passe minuit), plusieurs par jour.
- Nouveaux endpoints `GET`/`PUT /editions/{id}/volunteers/{vid}/availability`
(PUT = remplacement complet, COORDINATION) et
`GET /editions/{id}/availability` (toute l'édition, pour la grille).
- `OUTSIDE_AVAILABILITY` (toujours WARNING) : compare le créneau à l'union
des fenêtres du bénévole ce jour-là ; renvoie `date` + `uncovered_minutes`.
`DayPart` ne sert plus qu'à la borne de « journée » du cumul 8 h.
- L'import ne gère plus les disponibilités (fenêtres saisies dans l'app) :
`values.py` supprimé, mapping réduit à nom/email/téléphone/commentaire.
Migration 0007 (recrée `availability`). `AvailabilityStatus` supprimé.
158 tests, `alembic check` et `ruff` au vert. Front à suivre.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
76 lines
2.0 KiB
Python
76 lines
2.0 KiB
Python
"""Construit une `ValidationInput` depuis la base pour un couple (bénévole,
|
|
créneau). Couche de liaison : c'est le seul endroit du module `validation` qui
|
|
connaît la base."""
|
|
|
|
import uuid
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
from app.models import (
|
|
Assignment,
|
|
Availability,
|
|
DayPart,
|
|
Edition,
|
|
Shift,
|
|
Volunteer,
|
|
)
|
|
from app.validation.models import (
|
|
AvailabilityWindow,
|
|
DayPartWindow,
|
|
ShiftInfo,
|
|
ValidationInput,
|
|
)
|
|
|
|
|
|
def build_validation_input(
|
|
*,
|
|
session: Session,
|
|
edition: Edition,
|
|
volunteer: Volunteer,
|
|
shift: Shift,
|
|
exclude_assignment_id: uuid.UUID | None = None,
|
|
) -> ValidationInput:
|
|
day_parts = list(
|
|
session.exec(select(DayPart).where(DayPart.edition_id == edition.id))
|
|
)
|
|
|
|
# Toute affectation existante du bénévole compte (une affectation = une
|
|
# décision, toujours active).
|
|
stmt = (
|
|
select(Shift)
|
|
.join(Assignment, Assignment.shift_id == Shift.id)
|
|
.where(Assignment.volunteer_id == volunteer.id)
|
|
.where(Shift.id != shift.id)
|
|
)
|
|
if exclude_assignment_id is not None:
|
|
stmt = stmt.where(Assignment.id != exclude_assignment_id)
|
|
existing_shifts = tuple(
|
|
ShiftInfo(id=str(s.id), starts_at=s.starts_at, ends_at=s.ends_at)
|
|
for s in session.exec(stmt)
|
|
)
|
|
|
|
declarations = tuple(
|
|
AvailabilityWindow(
|
|
date=a.date, start_time=a.start_time, end_time=a.end_time
|
|
)
|
|
for a in session.exec(
|
|
select(Availability).where(
|
|
Availability.volunteer_id == volunteer.id
|
|
)
|
|
)
|
|
)
|
|
|
|
return ValidationInput(
|
|
candidate_shift=ShiftInfo(
|
|
id=str(shift.id),
|
|
starts_at=shift.starts_at,
|
|
ends_at=shift.ends_at,
|
|
),
|
|
existing_shifts=existing_shifts,
|
|
availabilities=declarations,
|
|
day_parts=tuple(
|
|
DayPartWindow(dp.code, dp.start_time, dp.end_time, dp.order)
|
|
for dp in day_parts
|
|
),
|
|
)
|