
# The staff espace on the API side

You will know how an animateur enters their space, what the API shows them and what it lets them write: slot swaps, ICS subscription, availability declaration, carpooling, reported unavailability. Each limit protecting a route open without an admin session is given with its reason.

## Entering the espace

The routes under `/api/espace-animateur/{jeton}` are, with the ICS subscription, the only ones reachable without an admin session. The token (the link printed on the individual PDF) alone resolves the animateur and their edition: `X-Edition-Id` is not read. An unknown token answers `404`, never `401`, and that of a non-active edition answers exactly the same, to say nothing of its validity ([decision 0072](repo:docs/decisions/0072-une-seule-edition-active.md)).

![Entering the staff espace and acknowledging receipt](repo:docs/diagrammes/espace-animateur.svg)

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

The link is not enough: the space serves the planning as a download, so all routes except `POST .../code` and `POST .../session` also require the `planning-espace` cookie session, bound to the animateur the token resolves. The record's email is the second factor: without an address, no code, and `400`. Code requests are capped (`ESPACE_CODE_MAX_DEMANDES`, 3 by default, over `ESPACE_CODE_FENETRE`, 10 minutes) and beyond answer `429`; opening the session clears the counter. `POST /api/animateurs/{id}/token` rotates the token and immediately invalidates the distributed link: the gesture to make when an individual planning leaked (the ICS subscription token, a separate key, is not touched).

## What the espace shows

The space shows the published plan, not the working plan: a validated swap, an applied repair or a solve do not move the space without a publication. A null `publieLe` means nothing has been communicated: seats are empty and the interface says so. Swap suggestions are computed on this same plan. `communiqueeLe` is null until the publication announcing a decision has left; the space says it only of an acceptance (the only case where the status contradicts what the person sees), the admin screen of every decision (its remaining to publish).

With the fair closed, submissions and cancellations are refused server-side (`400`); `foireOuverte` only serves to display it, and a dated bound is applied the same way. `foireOuvreLe` distinguishes "not yet open" from "closed"; it is null when the fair is open and when the window has passed. The planning stays visible and downloadable.

## Permanent ICS subscription

`GET /api/abonnements/{token}/planning.ics` serves the animateur's published planning, rebuilt at each call, as `text/calendar`: the address given once to one's calendar, a republication appearing at the next sync. A calendar client has no cookie and cannot answer a challenge: requiring the session would make the subscription impossible, and making it a complete access proof without second factor for the space token would be worse; the subscription therefore has its own key, separately revocable ([decision 0019](repo:docs/decisions/0019-jeton-et-chemin-dedies-pour-l-abonnement-ics.md), [public tokens](../installer/securite-jetons-publics.md)).

| | Espace token (`access_token`) | Subscription token (`abonnement_token`) |
| --- | --- | --- |
| Path | `/api/espace-animateur/{jeton}/…` | `/api/abonnements/{token}/planning.ics` |
| Also required | the session opened by e-mail code | nothing |
| Opens | the whole espace: schedule, PDF, swaps, availability, writes | one document, read-only |
| Rotation | `POST /api/animateurs/{id}/token` (admin) | `POST /api/espace-animateur/{jeton}/abonnement` (the staff member) |

The `/api/abonnements/` prefix exists only for this route: it is the pattern that an access proxy excepts from its authentication, it must designate only that and no other route is tied to it. Two behaviours:

- unknown or revoked token, or finished edition: `404` with a fixed sentence ("Subscription unknown, revoked, or edition finished"), the same in all cases, helping neither to guess a token nor to know whether it existed;
- nothing published: `200` and an empty calendar, never `404` (a client meeting a repeated `404` disables the feed).

The response carries `Cache-Control: private, no-cache` (a personal document). `POST /api/espace-animateur/{jeton}/abonnement` (session required) revokes the current address and creates a new one (`{"abonnementToken": "…"}`); the link already printed on a PDF keeps working, and the space view carries the current token in `abonnementToken`.

## Swaps

`GET` and `PUT /api/echanges/configuration` set the window of the schedule swap fair.

| Field | Role |
| --- | --- |
| `foireOuverte` | The switch, and the master: a dated window that is closed accepts nothing |
| `debut` / `fin` | Optional bounds, inclusive; empty = no bound; an end before the start is refused (`400`) before the write |
| `ouverteAujourdhui` | Read-only: the switch and today's date within the bounds |

![A swap request, from submission to decision](repo:docs/diagrammes/echange.svg)

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

![Life cycle of a swap request](repo:docs/diagrammes/echange-etats.svg)

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

A request is born `EN_ATTENTE_CIBLE` and enters the decidable queue (`PROPOSEE`) only once accepted by the targeted colleague; a colleague's refusal is terminal, the admin never arbitrates. It is prevalidated against hard constraints but saved whatever the verdict (`prevalidationOk` and the unmet constraints). If the colleague also holds a seat on the timeslot, the two swap; otherwise they take over the seat. A directed swap gives up one timeslot and takes back another designated one. Acceptance applies the swap as simulated, sets two `ANIMATEUR_CRENEAU` locks on the timeslot each receives and writes to nobody (the working plan changed, not the published plan, and the next publication announces it); the solver is not relaunched. A timeslot already begun, given or received, refuses the swap at proposal as at acceptance (`400`, [decision 0044](repo:docs/decisions/0044-le-passe-est-fige.md)). A batch solicits each targeted colleague by a notification of its own, counting only their requests.

### Who can replace me

`GET /api/espace-animateur/{jeton}/suggestions-echange?creneauId=X&standId=Y&plafond=N` serves the animateur who does not want a timeslot and has nobody in mind: they designate only their seat, and the assistant looks for swaps that hold (same mechanics as the repair assistant: the solver's eligibility filter on both sides, one simulation per lead, verdict on the whole plan; ceiling 20 by default, 100 at most). At most two seats per colleague are proposed, so the choice is about days and not a person; `listeTronquee` says the search stopped at the ceiling. The route is read-only, searches only for one's own seats (`400` otherwise) and only with the fair open. Three families, carried by `nature`:

| `nature` | Effect for the requester |
| --- | --- |
| `LIBERE` | The colleague is free at that time: the timeslot leaves their hands |
| `CROISE` | The colleague works that same timeslot: the seats swap, the requester changes stand |
| `DIRIGE` | A seat of another timeslot comes back; the suggestion carries `creneauCibleId`, its date, its hours and its stand, enough to build the directed request as is |

## Availability declaration

The animateur declares their unavailability days and game-category wishes. Nothing is written to the referential at submission: the declaration awaits an explicit admin decision. It is the first write route open from the space, and three limits hold it.

![Availability collection](repo:docs/diagrammes/declaration-disponibilites.svg)

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

| Bound | What it prevents |
| --- | --- |
| Collection window closed by default | The fair is open as long as nobody has closed it, for compatibility; a route that writes is not opened by omission |
| One pending proposal per staff member (partial unique index) | Volume: sending a thousand times leaves one row |
| `ESPACE_DECLARATION_MAX_ENVOIS` per staff member and per window (20 by default) | Rate: beyond it, `429` and `Retry-After` |

A day outside the event dates and an unknown game category are refused (`400`); while no timeslot exists, no day is imposed (collecting before the grid is the use case). Competences are not declared here: a self-declared competence feeds hard constraints, the stakes are not the same.

`GET` and `POST /api/espace-animateur/{jeton}/disponibilites`: the `GET` returns the window's state, the days, the game categories, what the referential says of the person, their pending proposal and history, even with the window closed; the `POST` replaces the pending proposal and answers the same view. The form opens on the pending proposal, otherwise on the referential (a blank page would mean "available every day"). `collecteOuverte` is false in two opposite situations, not yet begun and finished, which `collecteDebut` separates.

On the admin side, `GET /api/disponibilites` lists the declarations, newest first. `GET` and `PUT /api/disponibilites/configuration` read and write the window; `prevenirAnimateurs` also triggers sending the invitations. `POST /api/disponibilites/invitations` returns the links of an open collection (`409` otherwise); `destinataires` is `NOT_YET_INVITED` (default) or `NOT_YET_DECLARED`. `POST /api/disponibilites/{id}/application` applies the whole proposal to the record through `AnimateurService` (so `dataStale` fires), `.../refus` touches nothing and its comment is read by the animateur.

- All or nothing: the admin accepts or refuses the whole proposal, never line by line; the animateur sends a corrected version while the window is open.
- Application claims the decision before writing the record: otherwise a simultaneous refusal and application would let the second overwrite the animateur's days then receive a `409`. Claiming first makes the race a clean `409`, record intact.
- `prevenirAnimateurs` is an action, not a setting: never returned, ticked at each opening (the invitation is essential in the first round, tiresome at reopening). The response carries `invitation` (sent, `sansEmail`, failures), the link pointing to the declaration tab (`ApplicationLinks`).
- The `PUT` is atomic: without `PUBLIC_URL`, an opening ticked "notify" answers `400` and saves nothing. What fails afterwards fails per animateur and reads in `invitation`: missing address in `sansEmail`, missing space token in `echecs` with its cause.
- "This window" has no identity (`parametres_collecte`, one row per edition with no opening date): "already invited" reads in `envoi_mail` (`invitation-declaration` template, sends that left only), closing then reopening does not reset the count, and "everyone who declared nothing" is the way to resend to all.

## Carpooling

"I'm coming with…" (one to three teammates) does not travel with the declaration: the space sends it through `POST /api/espace-animateur/{jeton}/covoiturage`, and the admin decides it under `/api/disponibilites/coequipiers`. Applying or refusing a declaration never touches it, nor the reverse (two independent decisions, table `declaration_coequipier`).

| Bound | Reason |
| --- | --- |
| The collection window, the same as the declarations | A single period when the staff member writes before the build; closed, the tab can be read but sending answers `400` |
| One pending request per staff member | Sending again replaces; an empty list withdraws the request |
| A separate rate counter, at the same ceiling | Correcting oneself on one side does not use up the other's sends |
| `409` as long as a validated grouped arrival names the staff member | The validated group belongs to the organisation: it cancels it, never the espace |

`POST /api/disponibilites/coequipiers/{id}/validation` and `.../{id}/ecart` decide, with no body or reason; the gap deletes the request (`204`) and writes to nobody. Only validation goes out as a notification, best effort: it writes to each member, with a link to the Carpooling tab, and a failing SMTP never cancels the decision. The `statut` has only two values, `EN_ATTENTE` and `VALIDEE`. `POST /api/disponibilites/coequipiers/{id}/annulation` targets the group, not the single `{id}` request: it deletes the adjustment and all the requests validated with it, in one transaction, `204` without notifying anyone; `404` for an unknown `{id}`, `409` for a request no longer validated or whose adjustment has disappeared, and while a solve holds the edition. The trap is on the other side: `DELETE /api/contraintes-ad-hoc/{id}` and the `POST` rewriting an adjustment answer `409` on a grouped arrival a validated request supports (`issueDeCovoiturage` in the view), otherwise the group would believe in a car that no longer exists.

## Reported impediment

"I won't be able to be there": the staff member reports that they will be absent for a whole day or for a seat, through `POST /api/espace-animateur/{jeton}/signalements`; `DELETE /api/espace-animateur/{jeton}/signalements/{signalementId}` cancels their own. It is the espace's second write route, open for the whole edition, fair and collection closed included. Nothing is written to the schedule: the organisation notes or files it ([decision 0065](repo:docs/decisions/0065-empechement-signale-declaration-constatee.md)).

| Bound | What it prevents |
| --- | --- |
| A day on which the staff member holds a seat in the schedule communicated, not yet finished; for a seat, their own and not finished (`400`) | A report on what they do not see, or on the past |
| A single open report per person and per object (partial unique index); a day reported in full covers its seats (`409`) | Volume |
| `ESPACE_DECLARATION_MAX_ENVOIS`, counted apart from the declaration and before any validation | Rate: `429` and `Retry-After` |

The seat is designated by its natural key (`creneauId` and `standId`), never by the seat identifier a solve renumbers. The reason is optional and from a closed list (`PERSONNEL`, `TRANSPORT`, `AUTRE`): no free field, that is where a health reason nobody asked for would be written. The organisation is notified by email, best effort; the animateur cancels theirs while it is open, never after (`409`). The decision goes through `POST /api/jour-j/signalements/{signalementId}/traitement` ("Mark absent and replace") and `.../classement` ("File"). The processing reserves the report in the transaction writing the absence: two decisions a second apart, or a cancellation crossing the decision, leave a single winner, the other receiving `409`. If the absence is refused (lock, contradiction, solve under way), the reservation is cancelled and the report stays open. The animateur learns the decision by email, best effort ("taken into account" once the absence is written, "filed" without touching the planning), naming the day and the seat, never the reason.

`GET` and `PUT /api/jour-j/signalements/configuration` disable the action per edition (table `parametres_signalement`, enabled by default). Switched off, it disappears everywhere: the espace no longer offers it (`signalementsActifs`) and refuses a submission, the reports received are no longer displayed, and cancelling, filing or handling them answers `400`. They stay in the database, and switching back on restores them as they were.
