fix: some api bug
This commit is contained in:
@@ -9,6 +9,12 @@ Prometheus:
|
||||
|
||||
# k8s://juwan/<service name>:8080
|
||||
|
||||
ShopRpcConf:
|
||||
Target: k8s://juwan/shop-rpc-svc.juwan:8080
|
||||
# ===== PROC CONFIG =====
|
||||
#ShopRpcConf:
|
||||
# Target: k8s://juwan/shop-rpc-svc.juwan:8080
|
||||
|
||||
|
||||
# ===== DEV CONFIG ====
|
||||
ShopRpcConf:
|
||||
Endpoints:
|
||||
- shop-rpc:8080
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 接受邀请
|
||||
@@ -26,12 +21,7 @@ func AcceptInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewAcceptInvitationLogic(ctx, svcCtx)
|
||||
l := shop.NewAcceptInvitationLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AcceptInvitation(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 新增店铺公告
|
||||
@@ -26,12 +21,7 @@ func AddAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewAddAnnouncementLogic(ctx, svcCtx)
|
||||
l := shop.NewAddAnnouncementLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AddAnnouncement(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 创建店铺
|
||||
@@ -26,12 +21,7 @@ func CreateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewCreateShopLogic(ctx, svcCtx)
|
||||
l := shop.NewCreateShopLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateShop(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 删除店铺公告
|
||||
@@ -26,12 +21,7 @@ func DeleteAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewDeleteAnnouncementLogic(ctx, svcCtx)
|
||||
l := shop.NewDeleteAnnouncementLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeleteAnnouncement(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取当前用户的店铺
|
||||
@@ -26,12 +21,7 @@ func GetMyShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewGetMyShopLogic(ctx, svcCtx)
|
||||
l := shop.NewGetMyShopLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetMyShop(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -6,11 +6,10 @@ package shop
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取店铺详情
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取收入统计
|
||||
@@ -26,12 +21,7 @@ func GetShopIncomeStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewGetShopIncomeStatsLogic(ctx, svcCtx)
|
||||
l := shop.NewGetShopIncomeStatsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetShopIncomeStats(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -6,11 +6,10 @@ package shop
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取店长的店铺
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 邀请打手
|
||||
@@ -26,12 +21,7 @@ func InvitePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewInvitePlayerLogic(ctx, svcCtx)
|
||||
l := shop.NewInvitePlayerLogic(r.Context(), svcCtx)
|
||||
resp, err := l.InvitePlayer(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 拒绝邀请
|
||||
@@ -26,12 +21,7 @@ func RejectInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewRejectInvitationLogic(ctx, svcCtx)
|
||||
l := shop.NewRejectInvitationLogic(r.Context(), svcCtx)
|
||||
resp, err := l.RejectInvitation(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 移除打手
|
||||
@@ -26,12 +21,7 @@ func RemovePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewRemovePlayerLogic(ctx, svcCtx)
|
||||
l := shop.NewRemovePlayerLogic(r.Context(), svcCtx)
|
||||
resp, err := l.RemovePlayer(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
@@ -26,12 +22,7 @@ func UpdateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewUpdateShopLogic(ctx, svcCtx)
|
||||
l := shop.NewUpdateShopLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateShop(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -4,17 +4,12 @@
|
||||
package shop
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"juwan-backend/common/utils/contextj"
|
||||
"juwan-backend/common/utils/httpj"
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/shop/api/internal/logic/shop"
|
||||
"juwan-backend/app/shop/api/internal/svc"
|
||||
"juwan-backend/app/shop/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 更新店铺模板
|
||||
@@ -26,12 +21,7 @@ func UpdateShopTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
userId, err := httpj.GetUserIdFromHeader(r.Header)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(403, errors.New("forbidden: user not authenticated")))
|
||||
}
|
||||
ctx := contextj.WithUserID(r.Context(), userId)
|
||||
l := shop.NewUpdateShopTemplateLogic(ctx, svcCtx)
|
||||
l := shop.NewUpdateShopTemplateLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateShopTemplate(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
|
||||
@@ -36,6 +36,9 @@ func (l *CreateShopLogic) CreateShop(req *types.CreateShopReq) (resp *types.Shop
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ownerID == 0 {
|
||||
return nil, errors.New("user not authenticated")
|
||||
}
|
||||
|
||||
if req.Name == "" {
|
||||
return nil, errors.New("name is required")
|
||||
|
||||
@@ -46,6 +46,7 @@ func (l *UpdateShopLogic) UpdateShop(req *types.UpdateShopReq) (resp *types.Shop
|
||||
if current.Shops.OwnerId != userID {
|
||||
return nil, contextj.ERRILLEGALUSER
|
||||
}
|
||||
logx.Debugf("update shop %+v", req)
|
||||
|
||||
name := current.Shops.Name
|
||||
if req.Name != "" {
|
||||
|
||||
@@ -6,18 +6,22 @@ package svc
|
||||
import (
|
||||
"juwan-backend/app/shop/api/internal/config"
|
||||
"juwan-backend/app/shop/rpc/shopservice"
|
||||
"juwan-backend/common/middlewares"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
ShopRpc shopservice.ShopService
|
||||
Config config.Config
|
||||
ShopRpc shopservice.ShopService
|
||||
HeaderExtractorMiddleware rest.Middleware
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)),
|
||||
Config: c,
|
||||
ShopRpc: shopservice.NewShopService(zrpc.MustNewClient(c.ShopRpcConf)),
|
||||
HeaderExtractorMiddleware: middlewares.NewHeaderExtractorMiddleware().Handle,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"juwan-backend/common/middlewares"
|
||||
|
||||
"juwan-backend/app/shop/api/internal/config"
|
||||
"juwan-backend/app/shop/api/internal/handler"
|
||||
@@ -24,6 +25,8 @@ func main() {
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rest.MustNewServer(c.RestConf)
|
||||
server.Use(middlewares.NewHeaderExtractorMiddleware().Handle)
|
||||
server.Use(middlewares.NewRequestMiddleware().Handle)
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
Reference in New Issue
Block a user