From 177d771acf741d45db40440b44bb0f02555221a7 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 30 Aug 2026 11:17:11 +0800 Subject: [PATCH] feat(upload): mount existing my/update/download routes on user API --- backend/plugins/domain/upload/plugin.go | 4 ++ backend/plugins/domain/upload/plugin_test.go | 53 ++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 backend/plugins/domain/upload/plugin_test.go diff --git a/backend/plugins/domain/upload/plugin.go b/backend/plugins/domain/upload/plugin.go index e6b998bb..3fa08eaf 100644 --- a/backend/plugins/domain/upload/plugin.go +++ b/backend/plugins/domain/upload/plugin.go @@ -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) diff --git a/backend/plugins/domain/upload/plugin_test.go b/backend/plugins/domain/upload/plugin_test.go new file mode 100644 index 00000000..39de4d5a --- /dev/null +++ b/backend/plugins/domain/upload/plugin_test.go @@ -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) + } + } +}