diff --git a/server/data-transfer/internal/handler/routes.go b/server/data-transfer/internal/handler/routes.go index d47e16b2..80e849b9 100644 --- a/server/data-transfer/internal/handler/routes.go +++ b/server/data-transfer/internal/handler/routes.go @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/upload/qrcode", Handler: UploadQrcodeHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/upload/up-logo", + Handler: UploadLogoHandler(serverCtx), + }, }, rest.WithJwt(serverCtx.Config.Auth.AccessSecret), ) diff --git a/server/data-transfer/internal/handler/uploadlogohandler.go b/server/data-transfer/internal/handler/uploadlogohandler.go new file mode 100644 index 00000000..4bde73ae --- /dev/null +++ b/server/data-transfer/internal/handler/uploadlogohandler.go @@ -0,0 +1,37 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/server/data-transfer/internal/logic" + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" +) + +func UploadLogoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UploadLogoReq + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &types.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + + l := logic.NewUploadLogoLogic(r.Context(), svcCtx) + resp := l.UploadLogo(&req) + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/data-transfer/internal/logic/uploadlogologic.go b/server/data-transfer/internal/logic/uploadlogologic.go new file mode 100644 index 00000000..7f9c26c3 --- /dev/null +++ b/server/data-transfer/internal/logic/uploadlogologic.go @@ -0,0 +1,30 @@ +package logic + +import ( + "context" + + "fusenapi/server/data-transfer/internal/svc" + "fusenapi/server/data-transfer/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UploadLogoLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUploadLogoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogoLogic { + return &UploadLogoLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq) (resp *types.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/data-transfer/internal/types/types.go b/server/data-transfer/internal/types/types.go index e176e1da..043ee41e 100644 --- a/server/data-transfer/internal/types/types.go +++ b/server/data-transfer/internal/types/types.go @@ -26,6 +26,19 @@ type UploadQrcodeRsp struct { Data string `json:"d"` } +type UploadLogoReq struct { + SkuId int64 `json:"skuId"` + IsRemoveBg bool `json:"is_remove_bg"` + Proportion int64 `json:"proportion"` +} + +type UploadLogoRsp struct { + NobgUrl string `json:"nobg_url"` + ThumbnailUrl string `json:"thumbnail_url"` + IsmaxProportion bool `json:"ismax_proportion"` + ImgColor []string `json:"img_color"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/data-transfer.api b/server_api/data-transfer.api index 443759c3..893859e3 100644 --- a/server_api/data-transfer.api +++ b/server_api/data-transfer.api @@ -22,6 +22,9 @@ service data-transfer { //生成二维码 @handler UploadQrcodeHandler post /upload/qrcode (UploadQrcodeReq) returns (response); + //上传logo + @handler UploadLogoHandler + post /upload/up-logo (UploadLogoReq) returns (response); } //获取标准logo列表 @@ -43,4 +46,17 @@ type UploadQrcodeReq { type UploadQrcodeRsp { Link string `json:"link"` Data string `json:"d"` +} + +//上传logo +type UploadLogoReq { + SkuId int64 `json:"skuId"` + IsRemoveBg bool `json:"is_remove_bg"` + Proportion int64 `json:"proportion"` +} +type UploadLogoRsp { + NobgUrl string `json:"nobg_url"` + ThumbnailUrl string `json:"thumbnail_url"` + IsmaxProportion bool `json:"ismax_proportion"` + ImgColor []string `json:"img_color"` } \ No newline at end of file