Files
Kazier/backend/handlers/router.go
T
m a6b7f2002b
CI / lint-backend (push) Failing after 1m39s
CI / lint-mobile (push) Canceled after 11m8s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
fix backend audit findings (auth, upload, sync, data, ocr, contract)
2026-09-21 19:59:52 +02:00

54 lines
1.7 KiB
Go

package handlers
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/kazier/backend/pkg/api"
)
// RegisterRoutes wires the full /api/v1 surface (public + protected).
// Public: /health, /devices, /auth/login, /shares/links/:token (résolution de
// lien anonyme). Everything else requires a user bearer token (subject =
// user_id, claim = device_id, cf. docs/api-v1.md §2).
func RegisterRoutes(r *gin.Engine) {
public := r.Group("/api/v1")
{
public.GET("/health", Health)
public.POST("/devices", DevicesRegister)
public.POST("/auth/login", AuthLogin)
public.GET("/shares/links/:token", ShareLinkGet)
}
protected := r.Group("/api/v1")
protected.Use(RequireAuth)
{
protected.GET("/files", FilesList)
// Verrou LOT 6 §1 : les routes statiques restent déclarées AVANT
// /files/:id (Gin priorise déjà le statique sur le paramétré, mais
// l'ordre source verrouille l'intention : /files/folders ne doit
// jamais être avalé par FilesGet avec id="folders").
protected.GET("/files/search", FilesSearch)
protected.GET("/files/folders", FoldersList)
protected.GET("/files/:id", FilesGet)
protected.GET("/files/:id/ocr", FilesGetOcr)
protected.DELETE("/files/:id", FilesDelete)
protected.POST("/files/upload", FilesUpload)
protected.GET("/users/resolve", ResolveUser)
protected.PATCH("/users/me/password", ChangePassword)
protected.POST("/ocr/jobs", OcrJobsCreate)
protected.GET("/ocr/jobs/:id", OcrJobsGet)
protected.POST("/sync/ops", SyncOpsPush)
protected.GET("/sync/permissions", SyncPermissionsGet)
}
// Route inconnue → enveloppe d'erreur du contrat (jamais de HTML).
r.NoRoute(func(c *gin.Context) {
api.Error(c, http.StatusNotFound, "NOT_FOUND", "route not found")
})
}