feat(upload): mount existing my/update/download routes on user API

This commit is contained in:
ryan
2026-08-30 11:17:11 +08:00
parent 6f25618e83
commit 177d771acf
2 changed files with 57 additions and 0 deletions
+4
View File
@@ -126,6 +126,10 @@ func (p *Plugin) Apply(ctx *core.Context) error {
uploadGroup.GET("", handler.ListFiles)
uploadGroup.DELETE("/:id", handler.DeleteFile)
uploadGroup.POST("/batch-download", handler.BatchDownloadFiles)
uploadGroup.GET("/my", handler.ListMyFiles)
uploadGroup.PUT("/:id", handler.UpdateMyFile)
uploadGroup.GET("/download/:id", handler.DownloadFile)
uploadGroup.POST("/download/batch", handler.BatchDownloadFiles)
}
adminUploadGroup := ctx.Router().Group("/api/v1/admin/uploads", loginMW)
@@ -0,0 +1,53 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package upload
import (
"context"
"testing"
"github.com/gin-gonic/gin"
"Wavelet/core"
"Wavelet/core/contracts"
)
type stubDBService struct{ contracts.DBService }
type stubStorageService struct{ contracts.StorageService }
type stubAuthService struct{ contracts.AuthService }
func (stubAuthService) RequireAuthMiddleware() any {
return gin.HandlerFunc(func(c *gin.Context) { c.Next() })
}
func TestUserUploadRoutes(t *testing.T) {
gin.SetMode(gin.TestMode)
ctx := core.NewContext(context.Background())
core.Provide[contracts.DBService](ctx, stubDBService{})
core.Provide[contracts.StorageService](ctx, stubStorageService{})
core.Provide[contracts.AuthService](ctx, stubAuthService{})
if err := New().Apply(ctx); err != nil {
t.Fatal(err)
}
want := []string{
"GET /api/v1/upload/my",
"PUT /api/v1/upload/:id",
"GET /api/v1/upload/download/:id",
"POST /api/v1/upload/download/batch",
"GET /api/v1/upload",
"POST /api/v1/upload/batch-download",
}
found := make(map[string]bool, len(want))
for _, rd := range ctx.Router().Routes() {
found[rd.Method+" "+rd.Path] = true
}
for _, key := range want {
if !found[key] {
t.Errorf("missing route %s", key)
}
}
}