Files
Kazier/backend/handlers/store.go
T
venture 1e38e6e4ee V3 S6 : confiance (révocation, quota, appareils, conflits) + import + onboarding
Backend : token_version (000022, claim tv, 401 si révoqué, bump au
password — fin limite V1), quota (000023 idempotente, colonne héritée
de 000001, 413 QUOTA_EXCEEDED, GET /users/me/usage), devices
(GET + DELETE révocation, EnforceDeviceExists en prod), renames
concurrents transparents (baseUpdatedAt + conflicts[] non-fataux,
tolérance 2 s). Tests service + handlers + migrations + auth.

Mobile : pipeline conflits (DTO + SyncConflictStore + worker + dialogue),
baseUpdatedAt prêt, liens 7j par défaut, écran Appareils (+ quota),
import classeur unifié (scan/note/dossier), onboarding cercle Famille.

Contrat docs/api-v1.md, V3.md (S6 livré).
2026-09-26 11:56:39 +02:00

46 lines
1.6 KiB
Go

package handlers
import (
"errors"
"log"
"github.com/gin-gonic/gin"
"github.com/kazier/backend/pkg/api"
"github.com/kazier/backend/repository"
"github.com/kazier/backend/service"
)
// Store is the business layer used by handlers; set once at startup
// (cmd/server). Nil until then.
var Store *service.Resources
// Ocr queues/reads OCR jobs; set once at startup alongside Store.
var Ocr *service.Ocr
// writeError maps repository/service sentinels to contract error codes.
func writeError(c *gin.Context, err error) {
switch {
case errors.Is(err, repository.ErrNotFound):
api.Error(c, 404, "NOT_FOUND", "resource not found")
case errors.Is(err, repository.ErrGranteeNotFound):
api.Error(c, 404, "GRANTEE_NOT_FOUND", "the specified user does not exist")
case errors.Is(err, repository.ErrGroupNotFound):
api.Error(c, 404, "GROUP_NOT_FOUND", "the specified group does not exist")
case errors.Is(err, repository.ErrNameConflict):
api.Error(c, 409, "NAME_CONFLICT", "a resource with this name already exists here")
case errors.Is(err, service.ErrFileTooLarge):
api.Error(c, 413, "FILE_TOO_LARGE", "file exceeds the maximum allowed size")
case errors.Is(err, service.ErrQuotaExceeded):
api.Error(c, 413, "QUOTA_EXCEEDED", "storage quota exceeded")
default:
// Jamais de err.Error() brut au client (fuite SQL/FS/paths, cf.
// FEEDBACK #8) : message générique, détail au log serveur.
path := ""
if c.Request != nil && c.Request.URL != nil {
path = c.Request.URL.Path
}
log.Printf("internal error: path=%s err=%v", path, err)
api.Error(c, 500, "INTERNAL", "internal error")
}
}