fix: use snowflake for all order and state log ID generation
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"juwan-backend/app/order/rpc/internal/svc"
|
||||
"juwan-backend/app/order/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -31,8 +32,13 @@ func (l *AddOrderStateLogsLogic) AddOrderStateLogs(in *pb.AddOrderStateLogsReq)
|
||||
return nil, errors.New("order state log is required")
|
||||
}
|
||||
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
builder := l.svcCtx.OrderModelsRW.OrderStateLogs.Create().
|
||||
SetID(in.Id).
|
||||
SetID(idResp.Id).
|
||||
SetOrderID(in.OrderId).
|
||||
SetToStatus(in.ToStatus).
|
||||
SetAction(in.Action).
|
||||
|
||||
@@ -30,14 +30,11 @@ func NewAddOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddOrde
|
||||
|
||||
// -----------------------orders-----------------------
|
||||
func (l *AddOrdersLogic) AddOrders(in *pb.AddOrdersReq) (*pb.AddOrdersResp, error) {
|
||||
orderID := in.Id
|
||||
if orderID <= 0 {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderID = idResp.Id
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderID := idResp.Id
|
||||
|
||||
totalPrice, err := parseDecimal(in.GetTotalPrice())
|
||||
if err != nil || totalPrice.Cmp(decimal.Zero) <= 0 {
|
||||
@@ -101,5 +98,5 @@ func (l *AddOrdersLogic) AddOrders(in *pb.AddOrdersReq) (*pb.AddOrdersResp, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.AddOrdersResp{}, nil
|
||||
return &pb.AddOrdersResp{Id: orderID}, nil
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// goctl 1.10.1
|
||||
// Source: order.proto
|
||||
|
||||
package server
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// goctl 1.10.1
|
||||
// Source: order.proto
|
||||
|
||||
package orderservice
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v5.29.6
|
||||
// protoc v6.33.5
|
||||
// source: order.proto
|
||||
|
||||
package pb
|
||||
@@ -416,6 +416,7 @@ func (x *AddOrdersReq) GetUpdatedAt() int64 {
|
||||
|
||||
type AddOrdersResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -450,6 +451,13 @@ func (*AddOrdersResp) Descriptor() ([]byte, []int) {
|
||||
return file_order_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *AddOrdersResp) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type UpdateOrdersReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` //id
|
||||
@@ -1932,8 +1940,9 @@ const file_order_proto_rawDesc = "" +
|
||||
"\f_completedAtB\x0e\n" +
|
||||
"\f_cancelledAtB\f\n" +
|
||||
"\n" +
|
||||
"_updatedAt\"\x0f\n" +
|
||||
"\rAddOrdersResp\"\xd3\a\n" +
|
||||
"_updatedAt\"\x1f\n" +
|
||||
"\rAddOrdersResp\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\"\xd3\a\n" +
|
||||
"\x0fUpdateOrdersReq\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12#\n" +
|
||||
"\n" +
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v5.29.6
|
||||
// - protoc v6.33.5
|
||||
// source: order.proto
|
||||
|
||||
package pb
|
||||
|
||||
Reference in New Issue
Block a user