> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wethehivers.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Alertes emploi candidat

> Créer, modifier, désactiver une alerte emploi par email

# Alertes emploi candidat

Un candidat inscrit peut enregistrer jusqu'à **5 alertes**. Chaque alerte déclenche un email quotidien ou hebdomadaire avec les offres matchantes.

## Flow utilisateur

```mermaid theme={null}
flowchart TD
    S[Candidat effectue une recherche] --> FILTER[Applique filtres]
    FILTER --> BTN[Clique "Créer alerte"]
    BTN --> API[POST /candidats/me/alertes]
    API --> CONF[Confirmation + nom personnalisable]
    CONF --> CRON[Cron DAILY/WEEKLY]
    CRON --> MAIL[Email si matchs]
```

## 1. Créer une alerte

```http theme={null}
POST /v1/api/candidats/me/alertes HTTP/1.1
Authorization: Bearer <CANDIDAT_TOKEN>
Content-Type: application/json

{
  "nom": "Java senior Douala",
  "criteres": {
    "query": "java spring",
    "typeContrat": ["CDI"],
    "niveauExperience": ["SENIOR"],
    "villeIds": [101],
    "salaireMin": 600000
  },
  "frequence": "DAILY"
}
```

**Réponse** `201 Created` :

```json theme={null}
{
  "id": 77,
  "nom": "Java senior Douala",
  "frequence": "DAILY",
  "active": true,
  "prochaineExecution": "2026-04-19T07:00:00Z"
}
```

## 2. Critères supportés

```mermaid theme={null}
flowchart TD
    CRIT[criteres] --> Q[query: string]
    CRIT --> SEC[secteur: string[]]
    CRIT --> TC[typeContrat: string[]]
    CRIT --> NE[niveauExperience: string[]]
    CRIT --> V[villeIds: long[]]
    CRIT --> SAL[salaireMin: int]
    CRIT --> TEL[teletravail: bool]
```

| Champ              | Type      | Exemple                       |
| ------------------ | --------- | ----------------------------- |
| `query`            | string    | `"java spring"`               |
| `secteur`          | string\[] | `["SOFTWARE", "FINANCE"]`     |
| `typeContrat`      | string\[] | `["CDI", "CDD"]`              |
| `niveauExperience` | string\[] | `["SENIOR", "INTERMEDIAIRE"]` |
| `villeIds`         | long\[]   | `[101, 102]`                  |
| `salaireMin`       | int       | `500000`                      |
| `teletravail`      | bool      | `true`                        |

## 3. Lister mes alertes

```http theme={null}
GET /v1/api/candidats/me/alertes HTTP/1.1
```

```json theme={null}
{
  "alertes": [
    { "id": 77, "nom": "Java senior Douala", "active": true, "totalMatchs": 47 },
    { "id": 78, "nom": "React remote", "active": false, "totalMatchs": 12 }
  ]
}
```

## 4. Activer / désactiver

```http theme={null}
POST /v1/api/candidats/me/alertes/77/toggle HTTP/1.1
```

```mermaid theme={null}
stateDiagram-v2
    ACTIVE --> INACTIVE: toggle
    INACTIVE --> ACTIVE: toggle
```

## 5. Modifier les critères

```http theme={null}
PATCH /v1/api/candidats/me/alertes/77 HTTP/1.1

{ "criteres": { "query": "java spring kafka", "typeContrat": ["CDI"] } }
```

## 6. Supprimer

```http theme={null}
DELETE /v1/api/candidats/me/alertes/77 HTTP/1.1
```

## 7. Désabonnement one-click (email)

Chaque email contient un lien signé permettant de désactiver sans login :

```mermaid theme={null}
sequenceDiagram
    participant C as Candidat
    participant M as Email reçu
    participant API as Backend
    participant DB as DB

    M->>C: Email avec lien\n "Désactiver cette alerte"
    C->>API: GET /alertes/unsubscribe?token=...
    API->>API: Valider signature
    API->>DB: UPDATE active=false
    API-->>C: HTML "Alerte désactivée"
```

## Fréquences

| Fréquence | Cron                   | Utilisation    |
| --------- | ---------------------- | -------------- |
| `DAILY`   | Tous les jours à 07:00 | Veille active  |
| `WEEKLY`  | Lundi à 07:00          | Veille passive |

## Limites

* **5 alertes** max par candidat inscrit
* Anonyme : **0 alerte** (besoin d'un compte)
* Email envoyé uniquement si ≥ 1 match nouveau depuis `lastRunAt`
* Top 10 offres dans l'email, lien vers la recherche complète

## Exemple d'email reçu

```
Sujet : 3 nouvelles offres pour "Java senior Douala"

Bonjour Jean,

Voici les 3 nouvelles offres correspondant à votre alerte "Java senior Douala" :

1. Développeur Backend Java (H/F) — Tech Corp — Douala — CDI — 700k-900k XAF
2. Lead Developer Java — FinPlus — Douala — CDI — 1M-1.4M XAF
3. Ingénieur Backend Spring — DataFlow — Douala — CDI — 650k-850k XAF

[Voir toutes les offres]

— Désactiver cette alerte (en un clic)
```

## Déduplication

```mermaid theme={null}
flowchart LR
    RUN[Exécution alerte] --> MATCH[Offres matchantes]
    MATCH --> FILT{Déjà notifiée?\n table alerte_matches}
    FILT -->|oui| SKIP[Skip]
    FILT -->|non| SEND[Inclure dans email]
    SEND --> LOG[INSERT alerte_matches]
```

Une offre notifiée une fois ne sera jamais renvoyée sur la même alerte, même si elle est modifiée.

## Voir aussi

* [Modèle AlerteEmploi](/models/alerte)
* [Rechercher des offres](/guides/recherche-offres)
