api: return localized fields only in the requested ?lang=

appresult.Localize, the first admin middleware, rewrites JSON responses so
every {en, ru, tm} object becomes the plain string for ?lang= (tm, ru, en;
default tm), falling back tm -> ru -> en when that translation is empty.
?lang=all keeps the full objects for edit forms; other values are 400.
Key order and number precision are preserved; non-JSON responses and
/swagger are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
guwandykandClaude Opus 5.5 committed 2026-10-24 14:19:24 +05:00
1 parent a715cd23ea
commit 75b551e281
7 files changed
+348 -5

No files matched your search

+3
View File
@@ -7,6 +7,7 @@ import (
"online-back/internal/analytics"
analyticsdb "online-back/internal/analytics/db"
"online-back/internal/appresult"
"online-back/internal/backup"
backupdb "online-back/internal/backup/db"
"online-back/internal/cards"
@@ -65,6 +66,8 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.
}))
adminGroup := router.Group(adminAPIPrefix)
// First, so it sees every admin response; /swagger stays outside it.
adminGroup.Use(appresult.Localize())
adminGroup.Use(activitylog.Record(activitylogdb.NewRepository(client, logger), logger))
if err := perm.Sync(context.Background(), client); err != nil {
logger.Fatalf("rbac: sync permission catalog: %v", err)