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
@@ -3,9 +3,6 @@ package logic
import (
"context"
"errors"
"juwan-backend/app/game/rpc/internal/models/games"
"juwan-backend/app/game/rpc/internal/models/predicate"
"juwan-backend/app/game/rpc/internal/svc"
"juwan-backend/app/game/rpc/pb"
@@ -28,79 +25,26 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
}
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
if in.Limit > 1000 {
return nil, errors.New("limit too large")
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
return nil, errors.New("invalid pagination parameters")
}
preds := make([]predicate.Games, 0, 8)
if in.IdOpt != nil {
preds = append(preds, games.IDEQ(*in.IdOpt))
} else if in.Id != 0 {
preds = append(preds, games.IDEQ(in.Id))
}
if in.NameOpt != nil {
if *in.NameOpt != "" {
preds = append(preds, games.NameContainsFold(*in.NameOpt))
}
} else if in.Name != "" {
preds = append(preds, games.NameContainsFold(in.Name))
}
if in.IconOpt != nil {
if *in.IconOpt != "" {
preds = append(preds, games.IconContainsFold(*in.IconOpt))
}
} else if in.Icon != "" {
preds = append(preds, games.IconContainsFold(in.Icon))
}
if in.CategoryOpt != nil {
if *in.CategoryOpt != "" {
preds = append(preds, games.CategoryContainsFold(*in.CategoryOpt))
}
} else if in.Category != "" {
preds = append(preds, games.CategoryContainsFold(in.Category))
}
if in.SortOrderOpt != nil {
preds = append(preds, games.SortOrderEQ(int(*in.SortOrderOpt)))
} else if in.SortOrder != 0 {
preds = append(preds, games.SortOrderEQ(int(in.SortOrder)))
}
if in.IsActiveOpt != nil {
preds = append(preds, games.IsActiveEQ(*in.IsActiveOpt))
} else if in.IsActive {
preds = append(preds, games.IsActiveEQ(true))
}
query := l.svcCtx.GameModelRO.Games.Query()
if len(preds) > 0 {
if in.MatchMode == pb.MatchMode_MATCH_MODE_AND {
query = query.Where(games.And(preds...))
} else {
query = query.Where(games.Or(preds...))
}
}
all, err := query.
Offset(int(in.Page * in.Limit)).
Limit(int(in.Limit)).
All(l.ctx)
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
if err != nil {
logx.Errorf("search games failed, %s", err.Error())
return nil, errors.New("search games failed")
logx.Errorf("failed to query games: %v", err)
return nil, errors.New("failed to query games")
}
list := make([]*pb.Games, 0, len(all))
for _, v := range all {
temp := &pb.Games{}
err = copier.Copy(temp, &v)
err := copier.Copy(temp, v)
if err != nil {
logx.Errorf("search games failed, %s", err.Error())
continue
logx.Errorf("failed to copy games: %v", err)
return nil, errors.New("failed to copy games")
}
temp.CreatedAt = v.CreatedAt.Unix()
temp.UpdatedAt = v.UpdatedAt.Unix()
list = append(list, temp)
}
return &pb.SearchGamesResp{
Games: list,
}, nil
@@ -2,9 +2,6 @@ package logic
import (
"context"
"errors"
"time"
"juwan-backend/app/game/rpc/internal/svc"
"juwan-backend/app/game/rpc/pb"
@@ -26,60 +23,6 @@ func NewUpdateGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Updat
}
func (l *UpdateGamesLogic) UpdateGames(in *pb.UpdateGamesReq) (*pb.UpdateGamesResp, error) {
update := l.svcCtx.GameModelRW.Games.UpdateOneID(in.Id)
updated := false
if in.NameOpt != nil {
update.SetNillableName(in.NameOpt)
updated = true
} else if in.Name != "" {
update.SetName(in.Name)
updated = true
}
if in.IconOpt != nil {
update.SetNillableIcon(in.IconOpt)
updated = true
} else if in.Icon != "" {
update.SetIcon(in.Icon)
updated = true
}
if in.CategoryOpt != nil {
update.SetNillableCategory(in.CategoryOpt)
updated = true
} else if in.Category != "" {
update.SetCategory(in.Category)
updated = true
}
if in.SortOrderOpt != nil {
sortOrder := int(*in.SortOrderOpt)
update.SetNillableSortOrder(&sortOrder)
updated = true
} else if in.SortOrder != 0 {
sortOrder := int(in.SortOrder)
update.SetSortOrder(sortOrder)
updated = true
}
if in.IsActiveOpt != nil {
update.SetNillableIsActive(in.IsActiveOpt)
updated = true
} else if in.IsActive {
update.SetIsActive(true)
updated = true
}
if !updated {
return nil, errors.New("no fields to update")
}
update.SetUpdatedAt(time.Now())
if err := update.Exec(l.ctx); err != nil {
logx.WithContext(l.ctx).Errorf("UpdateGamesLogic err: %v", err)
return nil, errors.New("update games failed")
}
return &pb.UpdateGamesResp{}, nil
}