Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
116171dddd
|
@ -1,7 +1,7 @@
|
|||
#! /bin/bash
|
||||
name=${1%%\\*}
|
||||
|
||||
options=("backend")
|
||||
options=("backend" "product-template" "product-model")
|
||||
for option in "${options[@]}"; do
|
||||
if [ "$name" = "$option" ]; then
|
||||
echo "不能在"$name"里使用"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#! /bin/bash
|
||||
name=${1%%\\*}
|
||||
options=("backend" "product-template" "backend2")
|
||||
options=("backend" "product-template" "product-model")
|
||||
for option in "${options[@]}"; do
|
||||
if [ "$name" = "$option" ]; then
|
||||
echo $name
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product-model/internal/logic"
|
||||
|
@ -16,6 +17,37 @@ import (
|
|||
|
||||
func GetModelDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.BackendUserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil || claims == nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req types.GetModelDetailReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
@ -28,7 +60,7 @@ func GetModelDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetModelDetailLogic(r.Context(), svcCtx)
|
||||
resp := l.GetModelDetail(&req, r)
|
||||
resp := l.GetModelDetail(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product-model/internal/logic"
|
||||
|
@ -16,6 +17,37 @@ import (
|
|||
|
||||
func GetModelOtherInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.BackendUserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil || claims == nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req types.GetModelOtherInfoReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
@ -28,7 +60,7 @@ func GetModelOtherInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetModelOtherInfoLogic(r.Context(), svcCtx)
|
||||
resp := l.GetModelOtherInfo(&req, r)
|
||||
resp := l.GetModelOtherInfo(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/product-model/internal/logic"
|
||||
|
@ -16,6 +17,37 @@ import (
|
|||
|
||||
func UpdateProductModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.BackendUserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil || claims == nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetBackendUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req types.UpdateProductModelReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
|
@ -28,7 +60,7 @@ func UpdateProductModelHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUpdateProductModelLogic(r.Context(), svcCtx)
|
||||
resp := l.UpdateProductModel(&req, r)
|
||||
resp := l.UpdateProductModel(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-model/internal/svc"
|
||||
"fusenapi/server/product-model/internal/types"
|
||||
|
@ -30,17 +28,7 @@ func NewGetModelDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||
}
|
||||
}
|
||||
|
||||
func (l *GetModelDetailLogic) GetModelDetail(req *types.GetModelDetailReq, r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *GetModelDetailLogic) GetModelDetail(req *types.GetModelDetailReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
if req.ModelId <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param model_id is required")
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-model/internal/svc"
|
||||
"fusenapi/server/product-model/internal/types"
|
||||
|
@ -31,17 +28,7 @@ func NewGetModelOtherInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
}
|
||||
|
||||
func (l *GetModelOtherInfoLogic) GetModelOtherInfo(req *types.GetModelOtherInfoReq, r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *GetModelOtherInfoLogic) GetModelOtherInfo(req *types.GetModelOtherInfoReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
//获取所有灯光列表
|
||||
modelLightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAll(l.ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,9 +5,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -33,17 +33,7 @@ func NewUpdateProductModelLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
}
|
||||
|
||||
func (l *UpdateProductModelLogic) UpdateProductModel(req *types.UpdateProductModelReq, r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *UpdateProductModelLogic) UpdateProductModel(req *types.UpdateProductModelReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
if req.ModelData.Id <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "modelData`s id is required")
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func SaveBaseMapHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
}
|
||||
|
||||
l := logic.NewSaveBaseMapLogic(r.Context(), svcCtx)
|
||||
resp := l.SaveBaseMap(userinfo)
|
||||
resp := l.SaveBaseMap(r, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/product-template/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
@ -29,17 +26,7 @@ func NewGetBaseMapListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||
}
|
||||
}
|
||||
|
||||
func (l *GetBaseMapListLogic) GetBaseMapList(r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *GetBaseMapListLogic) GetBaseMapList(userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
baseMapFields := "id,name,url,ctime"
|
||||
baseMapList, err := l.svcCtx.AllModels.FsProductTemplateBasemap.GetAllEnabledList(l.ctx, baseMapFields)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -33,17 +33,7 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
}
|
||||
}
|
||||
|
||||
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
if req.TemplateId <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param template_id")
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@ package logic
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/product-template/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
@ -31,17 +30,7 @@ func NewSaveBaseMapLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveB
|
|||
}
|
||||
}
|
||||
|
||||
func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *SaveBaseMapLogic) SaveBaseMap(r *http.Request, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
bodyBytes, err := ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
var postData []types.SaveBaseMapReq
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product-template/internal/svc"
|
||||
"fusenapi/server/product-template/internal/types"
|
||||
|
@ -30,17 +29,7 @@ func NewUpdateTemplateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
|
|||
}
|
||||
}
|
||||
|
||||
func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, r *http.Request) (resp *basic.Response) {
|
||||
authKey := r.Header.Get("Auth-Key")
|
||||
genentModel := gmodel.NewFsGerentModel(l.svcCtx.MysqlConn)
|
||||
_, err := genentModel.Find(l.ctx, authKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first..")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||
}
|
||||
func (l *UpdateTemplateLogic) UpdateTemplate(req *types.UpdateTemplateReq, userInfo *auth.BackendUserInfo) (resp *basic.Response) {
|
||||
if req.ModelId <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param modelId is required")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user