Refactor: Remove deprecated gRPC service files and implement new API structure

- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`.
- Added new API server implementations for objectstory, player, and shop services.
- Introduced configuration files for new APIs in `etc/*.yaml`.
- Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`.
- Removed unused user update handler and user API files.
- Added utility functions for context management and HTTP header parsing.
- Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
This commit is contained in:
wwweww
2026-02-28 18:35:56 +08:00
parent d2f33b4b96
commit 19cc7a778c
349 changed files with 42548 additions and 1453 deletions
@@ -4,24 +4,34 @@
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"
)
// 接受邀请
func AcceptInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.AcceptInvitationReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewAcceptInvitationLogic(r.Context(), svcCtx)
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)
resp, err := l.AcceptInvitation(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,12 +4,17 @@
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"
)
// 新增店铺公告
@@ -21,7 +26,12 @@ func AddAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewAddAnnouncementLogic(r.Context(), svcCtx)
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)
resp, err := l.AddAnnouncement(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,12 +4,17 @@
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"
)
// 创建店铺
@@ -21,7 +26,12 @@ func CreateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewCreateShopLogic(r.Context(), svcCtx)
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)
resp, err := l.CreateShop(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,24 +4,34 @@
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"
)
// 删除店铺公告
func DeleteAnnouncementHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.DeleteAnnouncementReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewDeleteAnnouncementLogic(r.Context(), svcCtx)
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)
resp, err := l.DeleteAnnouncement(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,12 +4,17 @@
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"
)
// 获取当前用户的店铺
@@ -21,7 +26,12 @@ func GetMyShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewGetMyShopLogic(r.Context(), svcCtx)
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)
resp, err := l.GetMyShop(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -6,16 +6,17 @@ 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"
)
// 获取店铺详情
func GetShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.ShopIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
@@ -4,24 +4,34 @@
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"
)
// 获取收入统计
func GetShopIncomeStatsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.AcceptInvitationReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewGetShopIncomeStatsLogic(r.Context(), svcCtx)
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)
resp, err := l.GetShopIncomeStats(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -6,16 +6,17 @@ 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"
)
// 获取店长的店铺
func GetUserShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.UserIdReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
@@ -4,12 +4,17 @@
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"
)
// 邀请打手
@@ -21,7 +26,12 @@ func InvitePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewInvitePlayerLogic(r.Context(), svcCtx)
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)
resp, err := l.InvitePlayer(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,24 +4,34 @@
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"
)
// 拒绝邀请
func RejectInvitationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.AcceptInvitationReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewRejectInvitationLogic(r.Context(), svcCtx)
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)
resp, err := l.RejectInvitation(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,24 +4,34 @@
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"
)
// 移除打手
func RemovePlayerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EmptyResp
var req types.InvitationReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := shop.NewRemovePlayerLogic(r.Context(), svcCtx)
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)
resp, err := l.RemovePlayer(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,12 +4,17 @@
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"
)
// 更新店铺信息
@@ -21,7 +26,12 @@ func UpdateShopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewUpdateShopLogic(r.Context(), svcCtx)
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)
resp, err := l.UpdateShop(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
@@ -4,12 +4,17 @@
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"
)
// 更新店铺模板
@@ -21,7 +26,12 @@ func UpdateShopTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := shop.NewUpdateShopTemplateLogic(r.Context(), svcCtx)
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)
resp, err := l.UpdateShopTemplate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)