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:
@@ -93,7 +93,39 @@ func (r *Resources) ListFacts(resourceID string) ([]FactRow, error) {
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// factNeedingExtract is a file with OCR text but no auto facts yet.
|
||||
// CorrectFacts fully replaces the origin='user' set of a resource (S3 :
|
||||
// correction en un tap — le client envoie le jeu corrigé complet, pas un
|
||||
// diff). Auto facts are never touched. Empty params clears user corrections
|
||||
// (back to pure auto).
|
||||
func (r *Resources) CorrectFacts(resourceID string, params []FactParam) error {
|
||||
tx, err := r.DB.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback() //nolint:errcheck — no-op after Commit.
|
||||
if _, err := tx.Exec(
|
||||
`DELETE FROM resource_facts WHERE resource_id = $1 AND origin = 'user'`,
|
||||
resourceID,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, p := range params {
|
||||
id, err := NewIDErr()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(
|
||||
`INSERT INTO resource_facts
|
||||
(id, resource_id, fact_type, value_text, value_num, value_date, confidence, origin)
|
||||
VALUES ($1, $2, $3, NULLIF($4, ''), $5, NULLIF($6, '')::date, $7, 'user')`,
|
||||
id, resourceID, p.Type, p.ValueText, nullableFloat(p.ValueNum), derefStr(p.ValueDate), clamp01(p.Confidence),
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
type factNeedingExtract struct {
|
||||
ResourceID string
|
||||
Text string
|
||||
|
||||
Reference in New Issue
Block a user