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
@@ -0,0 +1,114 @@
package order
import (
"context"
"encoding/json"
"strconv"
"time"
"juwan-backend/app/order/api/internal/svc"
"juwan-backend/app/order/api/internal/types"
"juwan-backend/app/order/rpc/orderservice"
"juwan-backend/common/utils/contextj"
)
func int64Ptr(v int64) *int64 {
return &v
}
func stringPtr(v string) *string {
return &v
}
func formatUnix(ts int64) string {
if ts <= 0 {
return ""
}
return time.Unix(ts, 0).UTC().Format(time.RFC3339)
}
func toAPIOrder(in *orderservice.Orders) types.Order {
order := types.Order{}
if in == nil {
return order
}
totalPrice, _ := strconv.ParseFloat(in.GetTotalPrice(), 64)
playerID := strconv.FormatInt(in.GetPlayerId(), 10)
service := types.PlayerService{}
_ = json.Unmarshal([]byte(in.GetServiceSnapshot()), &service)
order = types.Order{
Id: in.GetId(),
ConsumerId: in.GetConsumerId(),
ConsumerName: in.GetConsumerName(),
PlayerId: playerID,
PlayerName: in.GetPlayerName(),
ShopId: in.GetShopId(),
ShopName: in.GetShopName(),
Service: service,
Status: in.GetStatus(),
TotalPrice: totalPrice,
Note: in.GetNote(),
CreatedAt: formatUnix(in.GetCreatedAt()),
AcceptedAt: formatUnix(in.GetAcceptedAt()),
CompletedAt: formatUnix(in.GetCompletedAt()),
}
return order
}
func transitionOrderStatus(ctx context.Context, svcCtx *svc.ServiceContext, orderID int64, toStatus string, setAcceptedAt bool, setClosedAt bool, setCompletedAt bool, setCancelledAt bool) error {
current, err := svcCtx.OrderRpc.GetOrdersById(ctx, &orderservice.GetOrdersByIdReq{Id: orderID})
if err != nil {
return err
}
if current.GetOrders() == nil {
return nil
}
now := time.Now().Unix()
updateReq := &orderservice.UpdateOrdersReq{
Id: orderID,
Status: stringPtr(toStatus),
UpdatedAt: int64Ptr(now),
}
if setAcceptedAt {
updateReq.AcceptedAt = int64Ptr(now)
}
if setClosedAt {
updateReq.ClosedAt = int64Ptr(now)
}
if setCompletedAt {
updateReq.CompletedAt = int64Ptr(now)
}
if setCancelledAt {
updateReq.CancelledAt = int64Ptr(now)
}
if _, err = svcCtx.OrderRpc.UpdateOrders(ctx, updateReq); err != nil {
return err
}
fromStatus := current.Orders.GetStatus()
actorID, _ := contextj.UserIDFrom(ctx)
actorRole := "system"
if actorID > 0 {
actorRole = "user"
}
_, err = svcCtx.OrderRpc.AddOrderStateLogs(ctx, &orderservice.AddOrderStateLogsReq{
Id: time.Now().UnixNano(),
OrderId: orderID,
FromStatus: &fromStatus,
ToStatus: toStatus,
Action: "status_transition",
ActorId: actorID,
ActorRole: actorRole,
CreatedAt: &now,
})
if err != nil {
return err
}
return nil
}