# Consignes, publication and freeze: what the API guarantees

You will know how to set, simulate and lift a consigne, preview then publish a plan without notifying everyone, read who received which version and who confirmed, freeze a referential family and read what moved on a day. The schema gives the shape of the calls; here is what it does not say.

## Consignes

A consigne closes a time band for **all** stands on a date and reopens those named on compensation windows ([hours and consignes](horaires-et-fenetres-des-stands.md), [ADR 0043](repo:docs/decisions/0043-consigne-d-edition-fermer-une-bande-sans-rien-detruire.md)).

![Prefill, simulate, lay down and lift a consigne](repo:docs/diagrammes/consigne.svg)

<sub>Source: [`diagrammes/consigne.puml`](repo:docs/diagrammes/consigne.puml).</sub>

**Future days only.** Setting, modifying and lifting refuse (`400`) a date not strictly after "today", that of the day-of clock (the date frozen by `/api/horloge` in development, demo and acceptance). `GET /api/consignes` returns `aujourdhui` so the screen computes the same boundary.

**One request sets, replaces or extends.** `POST /api/consignes` takes dates: a free date receives the consigne, a date already under one sees it **replaced in place** (`dejaSousConsigne` in the preview), and extending an alert is the same call with more dates. The dates of a request are written in **a single transaction**. Hours are accepted as `HH:mm`; a missing end or `00:00` reads "until midnight" and is **stored as an open end** (`00:00` written, `null` read back, the same everywhere).

**The preview is a full validation, without writing.** `POST /api/consignes/apercu` replays the whole validation (band, reason, windows, known stands, headcounts under the stand's maximum, one stand per window) and returns one line per date: seats and minutes before and after, timeslots to add and remove, entering and leaving stands, available minors and adults, validation removed, locks and ad hoc rules naming a shift of the band, people seated in the band. `POST /api/consignes` returns this same preview, computed **before** the write (afterwards nothing distinguishes the added timeslots from the nominal grid). `creneauxDuJour` avoids reading a date with no grid as a date the consigne emptied. The headcount is the **opening's**, not the stand's: a stand reopened at 2 in the morning and 7 in the evening carries two openings; absent, it inherits the highest headcount the stand loses in the band, otherwise its minimum.

**The preselection sets aside without forbidding.** `POST /api/consignes/preselection` proposes ticked the stands that lose minutes in the band. A stand with hand-set hours that day (`exceptionDatee`, with its `motif`) is set aside but stays tickable: the consigne does not silently contradict a decision taken.

**Lifting deletes the added timeslots, seats included**: it is the feature's only deletion, and it is announced. `POST /api/consignes/levee/apercu` names the shifts that go and counts the people seated, and the next publication calls them "removed". It also warns when frozen days empty the week ([ADR 0089](repo:docs/decisions/0089-la-levee-avertit-quand-les-journees-figees-vident-la-semaine.md)): when the lift adds seat-minutes and at least one animateur available that day already holds a frozen seat on each of the six other days of their ISO week, it counts these people (`animateursSansJourLibre`), names the `JOUR`-locked days to reopen (`joursADeverrouiller`) and says how many they free (`animateursLiberes`): a warning, never a refusal, naming no one.

**Setting or lifting removes the review validation** of the days touched, locked or not, where a solve keeps it on a locked day ([ADR 0039](repo:docs/decisions/0039-validation-de-relecture-distincte-du-verrou.md)): a lock freezes seats, and those of the band no longer exist (`validationRetiree`).

### What the consigne takes with it

- **`POST /api/planning/reset` also erases the consignes and presets** of the edition; the database export and import carry them.
- **Presets are copied at edition duplication, consignes are not**: a preset ("Heatwave plan") describes the event's shape, a consigne belongs to an edition's days. The preset name carried by a consigne is a name, not a key: deleting the preset does not rewrite history. Its `id` is optional at creation (`POST /api/consignes/prereglages`).
- **The reason reaches the person whose day the band empties**: the "days with modified hours" lines of the publication mail are read on the dates where the person holds a seat in the published plan **or in the one it replaces**; the animateur space and the individual PDF carry the reason on their rest days too.

### Meal windows specific to the consigne

A consigne, the request and the preset may carry their `repas`: `midiDebut`/`midiFin`, `soirDebut`/`soirFin`, `coupureMinutes`, `justification`. Each missing field keeps the edition's value. A window is given with both bounds or none, and **must contain the break**: an evening 19h-19h30 under a 60-minute break is refused (`400`), since the solver sets aside a window too short as untenable and the date would be left with no rule. The `justification`, in business terms, is mandatory as soon as a field is filled (`400` otherwise) and is displayed next to the day. The override is **dated by construction**: it governs only the consigne's date (solver, Breaks, Needs and Catering screens, grid check) and leaves with it on lifting; `GET /api/parametres/legal` never moves. Only meal windows are overridden: legal ceilings stay out of a consigne's reach.

## Publication

`GET /api/planning/publication` says who would be notified and what they would read, without sending anything; `POST /api/planning/publication` publishes.

![Preview then publication of the schedule](repo:docs/diagrammes/publication.svg)

<sub>Source: [`diagrammes/publication.puml`](repo:docs/diagrammes/publication.puml).</sub>

Publishing marks the working plan as **the communicated plan** and writes only to people whose schedule changed since the last publication. The count is **per person**: renaming a stand wakes nobody, swapping two shifts wakes exactly two people. Each recipient arrives with the exact sentences of their mail (`changements`), which the administrator reads before any send ([ADR 0011](repo:docs/decisions/0011-publier-plutot-qu-envoyer-a-tous.md)). The only guard is concurrency: publishing during a solve would freeze a plan about to be rewritten, hence `409`.

`premiereDiffusion` identifies someone to whom nothing was ever sent: their whole schedule is the news. As long as `jamaisPublie` is `true`, **the animateur space is empty**. A failed send **does not come back** in the next count, since the counter measures what changed, not what was delivered: the report names the missed, and `POST /api/planning/envoi/animateur/{animateurId}` is the catch-up (it sends the **published** plan, `400` while nothing has been).

### Two send registers

Each send, of a publication or a resend, leaves its state in `envoi_planning`, dates and states only (`ENVOYE`, `ECHEC`, `SANS_EMAIL`, `EXCLU`), never content, with on failure a short cause (`ADRESSE_REFUSEE`, `BOITE_PLEINE`, `SERVEUR_INJOIGNABLE`, `AUTRE`) rather than the mail server's message, which quotes the address. The preview derives `envoisEnEchec` (people whose **last** send failed), and `GET /api/editions/courant/etat` no longer says "done" on the publication line while any remain.

| Register | Question | Where it is read |
| --- | --- | --- |
| `envoi_planning` | which version did they receive? | the Share screen |
| `envoi_mail` | could they be reached? | the Staff page |

`envoi_mail` keeps the result of **every** mail addressed to an animateur, written at the single exit point, with a category read from the SMTP code: `RELAIS_INJOIGNABLE`, `AUTHENTIFICATION`, `ADRESSE_REFUSEE`, `TEMPORAIRE`, `AUTRE` (an extended code wins, and only a `5.1.x` designates the recipient: a `553 5.7.1` is the sender refused). It is read through `dernierEnvoi` in `GET /api/animateurs/confirmations`, never mixed with the confirmation status, and through `echecsEnvoi` in the summary. `ENVOYE` means "handed to the relay", nothing more, and nothing at all under `MAIL_MOCK=true`, which `GET /api/config` states (`mailMock`) so the screen writes "simulated".

`GET /api/planning/publication/etat` returns **who received which version**, one line per animateur of the edition: the announced version (`version.numero`), the last send (`envoi`), the eve reminder and the chase read from `notification_planifiee`, the acknowledgement, `aPrevenir`, `differe` and `joursAPrevenir`. Nothing is recomputed: each column reads the store that already answers its question.

### Publishing for a few people

`{"cibles": ["id", …]}` restricts a publication to the named people ("Notify the 2 people" after an accepted swap, or a day-of replacement). All other concerned people are **deferred** ([ADR 0047](repo:docs/decisions/0047-differer-le-message-d-une-personne-sans-la-perdre-de-vue.md)): the capture stays global, their marker does not move, they come back in the next count, `reporte` being `true` on their preview line, with the gap accumulated since what they received (`animateur.plan_notifie_id`). Targets naming no concerned person: `409`.

### The POST body

The `POST` takes a JSON body `{"cibles": ["id", …]}` and requires `Content-Type: application/json` (the list has free length and an id comes from the client: neither a separator nor a URL is safe). An empty body, or one without `cibles`, publishes for all concerned people. The 3.x `exclusions` field is gone: a client still sending it is **refused** with `400`, the message naming the key, and nobody is notified; the response no longer carries `avertissements` since 5.0. The home alert `EXCLUSION_PUBLICATION_RETIREE` closes, person by person, when a publication has actually notified that person.

Each preview line carries what is needed to sort without reading French: `ajouts`, `retraits`, `deplacements`, `mineur` (the same shift, on the same stand, slid by at most a quarter hour, with no swap decision pending: a reading criterion, never an automatic exclusion, since not notifying someone is an act) and `jours`, the dates of its changes, the same rule as `ChangementsJourneeService`: the Broadcast day filter and a day's changes count the same people.

### The recipients trace

`GET /api/planning/publication/export` returns the preview list as CSV. `GET /api/planning/publication/destinataires` returns the trace: who was notified of what and when, including those who could not be reached (`SANS_EMAIL`, `ECHEC`); without parameter, that of the last publication. It stores `changements` (the schedule) and `demandes` (swaps) separately: a schedule sentence says what was announced and always will, whereas "your request is pending" stops being true as soon as the organisation decides.

The animateur space is a second reader of this trace: `GET /api/espace-animateur/{jeton}` returns in `changements` the sentences of the last line concerning the token's holder (their schedule only) with `changementsLe`. They are never recomputed: a stand renamed since does not rewrite what was announced. The line is served whatever the send's fate: with no address or after a failure, the space is the only place these sentences still exist. A first broadcast returns an empty list. **A swap decision is not announced when taken** but by the publication that carries it: accepting a swap changes the working plan, not the published one.

## Changes of a day

`GET /api/journees/{jour}/changements?reference=publication|resolution` says what moved on a day, read twice on the same facts: per seat (stand, hours, holder before and after: `nouveau`, `retiré`, `remplacé`, `horaires modifiés`) and per animateur, in the publication's own sentences. The second reading **is** the publication diff filtered on the date: the Day tab and the Publication screen do not tell two stories. It is computed without the first-broadcast framing. The per-seat reading matches on the natural key (stand, day, hours); seats of the same cell are interchangeable. A person **kept on their stand at other hours** (a timeslot trimmed by a consigne) is an `HORAIRES` line (`heureDebutAvant`/`heureFinAvant` carry the reference), counted in `horairesModifies`, not a removal plus a new seat; two seats trimmed on one stand stay two removals and two new ones.

Two references, and **none is invented**: `publication` compares to the last published snapshot; `resolution` compares to the automatic snapshot taken just before the last **effective** solve, the one that actually replaced the plan (`snapshot_avant_solve_id`). A solve interrupted or refused on its problem does not move the reference, otherwise the tab would compare the plan to itself; neither does a restore or import between two solves: what they changed reads as changed since the solve.

The purge of automatic snapshots spares the one the reference designates; a manual deletion brings back "nothing to compare". Without parameter, the publication when there is one, the solve otherwise (`reference` says which). Without a reference, the response carries `referenceDisponible: false` and zero counters: "nothing to compare" is not "no change". A day the grid does not carry answers empty, not `404`. It is a read, with no journal trace; `comparer_journee` returns the same by ids.

## Acknowledgement

`POST /api/espace-animateur/{jeton}/confirmation` ("I've read it and I'll be there") is the only thing the space writes about the planning itself. Clicking twice answers `200` with the **first** date; confirming before any publication answers `409`. `GET /api/animateurs/confirmations` returns one line per animateur, `NON_VU` included, and `GET /api/animateurs/confirmations/synthese` three numbers (confirmed, chased, silent) among people holding a seat on the published plan, with that publication's date.

| Status | What it says |
| --- | --- |
| `NON_VU` | nothing came back: nobody has been asked yet, or the plan has moved since |
| `CONFIRME` | the button was clicked, with the date |
| `RELANCE` | a reminder went out, overnight or by hand, and remains unanswered |

The absence of a database row **means** `NON_VU`: resetting is a deletion, there are never two ways of writing "did not answer". `affecte` identifies someone with no seat in the published plan: nothing was asked of them, the column does not count them among people to chase. **Republishing resets to `NON_VU` only people whose schedule actually changed** (`PublicationDiffService`): asking someone notified of a single swap decision to confirm again would turn the button into a reflex.

### A reminder never goes out twice

`POST /api/animateurs/relances` (body `{ "animateurIds": […] }`) sends the confirmation reminder without waiting for the night, same text, and **reserves the same key** as the night job (`animateurId|publication date`) in the scheduled-sends journal before the mail leaves: someone chased by hand is not chased the next night, and someone the night already wrote is returned in `dejaRelancesPourCettePublication`. The key carries the date of the edition's last publication: it changes for everyone at each republication; it is the status that closes that door (a person already `RELANCE` is refused, only a republication that moves their schedule resets them to `NON_VU`). The report carries ids only: `envoyes`, `dejaConfirmes`, `sansEmail`, `dejaRelancesPourCettePublication`, `echecs`, `sansPoste`. A failed send is **counted**, not swallowed, and leaves an alert on the home page; so does a record without address. The route answers `400` while nothing was ever published, or if an id designates nobody: then nothing leaves, not even to the valid ids before it.

## Phase of the edition and reference data freeze

The edition's phase decides which referential families are frozen ([ADR 0115](repo:docs/decisions/0115-la-phase-de-l-edition-remplace-le-gel.md)): it is read in `GET /api/editions/courant` (`phase`, `phaseDepuis`, `structureDebloquee`) and declared by `PUT /api/editions/courant/phase` (`{ "phase": "CALCUL" }`), going back included; declaring the phase you are in does not change its date. Publication moves the edition to `PUBLIEE` by itself. In `PUBLIEE` only, `PUT /api/editions/courant/deblocage-structure` reopens the structure and `DELETE` refreezes it (`409` elsewhere); entering a phase and publishing refreeze an unblocked structure. `GET /api/editions/courant/gel` lists the state of the four families. Freezing or reopening **one** family no longer exists: the 3.x write routes of the freeze left the API in 5.0, and the phase freezes or reopens the four together.

A write that a frozen family covers is refused with **`409`**, like a stale write; tell them apart by the `code`: `MODIFICATION_CONCURRENTE` calls for "reload or overwrite", `REFERENTIEL_FIGE` for "change phase or unblock the structure" and carries `familles` ([the conventions](api-conventions.md#lire-un-refus)). Three consequences are not readable in the schema:

- **the refusal is on the field, not the route**: a `PUT /api/stands/{id}` changing only the name passes under a stands freeze, the same `PUT` changing a headcount is refused, by comparison with the stored record (bulk edit refuses exactly the rows it really modifies);
- **a file is refused whole**, before the first row: the animateur import as soon as it changes the competences of someone already registered;
- **what replaces everything is refused as soon as any family is frozen**: scenario import, restoring a pre-wipe copy, reset, and a **solve whose client supplies the problem** (`POST /api/solve`, `POST /api/solve/async`), whose landing rewrites stands, timeslots and competences. A solve built by the server is never refused.

Two cases remain open. The import of a SQL dump is not refused: it replaces the whole database and restores the phase each edition carried. Consignes remain open too, as their grid write does not go through the methods the freeze guards.
