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:
@@ -4,27 +4,29 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"juwan-backend/common/utils/responses"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"juwan-backend/app/game/api/internal/logic/game"
|
||||
"juwan-backend/app/game/api/internal/svc"
|
||||
"juwan-backend/app/game/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取游戏详情
|
||||
func GetGameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.EmptyResp
|
||||
var req types.GetGameReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := game.NewGetGameLogic(r.Context(), svcCtx)
|
||||
resp := l.GetGame(&req)
|
||||
resp, err := l.GetGame(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.ErrorCtx(r.Context(), w, responses.NewErrorResp(400, err))
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
||||
@@ -27,16 +27,16 @@ func NewGetGameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGameLo
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game) {
|
||||
func (l *GetGameLogic) GetGame(req *types.GetGameReq) (resp *types.Game, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
game, err := l.svcCtx.GameRpc.GetGamesById(l.ctx, &pb.GetGamesByIdReq{Id: req.Id})
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return &types.Game{
|
||||
Id: game.Games.Id,
|
||||
Name: game.Games.Name,
|
||||
Icon: game.Games.Icon,
|
||||
Category: game.Games.Category,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package game
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/game/rpc/pb"
|
||||
|
||||
"juwan-backend/app/game/api/internal/svc"
|
||||
"juwan-backend/app/game/api/internal/types"
|
||||
@@ -29,6 +30,30 @@ func NewListGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGam
|
||||
|
||||
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
all, err := l.svcCtx.GameRpc.SearchGames(l.ctx, &pb.SearchGamesReq{
|
||||
Page: req.Offset,
|
||||
Limit: req.Limit,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]types.Game, 0, len(all.Games))
|
||||
for _, v := range all.Games {
|
||||
list = append(list, types.Game{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Icon: v.Icon,
|
||||
Category: v.Category,
|
||||
})
|
||||
}
|
||||
return &types.GameListResp{
|
||||
Items: list,
|
||||
Meta: types.PageMeta{
|
||||
Total: 0,
|
||||
Offset: req.Offset + 1,
|
||||
Limit: 20,
|
||||
},
|
||||
}, nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ package svc
|
||||
|
||||
import (
|
||||
"juwan-backend/app/game/api/internal/config"
|
||||
"juwan-backend/app/game/rpc/gamepublic"
|
||||
"juwan-backend/app/game/rpc/gameservice"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
GameRpc gamepublic.GamePublic
|
||||
GameRpc gameservice.GameService
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
GameRpc: gamepublic.NewGamePublic(zrpc.MustNewClient(c.GameRpcConf)),
|
||||
GameRpc: gameservice.NewGameService(zrpc.MustNewClient(c.GameRpcConf)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user