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:
@@ -0,0 +1,117 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/models/orders"
|
||||
"juwan-backend/app/order/rpc/internal/models/predicate"
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchOrdersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchOrdersLogic {
|
||||
return &SearchOrdersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchOrdersLogic) SearchOrders(in *pb.SearchOrdersReq) (*pb.SearchOrdersResp, error) {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
preds := make([]predicate.Orders, 0, 20)
|
||||
if in.Id != nil {
|
||||
preds = append(preds, orders.IDEQ(*in.Id))
|
||||
}
|
||||
if in.ConsumerId != nil {
|
||||
preds = append(preds, orders.ConsumerIDEQ(*in.ConsumerId))
|
||||
}
|
||||
if in.ConsumerName != nil && *in.ConsumerName != "" {
|
||||
preds = append(preds, orders.ConsumerNameContainsFold(*in.ConsumerName))
|
||||
}
|
||||
if in.PlayerId != nil {
|
||||
preds = append(preds, orders.PlayerIDEQ(*in.PlayerId))
|
||||
}
|
||||
if in.PlayerName != nil && *in.PlayerName != "" {
|
||||
preds = append(preds, orders.PlayerNameContainsFold(*in.PlayerName))
|
||||
}
|
||||
if in.ShopId != nil {
|
||||
preds = append(preds, orders.ShopIDEQ(*in.ShopId))
|
||||
}
|
||||
if in.ShopName != nil && *in.ShopName != "" {
|
||||
preds = append(preds, orders.ShopNameContainsFold(*in.ShopName))
|
||||
}
|
||||
if in.Status != nil && *in.Status != "" {
|
||||
preds = append(preds, orders.StatusEQ(*in.Status))
|
||||
}
|
||||
if in.TotalPrice != nil && *in.TotalPrice != "" {
|
||||
price, err := parseDecimal(*in.TotalPrice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
preds = append(preds, orders.TotalPriceEQ(price))
|
||||
}
|
||||
if in.Note != nil && *in.Note != "" {
|
||||
preds = append(preds, orders.NoteContainsFold(*in.Note))
|
||||
}
|
||||
if in.Version != nil {
|
||||
preds = append(preds, orders.VersionEQ(int(*in.Version)))
|
||||
}
|
||||
if in.TimeoutJobId != nil && *in.TimeoutJobId != "" {
|
||||
preds = append(preds, orders.TimeoutJobIDEQ(*in.TimeoutJobId))
|
||||
}
|
||||
if in.SearchText != nil && *in.SearchText != "" {
|
||||
preds = append(preds, orders.SearchTextContainsFold(*in.SearchText))
|
||||
}
|
||||
if in.CreatedAt != nil && *in.CreatedAt > 0 {
|
||||
preds = append(preds, orders.CreatedAtGTE(time.Unix(*in.CreatedAt, 0)))
|
||||
}
|
||||
if in.AcceptedAt != nil && *in.AcceptedAt > 0 {
|
||||
preds = append(preds, orders.AcceptedAtGTE(time.Unix(*in.AcceptedAt, 0)))
|
||||
}
|
||||
if in.ClosedAt != nil && *in.ClosedAt > 0 {
|
||||
preds = append(preds, orders.ClosedAtGTE(time.Unix(*in.ClosedAt, 0)))
|
||||
}
|
||||
if in.CompletedAt != nil && *in.CompletedAt > 0 {
|
||||
preds = append(preds, orders.CompletedAtGTE(time.Unix(*in.CompletedAt, 0)))
|
||||
}
|
||||
if in.CancelledAt != nil && *in.CancelledAt > 0 {
|
||||
preds = append(preds, orders.CancelledAtGTE(time.Unix(*in.CancelledAt, 0)))
|
||||
}
|
||||
if in.UpdatedAt != nil && *in.UpdatedAt > 0 {
|
||||
preds = append(preds, orders.UpdatedAtGTE(time.Unix(*in.UpdatedAt, 0)))
|
||||
}
|
||||
|
||||
query := l.svcCtx.OrderModelsRO.Orders.Query()
|
||||
if len(preds) > 0 {
|
||||
query = query.Where(orders.And(preds...))
|
||||
}
|
||||
|
||||
items, err := query.Offset(int(in.Page * in.Limit)).Limit(int(in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]*pb.Orders, 0, len(items))
|
||||
for _, item := range items {
|
||||
result = append(result, toPBOrder(item))
|
||||
}
|
||||
|
||||
return &pb.SearchOrdersResp{Orders: result}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user