V3 S3 : correction des faits (fiche document + correct_facts)
Backend : CorrectFacts (editor+, validation Go -> 400 jamais 500), op outbox correct_facts (full-replace jeu user), PATCH /files/:id/facts (renvoie jeu complet). Tests service + sync + handlers. Mobile (Room v20) : table resource_facts + FactsDao, FactsRepository (sync remplace-en-bloc, correction optimiste + outbox atomique), fiche « Ce qu'on a compris » sur le viewer (chips, suggéré grisé, édition par type, reset auto), bouton viewer si processed, FR/EN. Contrat docs/api-v1.md, V3.md (S1-S3 livrés, FTS -> v21).
This commit is contained in:
@@ -133,6 +133,54 @@ func FilesGetFacts(c *gin.Context) {
|
||||
api.OK(c, facts)
|
||||
}
|
||||
|
||||
// FilesCorrectFacts remplace le jeu `user` des faits (V3 S3) :
|
||||
// PATCH /files/:id/facts `{ facts: [...] }` (full-replace, jamais de diff).
|
||||
// Nécessite editor+ (comme update_metadata) ; viewer- → 404 NOT_FOUND.
|
||||
// Corps invalide (type inconnu, date non ISO, fait sans valeur) → 400.
|
||||
func FilesCorrectFacts(c *gin.Context) {
|
||||
if Store == nil {
|
||||
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
||||
return
|
||||
}
|
||||
userID := c.GetString(UserIDKey)
|
||||
id := c.Param("id")
|
||||
if !deviceIDPattern.MatchString(id) {
|
||||
api.Error(c, http.StatusNotFound, "NOT_FOUND", "file not found")
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Facts []service.FactDTO `json:"facts"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "invalid JSON body (expected { facts: [...] })")
|
||||
return
|
||||
}
|
||||
if req.Facts == nil {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "missing required field `facts`")
|
||||
return
|
||||
}
|
||||
if len(req.Facts) > 100 {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "`facts` too long (max 100)")
|
||||
return
|
||||
}
|
||||
if err := Store.CorrectFacts(userID, id, req.Facts); err != nil {
|
||||
// Erreurs de validation (type/date/valeur) → 400 explicite, pas 500 :
|
||||
// ce sont des fautes client, jamais des pannes (cf. FEEDBACK #8).
|
||||
if errors.Is(err, service.ErrInvalidFact) {
|
||||
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", err.Error())
|
||||
return
|
||||
}
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
facts, err := Store.GetFacts(userID, id)
|
||||
if err != nil {
|
||||
writeError(c, err)
|
||||
return
|
||||
}
|
||||
api.OK(c, facts)
|
||||
}
|
||||
|
||||
// own ou shared) : GET /files/:id/content. Réponse binaire (Content-Type du
|
||||
// fichier, Content-Disposition inline) — jamais d'enveloppe {data}. Supporte
|
||||
// Range via http.ServeContent (Gin c.File). Sans bytes serveur (ressource
|
||||
|
||||
Reference in New Issue
Block a user