Retrait des compétences ; disponibilités en fenêtres horaires libres
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
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
81609eecc5
commit
be51770b51
@@ -6,7 +6,7 @@ from fastapi import APIRouter, Depends, HTTPException, Response, status
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from app.api._common import owned_or_404, replace_links, resolve_skills
|
||||
from app.api._common import owned_or_404, replace_links
|
||||
from app.api.deps import get_edition
|
||||
from app.api.schemas import VolunteerCreate, VolunteerRead, VolunteerUpdate
|
||||
from app.auth.deps import (
|
||||
@@ -21,11 +21,9 @@ from app.models import (
|
||||
Edition,
|
||||
Position,
|
||||
Role,
|
||||
Skill,
|
||||
Volunteer,
|
||||
VolunteerArtist,
|
||||
VolunteerPositionWish,
|
||||
VolunteerSkill,
|
||||
)
|
||||
|
||||
router = APIRouter(
|
||||
@@ -41,16 +39,6 @@ def _ensure_can_read(account: Account, volunteer_id: uuid.UUID) -> None:
|
||||
raise HTTPException(status_code=403, detail={"code": "error.forbidden"})
|
||||
|
||||
|
||||
def _skill_codes(session: Session, volunteer_id: uuid.UUID) -> list[str]:
|
||||
return sorted(
|
||||
session.exec(
|
||||
select(Skill.code)
|
||||
.join(VolunteerSkill, VolunteerSkill.skill_id == Skill.id)
|
||||
.where(VolunteerSkill.volunteer_id == volunteer_id)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _artist_ids(session: Session, volunteer_id: uuid.UUID) -> list[uuid.UUID]:
|
||||
return list(
|
||||
session.exec(
|
||||
@@ -81,27 +69,11 @@ def _wished_position_ids(
|
||||
def _read(session: Session, volunteer: Volunteer) -> VolunteerRead:
|
||||
return VolunteerRead(
|
||||
**volunteer.model_dump(),
|
||||
skill_codes=_skill_codes(session, volunteer.id),
|
||||
artist_ids=_artist_ids(session, volunteer.id),
|
||||
wished_position_ids=_wished_position_ids(session, volunteer.id),
|
||||
)
|
||||
|
||||
|
||||
def _set_skills(
|
||||
session: Session, volunteer: Volunteer, codes: list[str]
|
||||
) -> None:
|
||||
skills = resolve_skills(session, volunteer.edition_id, codes)
|
||||
replace_links(
|
||||
session,
|
||||
VolunteerSkill,
|
||||
filter_column=VolunteerSkill.volunteer_id,
|
||||
filter_value=volunteer.id,
|
||||
pairs=[
|
||||
{"volunteer_id": volunteer.id, "skill_id": s.id} for s in skills
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def _resolve_owned_ids(
|
||||
session: Session, model, edition_id: uuid.UUID, ids: list[uuid.UUID], code: str
|
||||
) -> list[uuid.UUID]:
|
||||
@@ -168,9 +140,7 @@ def create_volunteer(
|
||||
) -> VolunteerRead:
|
||||
volunteer = Volunteer(
|
||||
edition_id=edition.id,
|
||||
**payload.model_dump(
|
||||
exclude={"skill_codes", "artist_ids", "wished_position_ids"}
|
||||
),
|
||||
**payload.model_dump(exclude={"artist_ids", "wished_position_ids"}),
|
||||
)
|
||||
session.add(volunteer)
|
||||
try:
|
||||
@@ -180,7 +150,6 @@ def create_volunteer(
|
||||
raise HTTPException(
|
||||
status_code=409, detail={"code": "volunteer.duplicate_email"}
|
||||
) from exc
|
||||
_set_skills(session, volunteer, payload.skill_codes)
|
||||
_set_artists(session, volunteer, payload.artist_ids)
|
||||
_set_wished_positions(session, volunteer, payload.wished_position_ids)
|
||||
session.commit()
|
||||
@@ -224,7 +193,6 @@ def update_volunteer(
|
||||
) -> VolunteerRead:
|
||||
volunteer = owned_or_404(session.get(Volunteer, volunteer_id), edition.id)
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
skill_codes = changes.pop("skill_codes", None)
|
||||
artist_ids = changes.pop("artist_ids", None)
|
||||
wished_position_ids = changes.pop("wished_position_ids", None)
|
||||
for field, value in changes.items():
|
||||
@@ -236,8 +204,6 @@ def update_volunteer(
|
||||
raise HTTPException(
|
||||
status_code=409, detail={"code": "volunteer.duplicate_email"}
|
||||
) from exc
|
||||
if skill_codes is not None:
|
||||
_set_skills(session, volunteer, skill_codes)
|
||||
if artist_ids is not None:
|
||||
_set_artists(session, volunteer, artist_ids)
|
||||
if wished_position_ids is not None:
|
||||
@@ -256,7 +222,7 @@ def delete_volunteer(
|
||||
) -> Response:
|
||||
volunteer = owned_or_404(session.get(Volunteer, volunteer_id), edition.id)
|
||||
# Effacement complet : la cascade base supprime disponibilités,
|
||||
# affectations, liens de compétence et compte éventuel.
|
||||
# affectations, vœux et compte éventuel.
|
||||
session.delete(volunteer)
|
||||
session.commit()
|
||||
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
Reference in New Issue
Block a user