Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-06-12 15:19:02 +08:00
30 changed files with 435 additions and 29 deletions

View File

@@ -23,6 +23,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: SaveCanteenTypeProductHandler(serverCtx),
},
},
//rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
)
}

View File

@@ -1,19 +1,20 @@
package svc
import (
"fusenapi/initalize"
"fusenapi/server/canteen/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn sqlx.SqlConn
MysqlConn *gorm.DB
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.SourceMysql),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}

View File

@@ -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),
)

View File

@@ -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)
}
}
}

View File

@@ -0,0 +1,31 @@
package logic
import (
"context"
"fusenapi/utils/basic"
"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)
}

View File

@@ -1,19 +1,20 @@
package svc
import (
config2 "fusenapi/server/data-transfer/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"fusenapi/initalize"
"fusenapi/server/data-transfer/internal/config"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config2.Config
Config config.Config
MysqlConn sqlx.SqlConn
MysqlConn *gorm.DB
}
func NewServiceContext(c config2.Config) *ServiceContext {
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.SourceMysql),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}

View File

@@ -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"`

View File

@@ -1,18 +1,20 @@
package svc
import (
"fusenapi/initalize"
"fusenapi/server/product/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
MysqlConn sqlx.SqlConn
Config config.Config
MysqlConn *gorm.DB
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: sqlx.NewMysql(c.DataSource),
MysqlConn: initalize.InitMysql(c.SourceMysql),
}
}