feat(backend): rouage gin /api/v1, enveloppe {data,meta}/{error}, health réel, stubs 501 + test de contrat routes
This commit is contained in:
@@ -1,17 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/vaultdrop/backend/config"
|
||||
"github.com/vaultdrop/backend/handlers"
|
||||
)
|
||||
|
||||
func newRouter() *gin.Engine {
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
api := r.Group("/api/v1")
|
||||
{
|
||||
api.GET("/health", handlers.Health)
|
||||
api.POST("/devices", handlers.DevicesRegister)
|
||||
|
||||
api.GET("/files", handlers.FilesList)
|
||||
api.GET("/files/search", handlers.FilesSearch)
|
||||
api.GET("/files/:id", handlers.FilesGet)
|
||||
api.DELETE("/files/:id", handlers.FilesDelete)
|
||||
api.GET("/files/folders", handlers.FoldersList)
|
||||
api.POST("/files/upload", handlers.FilesUpload)
|
||||
|
||||
api.POST("/ocr/jobs", handlers.OcrJobsCreate)
|
||||
api.GET("/ocr/jobs/:id", handlers.OcrJobsGet)
|
||||
|
||||
api.POST("/sync/ops", handlers.SyncOpsPush)
|
||||
api.GET("/sync/permissions", handlers.SyncPermissionsGet)
|
||||
}
|
||||
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
err, _ := config.LoadApplicationConfig()
|
||||
err, cfg := config.LoadApplicationConfig()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if err := newRouter().Run(fmt.Sprintf(":%d", cfg.Port)); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ func TestCreateDocument(t *testing.T) {
|
||||
|
||||
fmt.Println(document, directory)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// expectedRoutes mirrors the endpoints in mobile/api/client.ts (the contract).
|
||||
// Paths are full (under /api/v1), methods match the client calls exactly.
|
||||
var expectedRoutes = []string{
|
||||
"GET /api/v1/health",
|
||||
"POST /api/v1/devices",
|
||||
|
||||
"GET /api/v1/files",
|
||||
"GET /api/v1/files/:id",
|
||||
"DELETE /api/v1/files/:id",
|
||||
"GET /api/v1/files/search",
|
||||
"GET /api/v1/files/folders",
|
||||
"POST /api/v1/files/upload",
|
||||
|
||||
"POST /api/v1/ocr/jobs",
|
||||
"GET /api/v1/ocr/jobs/:id",
|
||||
|
||||
"POST /api/v1/sync/ops",
|
||||
"GET /api/v1/sync/permissions",
|
||||
}
|
||||
|
||||
func TestRoutesMatchClientContract(t *testing.T) {
|
||||
|
||||
registered := map[string]bool{}
|
||||
for _, route := range newRouter().Routes() {
|
||||
registered[route.Method+" "+route.Path] = true
|
||||
}
|
||||
|
||||
for _, want := range expectedRoutes {
|
||||
if !registered[want] {
|
||||
t.Errorf("missing route %q — must mirror mobile/api/client.ts", want)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user