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)
|
||||
|
||||
+36
-14
@@ -1,7 +1,6 @@
|
||||
Name: pb.rpc
|
||||
ListenOn: 0.0.0.0:8080
|
||||
|
||||
|
||||
Prometheus:
|
||||
Host: 0.0.0.0
|
||||
Port: 4001
|
||||
@@ -12,26 +11,49 @@ Prometheus:
|
||||
# - 127.0.0.1:2379
|
||||
# Key: pb.rpc
|
||||
|
||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||
# ===== PROC Config =====
|
||||
#SnowflakeRpcConf:
|
||||
# Target: k8s://juwan/snowflake-svc:8080
|
||||
#UsersRpcConf:
|
||||
# Target: k8s://juwan/user-rpc-svc:8080
|
||||
|
||||
#DB:
|
||||
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@{DB_HOST_RW}.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
# Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@{BD_HOST_RO}.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
#
|
||||
#
|
||||
#CacheConf:
|
||||
# - Host: "${REDIS_M_HOST}"
|
||||
# Type: node
|
||||
# Pass: "${REDIS_PASSWORD}"
|
||||
# User: "default"
|
||||
# - Host: "${REDIS_S_HOST}"
|
||||
# Type: node
|
||||
# Pass: "${REDIS_PASSWORD}"
|
||||
# User: "default"
|
||||
|
||||
# ===== DEV Config =====
|
||||
SnowflakeRpcConf:
|
||||
Target: k8s://juwan/snowflake-svc:8080
|
||||
|
||||
Endpoints:
|
||||
- snowflake:8080
|
||||
-
|
||||
UsersRpcConf:
|
||||
Endpoints:
|
||||
- user-rpc:8080
|
||||
|
||||
DB:
|
||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
CacheConf:
|
||||
- Host: "${REDIS_M_HOST}"
|
||||
- Host: "${REDIS_HOST}:${REDIS_PORT}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
- Host: "${REDIS_S_HOST}"
|
||||
Type: node
|
||||
Pass: "${REDIS_PASSWORD}"
|
||||
User: "default"
|
||||
|
||||
Log:
|
||||
Level: info
|
||||
|
||||
|
||||
# Target: k8s://juwan/<service name>.<namespace>:8080
|
||||
#DB:
|
||||
# Master: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-rw.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
# Slaves: "postgresql://${PD_USERNAME}:${DB_PASSWORD}@user-db-ro.juwan:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
SnowflakeRpcConf zrpc.RpcClientConf
|
||||
UsersRpcConf zrpc.RpcClientConf
|
||||
DB struct {
|
||||
Master string
|
||||
Slaves string
|
||||
|
||||
@@ -4,7 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
pb2 "juwan-backend/app/users/rpc/pb"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"juwan-backend/app/shop/rpc/internal/svc"
|
||||
"juwan-backend/app/shop/rpc/pb"
|
||||
@@ -27,8 +31,25 @@ func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShops
|
||||
}
|
||||
}
|
||||
|
||||
var allowedRoles = []string{"owner", "admin"}
|
||||
var allowedCommissionTypes = []string{"fixed", "percentage"}
|
||||
var allowedDispatchModes = []string{"manual", "auto"}
|
||||
|
||||
// -----------------------shops-----------------------
|
||||
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||
user, err := l.svcCtx.UsersRpc.GetUsersById(l.ctx, &pb2.GetUsersByIdReq{
|
||||
Id: in.OwnerId,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("add shops err: %v", err)
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
|
||||
if !slices.Contains(allowedRoles, user.Users.CurrentRole) {
|
||||
logx.Errorf("add shops err: user %v has no permission to add shop", in.OwnerId)
|
||||
return nil, errors.New("no permission to add shop")
|
||||
}
|
||||
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
@@ -44,28 +65,53 @@ func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||
|
||||
rating, err := decimal.NewFromString(in.Rating)
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices new from string err:%v", err)
|
||||
return nil, errors.New("invalid rating")
|
||||
}
|
||||
commissionValue, err := decimal.NewFromString(in.CommissionValue)
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices new from string err:%v", err)
|
||||
return nil, errors.New("invalid commissionValue")
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopModelRO.Shops.Create().
|
||||
commissionType := strings.ToLower(strings.TrimSpace(in.CommissionType))
|
||||
if commissionType == "" {
|
||||
commissionType = "percentage"
|
||||
}
|
||||
if !slices.Contains(allowedCommissionTypes, commissionType) {
|
||||
logx.Errorf("addPlayerServices contains err: invalid commissionType %v", in.CommissionType)
|
||||
return nil, errors.New("invalid commissionType")
|
||||
}
|
||||
|
||||
dispatchMode := strings.ToLower(strings.TrimSpace(in.DispatchMode))
|
||||
if dispatchMode == "" {
|
||||
dispatchMode = "manual"
|
||||
}
|
||||
if !slices.Contains(allowedDispatchModes, dispatchMode) {
|
||||
logx.Errorf("addPlayerServices contains err: invalid dispatchMode %v", in.DispatchMode)
|
||||
return nil, errors.New("invalid dispatchMode")
|
||||
}
|
||||
|
||||
announcements := schema.TextArray{Elements: in.Announcements, Valid: true}
|
||||
if announcements.Elements == nil {
|
||||
announcements.Elements = []string{}
|
||||
}
|
||||
|
||||
_, err = l.svcCtx.ShopModelRW.Shops.Create().
|
||||
SetID(idResp.Id).
|
||||
SetOwnerID(in.OwnerId).
|
||||
SetOwnerID(idResp.Id).
|
||||
SetName(in.Name).
|
||||
SetBanner(in.Banner).
|
||||
SetDescription(in.Description).
|
||||
SetRating(rating).
|
||||
SetTotalOrders(int(in.TotalOrders)).
|
||||
SetPlayerCount(int(in.PlayerCount)).
|
||||
SetNillableCommissionType(&in.CommissionType).
|
||||
SetCommissionType(commissionType).
|
||||
SetCommissionValue(commissionValue).
|
||||
SetAllowMultiShop(in.AllowMultiShop).
|
||||
SetAllowIndependentOrders(in.AllowIndependentOrders).
|
||||
SetDispatchMode(in.DispatchMode).
|
||||
SetAnnouncements(in.Announcements).
|
||||
SetDispatchMode(dispatchMode).
|
||||
SetAnnouncements(announcements).
|
||||
SetTemplateConfig(templateConfig).
|
||||
Save(l.ctx)
|
||||
|
||||
@@ -73,5 +119,6 @@ func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
return nil, errors.New("add player service failed")
|
||||
}
|
||||
logx.Debugf("shop created with id: %v", idResp.Id)
|
||||
return &pb.AddShopsResp{}, nil
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsBy
|
||||
AllowMultiShop: shop.AllowMultiShop,
|
||||
AllowIndependentOrders: shop.AllowIndependentOrders,
|
||||
DispatchMode: shop.DispatchMode,
|
||||
Announcements: shop.Announcements,
|
||||
Announcements: shop.Announcements.Elements,
|
||||
TemplateConfig: string(templateConfigBytes),
|
||||
CreatedAt: shop.CreatedAt.Unix(),
|
||||
UpdatedAt: shop.UpdatedAt.Unix(),
|
||||
|
||||
@@ -124,7 +124,7 @@ func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsRe
|
||||
AllowMultiShop: item.AllowMultiShop,
|
||||
AllowIndependentOrders: item.AllowIndependentOrders,
|
||||
DispatchMode: item.DispatchMode,
|
||||
Announcements: item.Announcements,
|
||||
Announcements: item.Announcements.Elements,
|
||||
TemplateConfig: string(templateConfigBytes),
|
||||
CreatedAt: item.CreatedAt.Unix(),
|
||||
UpdatedAt: item.UpdatedAt.Unix(),
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"time"
|
||||
|
||||
@@ -75,7 +76,7 @@ func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsRe
|
||||
SetAllowIndependentOrders(in.AllowIndependentOrders)
|
||||
|
||||
if len(in.Announcements) > 0 {
|
||||
updater = updater.SetAnnouncements(in.Announcements)
|
||||
updater = updater.SetAnnouncements(schema.TextArray{Elements: in.Announcements, Valid: true})
|
||||
}
|
||||
|
||||
if in.TemplateConfig != "" {
|
||||
|
||||
@@ -94,7 +94,7 @@ var (
|
||||
{Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true},
|
||||
{Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"},
|
||||
{Name: "announcements", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "announcements", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "text[]"}},
|
||||
{Name: "template_config", Type: field.TypeJSON, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
@@ -1437,8 +1438,7 @@ type ShopsMutation struct {
|
||||
allow_multi_shop *bool
|
||||
allow_independent_orders *bool
|
||||
dispatch_mode *string
|
||||
announcements *[]string
|
||||
appendannouncements []string
|
||||
announcements *schema.TextArray
|
||||
template_config *map[string]interface{}
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
@@ -2138,13 +2138,12 @@ func (m *ShopsMutation) ResetDispatchMode() {
|
||||
}
|
||||
|
||||
// SetAnnouncements sets the "announcements" field.
|
||||
func (m *ShopsMutation) SetAnnouncements(s []string) {
|
||||
m.announcements = &s
|
||||
m.appendannouncements = nil
|
||||
func (m *ShopsMutation) SetAnnouncements(sa schema.TextArray) {
|
||||
m.announcements = &sa
|
||||
}
|
||||
|
||||
// Announcements returns the value of the "announcements" field in the mutation.
|
||||
func (m *ShopsMutation) Announcements() (r []string, exists bool) {
|
||||
func (m *ShopsMutation) Announcements() (r schema.TextArray, exists bool) {
|
||||
v := m.announcements
|
||||
if v == nil {
|
||||
return
|
||||
@@ -2155,7 +2154,7 @@ func (m *ShopsMutation) Announcements() (r []string, exists bool) {
|
||||
// OldAnnouncements returns the old "announcements" field's value of the Shops entity.
|
||||
// If the Shops object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err error) {
|
||||
func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v schema.TextArray, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAnnouncements is only allowed on UpdateOne operations")
|
||||
}
|
||||
@@ -2169,23 +2168,9 @@ func (m *ShopsMutation) OldAnnouncements(ctx context.Context) (v []string, err e
|
||||
return oldValue.Announcements, nil
|
||||
}
|
||||
|
||||
// AppendAnnouncements adds s to the "announcements" field.
|
||||
func (m *ShopsMutation) AppendAnnouncements(s []string) {
|
||||
m.appendannouncements = append(m.appendannouncements, s...)
|
||||
}
|
||||
|
||||
// AppendedAnnouncements returns the list of values that were appended to the "announcements" field in this mutation.
|
||||
func (m *ShopsMutation) AppendedAnnouncements() ([]string, bool) {
|
||||
if len(m.appendannouncements) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
return m.appendannouncements, true
|
||||
}
|
||||
|
||||
// ClearAnnouncements clears the value of the "announcements" field.
|
||||
func (m *ShopsMutation) ClearAnnouncements() {
|
||||
m.announcements = nil
|
||||
m.appendannouncements = nil
|
||||
m.clearedFields[shops.FieldAnnouncements] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -2198,7 +2183,6 @@ func (m *ShopsMutation) AnnouncementsCleared() bool {
|
||||
// ResetAnnouncements resets all changes to the "announcements" field.
|
||||
func (m *ShopsMutation) ResetAnnouncements() {
|
||||
m.announcements = nil
|
||||
m.appendannouncements = nil
|
||||
delete(m.clearedFields, shops.FieldAnnouncements)
|
||||
}
|
||||
|
||||
@@ -2581,7 +2565,7 @@ func (m *ShopsMutation) SetField(name string, value ent.Value) error {
|
||||
m.SetDispatchMode(v)
|
||||
return nil
|
||||
case shops.FieldAnnouncements:
|
||||
v, ok := value.([]string)
|
||||
v, ok := value.(schema.TextArray)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
|
||||
@@ -76,10 +76,6 @@ func init() {
|
||||
shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string)
|
||||
// shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
||||
shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error)
|
||||
// shopsDescAnnouncements is the schema descriptor for announcements field.
|
||||
shopsDescAnnouncements := shopsFields[13].Descriptor()
|
||||
// shops.DefaultAnnouncements holds the default value on creation for the announcements field.
|
||||
shops.DefaultAnnouncements = shopsDescAnnouncements.Default.([]string)
|
||||
// shopsDescCreatedAt is the schema descriptor for created_at field.
|
||||
shopsDescCreatedAt := shopsFields[15].Descriptor()
|
||||
// shops.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
@@ -8,11 +11,53 @@ import (
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
var shopDefaultRating = decimal.RequireFromString("5.00")
|
||||
|
||||
type TextArray pgtype.Array[string]
|
||||
|
||||
func (s *TextArray) Scan(src any) error {
|
||||
if src == nil {
|
||||
s.Elements = []string{}
|
||||
s.Dims = nil
|
||||
s.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
var strSrc string
|
||||
switch v := src.(type) {
|
||||
case string:
|
||||
strSrc = v
|
||||
case []byte:
|
||||
strSrc = string(v)
|
||||
default:
|
||||
return errors.New("failed to scan text array")
|
||||
}
|
||||
|
||||
trimmed := strings.Trim(strSrc, "{}")
|
||||
if len(trimmed) == 0 {
|
||||
s.Elements = []string{}
|
||||
s.Dims = nil
|
||||
s.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
s.Elements = strings.Split(trimmed, ",")
|
||||
s.Dims = nil
|
||||
s.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s TextArray) Value() (driver.Value, error) {
|
||||
if s.Elements == nil {
|
||||
return []string{}, nil
|
||||
}
|
||||
return s.Elements, nil
|
||||
}
|
||||
|
||||
// Shops holds the schema definition for the Shops entity.
|
||||
type Shops struct {
|
||||
ent.Schema
|
||||
@@ -56,7 +101,9 @@ func (Shops) Fields() []ent.Field {
|
||||
field.Bool("allow_multi_shop").Optional().Default(false),
|
||||
field.Bool("allow_independent_orders").Optional().Default(true),
|
||||
field.String("dispatch_mode").MaxLen(20).Default("manual"),
|
||||
field.Strings("announcements").Optional().Default([]string{}),
|
||||
field.Other("announcements", TextArray{}).
|
||||
SchemaType(map[string]string{dialect.Postgres: "text[]"}).
|
||||
Optional(),
|
||||
field.JSON("template_config", map[string]any{}).Optional(),
|
||||
field.Time("created_at").Default(time.Now).Immutable(),
|
||||
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
||||
|
||||
@@ -5,6 +5,7 @@ package models
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -44,7 +45,7 @@ type Shops struct {
|
||||
// DispatchMode holds the value of the "dispatch_mode" field.
|
||||
DispatchMode string `json:"dispatch_mode,omitempty"`
|
||||
// Announcements holds the value of the "announcements" field.
|
||||
Announcements []string `json:"announcements,omitempty"`
|
||||
Announcements schema.TextArray `json:"announcements,omitempty"`
|
||||
// TemplateConfig holds the value of the "template_config" field.
|
||||
TemplateConfig map[string]interface{} `json:"template_config,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
@@ -59,10 +60,12 @@ func (*Shops) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case shops.FieldAnnouncements, shops.FieldTemplateConfig:
|
||||
case shops.FieldTemplateConfig:
|
||||
values[i] = new([]byte)
|
||||
case shops.FieldRating, shops.FieldCommissionValue:
|
||||
values[i] = new(decimal.Decimal)
|
||||
case shops.FieldAnnouncements:
|
||||
values[i] = new(schema.TextArray)
|
||||
case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders:
|
||||
values[i] = new(sql.NullBool)
|
||||
case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount:
|
||||
@@ -167,12 +170,10 @@ func (_m *Shops) assignValues(columns []string, values []any) error {
|
||||
_m.DispatchMode = value.String
|
||||
}
|
||||
case shops.FieldAnnouncements:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
if value, ok := values[i].(*schema.TextArray); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field announcements", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Announcements); err != nil {
|
||||
return fmt.Errorf("unmarshal field announcements: %w", err)
|
||||
}
|
||||
} else if value != nil {
|
||||
_m.Announcements = *value
|
||||
}
|
||||
case shops.FieldTemplateConfig:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
|
||||
@@ -102,8 +102,6 @@ var (
|
||||
DefaultDispatchMode string
|
||||
// DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
|
||||
DispatchModeValidator func(string) error
|
||||
// DefaultAnnouncements holds the default value on creation for the "announcements" field.
|
||||
DefaultAnnouncements []string
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
@@ -180,6 +178,11 @@ func ByDispatchMode(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDispatchMode, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAnnouncements orders the results by the announcements field.
|
||||
func ByAnnouncements(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAnnouncements, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
|
||||
@@ -4,6 +4,7 @@ package shops
|
||||
|
||||
import (
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -115,6 +116,11 @@ func DispatchMode(v string) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
|
||||
}
|
||||
|
||||
// Announcements applies equality check predicate on the "announcements" field. It's identical to AnnouncementsEQ.
|
||||
func Announcements(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
|
||||
@@ -740,6 +746,46 @@ func DispatchModeContainsFold(v string) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v))
|
||||
}
|
||||
|
||||
// AnnouncementsEQ applies the EQ predicate on the "announcements" field.
|
||||
func AnnouncementsEQ(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldEQ(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsNEQ applies the NEQ predicate on the "announcements" field.
|
||||
func AnnouncementsNEQ(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldNEQ(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsIn applies the In predicate on the "announcements" field.
|
||||
func AnnouncementsIn(vs ...schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldIn(FieldAnnouncements, vs...))
|
||||
}
|
||||
|
||||
// AnnouncementsNotIn applies the NotIn predicate on the "announcements" field.
|
||||
func AnnouncementsNotIn(vs ...schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldNotIn(FieldAnnouncements, vs...))
|
||||
}
|
||||
|
||||
// AnnouncementsGT applies the GT predicate on the "announcements" field.
|
||||
func AnnouncementsGT(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldGT(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsGTE applies the GTE predicate on the "announcements" field.
|
||||
func AnnouncementsGTE(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldGTE(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsLT applies the LT predicate on the "announcements" field.
|
||||
func AnnouncementsLT(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldLT(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsLTE applies the LTE predicate on the "announcements" field.
|
||||
func AnnouncementsLTE(v schema.TextArray) predicate.Shops {
|
||||
return predicate.Shops(sql.FieldLTE(FieldAnnouncements, v))
|
||||
}
|
||||
|
||||
// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field.
|
||||
func AnnouncementsIsNil() predicate.Shops {
|
||||
return predicate.Shops(sql.FieldIsNull(FieldAnnouncements))
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"time"
|
||||
|
||||
@@ -166,11 +167,19 @@ func (_c *ShopsCreate) SetNillableDispatchMode(v *string) *ShopsCreate {
|
||||
}
|
||||
|
||||
// SetAnnouncements sets the "announcements" field.
|
||||
func (_c *ShopsCreate) SetAnnouncements(v []string) *ShopsCreate {
|
||||
func (_c *ShopsCreate) SetAnnouncements(v schema.TextArray) *ShopsCreate {
|
||||
_c.mutation.SetAnnouncements(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||
func (_c *ShopsCreate) SetNillableAnnouncements(v *schema.TextArray) *ShopsCreate {
|
||||
if v != nil {
|
||||
_c.SetAnnouncements(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTemplateConfig sets the "template_config" field.
|
||||
func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate {
|
||||
_c.mutation.SetTemplateConfig(v)
|
||||
@@ -274,10 +283,6 @@ func (_c *ShopsCreate) defaults() {
|
||||
v := shops.DefaultDispatchMode
|
||||
_c.mutation.SetDispatchMode(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Announcements(); !ok {
|
||||
v := shops.DefaultAnnouncements
|
||||
_c.mutation.SetAnnouncements(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := shops.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
@@ -407,7 +412,7 @@ func (_c *ShopsCreate) createSpec() (*Shops, *sqlgraph.CreateSpec) {
|
||||
_node.DispatchMode = value
|
||||
}
|
||||
if value, ok := _c.mutation.Announcements(); ok {
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||
_node.Announcements = value
|
||||
}
|
||||
if value, ok := _c.mutation.TemplateConfig(); ok {
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/shop/rpc/internal/models/schema"
|
||||
"juwan-backend/app/shop/rpc/internal/models/shops"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/dialect/sql/sqljson"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
@@ -262,14 +262,16 @@ func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate {
|
||||
}
|
||||
|
||||
// SetAnnouncements sets the "announcements" field.
|
||||
func (_u *ShopsUpdate) SetAnnouncements(v []string) *ShopsUpdate {
|
||||
func (_u *ShopsUpdate) SetAnnouncements(v schema.TextArray) *ShopsUpdate {
|
||||
_u.mutation.SetAnnouncements(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AppendAnnouncements appends value to the "announcements" field.
|
||||
func (_u *ShopsUpdate) AppendAnnouncements(v []string) *ShopsUpdate {
|
||||
_u.mutation.AppendAnnouncements(v)
|
||||
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||
func (_u *ShopsUpdate) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdate {
|
||||
if v != nil {
|
||||
_u.SetAnnouncements(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
@@ -437,15 +439,10 @@ func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Announcements(); ok {
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, shops.FieldAnnouncements, value)
|
||||
})
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.AnnouncementsCleared() {
|
||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
|
||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.TemplateConfig(); ok {
|
||||
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
||||
@@ -708,14 +705,16 @@ func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne {
|
||||
}
|
||||
|
||||
// SetAnnouncements sets the "announcements" field.
|
||||
func (_u *ShopsUpdateOne) SetAnnouncements(v []string) *ShopsUpdateOne {
|
||||
func (_u *ShopsUpdateOne) SetAnnouncements(v schema.TextArray) *ShopsUpdateOne {
|
||||
_u.mutation.SetAnnouncements(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AppendAnnouncements appends value to the "announcements" field.
|
||||
func (_u *ShopsUpdateOne) AppendAnnouncements(v []string) *ShopsUpdateOne {
|
||||
_u.mutation.AppendAnnouncements(v)
|
||||
// SetNillableAnnouncements sets the "announcements" field if the given value is not nil.
|
||||
func (_u *ShopsUpdateOne) SetNillableAnnouncements(v *schema.TextArray) *ShopsUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAnnouncements(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
@@ -913,15 +912,10 @@ func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error)
|
||||
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Announcements(); ok {
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, shops.FieldAnnouncements, value)
|
||||
})
|
||||
_spec.SetField(shops.FieldAnnouncements, field.TypeOther, value)
|
||||
}
|
||||
if _u.mutation.AnnouncementsCleared() {
|
||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
|
||||
_spec.ClearField(shops.FieldAnnouncements, field.TypeOther)
|
||||
}
|
||||
if value, ok := _u.mutation.TemplateConfig(); ok {
|
||||
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
stdsql "database/sql"
|
||||
"fmt"
|
||||
"juwan-backend/app/shop/rpc/internal/config"
|
||||
"juwan-backend/app/shop/rpc/internal/models"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
"juwan-backend/app/users/rpc/usercenter"
|
||||
"juwan-backend/common/redisx"
|
||||
"juwan-backend/common/snowflakex"
|
||||
"juwan-backend/pkg/adapter"
|
||||
@@ -12,27 +14,32 @@ import (
|
||||
"time"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Snowflake snowflake.SnowflakeServiceClient
|
||||
UsersRpc usercenter.Usercenter
|
||||
ShopModelRW *models.Client
|
||||
ShopModelRO *models.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
||||
rawRW, err := stdsql.Open("pgx", c.DB.Master)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ROConn, err := sql.Open("pgx", c.DB.Slaves)
|
||||
rawRO, err := stdsql.Open("pgx", c.DB.Slaves)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
RWConn := sql.OpenDB(dialect.Postgres, rawRW)
|
||||
ROConn := sql.OpenDB(dialect.Postgres, rawRO)
|
||||
|
||||
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||
if redisCluster == nil || err != nil {
|
||||
@@ -58,6 +65,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||
UsersRpc: usercenter.NewUsercenter(zrpc.MustNewClient(c.UsersRpcConf)),
|
||||
ShopModelRO: models.NewClient(roModelOpts...),
|
||||
ShopModelRW: models.NewClient(rwModelOpts...),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user