This commit is contained in:
laodaming
2023-06-01 18:34:41 +08:00
parent 08e6f00ff5
commit 2d7ea2e302
10 changed files with 304 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package handler
import (
"fusenapi/utils/auth"
"net/http"
"fusenapi/product/internal/logic"
@@ -11,14 +12,19 @@ import (
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//检测登录权限
userInfo, err := auth.CheckAuth(r)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
var req types.GetProductListReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
resp, err := l.GetProductList(&req)
resp, err := l.GetProductList(&req, userInfo.UserId)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {

View File

@@ -2,6 +2,8 @@ package logic
import (
"context"
"errors"
"fusenapi/model"
"fusenapi/utils/image"
"fusenapi/product/internal/svc"
@@ -25,11 +27,19 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
// 获取产品列表
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp *types.Response, err error) {
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, uid int64) (resp *types.Response, err error) {
//获取合适尺寸
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取是否存在千人千面
userModel := model.NewFsUserModel(l.svcCtx.MysqlConn)
userInfo, err := userModel.FindOne(l.ctx, uid)
if err != nil {
return nil, err
}
if userInfo.Id == 0 {
return nil, errors.New("user not exists")
}
return
}

View File

@@ -1,19 +1,18 @@
package svc
import (
"fusenapi/model"
"fusenapi/product/internal/config"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
type ServiceContext struct {
Config config.Config
FsProductModel model.FsProductModel
Config config.Config
MysqlConn sqlx.SqlConn
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
FsProductModel: model.NewFsProductModel(sqlx.NewMysql(c.DataSource)),
Config: c,
MysqlConn: sqlx.NewMysql(c.DataSource),
}
}

View File

@@ -22,7 +22,6 @@ func main() {
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)