479a8de858
- agent/websocket.go: expose sendMessage() + notifyUI() pour broadcaster les résultats d'activation à tous les clients UI connectés - agent/ui.go: supprime forwardActivation(), utilise sendMessage() sur la connexion WS principale au lieu d'une connexion temporaire - agent/activation.go: ajoute os.MkdirAll avant l'écriture d'activation.json - server/prisma/schema.prisma: onDelete Cascade sur Node→Student - server/app/dashboard/students/page.tsx: nom cliquable vers fiche détail - server/app/dashboard/students/[id]/actions.ts: deleteMany → delete
42 lines
874 B
Go
42 lines
874 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type Activation struct {
|
|
Activated bool `json:"activated"`
|
|
StudentId string `json:"studentId,omitempty"`
|
|
StudentName string `json:"studentName,omitempty"`
|
|
Code string `json:"code,omitempty"`
|
|
}
|
|
|
|
func activationFile(dataDir string) string {
|
|
return filepath.Join(dataDir, "activation.json")
|
|
}
|
|
|
|
func loadActivation(dataDir string) (*Activation, error) {
|
|
f := activationFile(dataDir)
|
|
data, err := os.ReadFile(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var a Activation
|
|
err = json.Unmarshal(data, &a)
|
|
return &a, err
|
|
}
|
|
|
|
func saveActivation(dataDir string, a *Activation) error {
|
|
if err := os.MkdirAll(dataDir, 0755); err != nil {
|
|
return err
|
|
}
|
|
f := activationFile(dataDir)
|
|
data, err := json.MarshalIndent(a, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(f, data, 0644)
|
|
}
|