Files
quyun-v2/backend/app/http/v1/common.go
Rogee 54de243fa1 feat: Refactor user context handling and service methods
- Updated middleware to fetch user and tenant models by ID and set them in context.
- Refactored common service methods to accept userID as a parameter instead of extracting from context.
- Modified content service methods to include userID as a parameter for better clarity and performance.
- Adjusted coupon, creator, notification, order, tenant, user, and wallet services to utilize userID directly.
- Enhanced context key constants for improved readability and maintainability.
2025-12-30 22:49:26 +08:00

38 lines
859 B
Go

package v1
import (
"mime/multipart"
"quyun/v2/app/http/v1/dto"
"quyun/v2/app/services"
"quyun/v2/pkg/consts"
"github.com/gofiber/fiber/v3"
"github.com/spf13/cast"
)
// @provider
type Common struct{}
// Upload file
//
// @Router /v1/upload [post]
// @Summary Upload file
// @Description Upload file
// @Tags Common
// @Accept multipart/form-data
// @Produce json
// @Param file formData file true "File"
// @Param type formData string false "Type enum(image, video, audio)"
// @Success 200 {object} dto.UploadResult
// @Bind file file
// @Bind typeArg body key(type)
func (c *Common) Upload(ctx fiber.Ctx, file *multipart.FileHeader, typeArg *string) (*dto.UploadResult, error) {
val := ""
if typeArg != nil {
val = *typeArg
}
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
return services.Common.Upload(ctx.Context(), uid, file, val)
}