diff --git a/CHANGELOG.md b/CHANGELOG.md index 400a1103..313f968f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,36 @@ +## [1.13.0-beta.1](https://github.com/LerianStudio/midaz/compare/v1.12.0...v1.13.0-beta.1) (2024-10-02) + + +### Features + +* create grpc account in adapter :sparkles: ([78dbddb](https://github.com/LerianStudio/midaz/commit/78dbddb255c0dd73c74e32c4a049d59af88f6a04)) +* create operation postgres crud to use with transaction ([0b541a4](https://github.com/LerianStudio/midaz/commit/0b541a48086bc8336085bee3e71606bd1b55d13f)) +* create transaction constant :sparkles: ([4f5a03b](https://github.com/LerianStudio/midaz/commit/4f5a03b920961e33a76d96ead2c05500f97020f8)) +* implements transaction api using grcp to get account on ledger :sparkles: ([7b19915](https://github.com/LerianStudio/midaz/commit/7b199150850a41d5a1bb80b725d7bc8db296e10a)) + + +### Bug Fixes + +* account proto class updated with all fields. :bug: ([0f00bb7](https://github.com/LerianStudio/midaz/commit/0f00bb79be7fb9ec20723c4f56cd607e6ef144ad)) +* add lib :bug: ([55f0aa0](https://github.com/LerianStudio/midaz/commit/55f0aa0fea1b40cce38da9d35e296e66daf15d5c)) +* adjust account proto in common to improve requests and responses on ledger :bug: ([844d994](https://github.com/LerianStudio/midaz/commit/844d9949171b04860fc14eef888a0d2732c63bb2)) +* adjust to slice to use append instead use index. :bug: ([990c426](https://github.com/LerianStudio/midaz/commit/990c426f87a485790c6c586aadd35b5ac71bf32f)) +* create transaction on postgresql :bug: ([688a16c](https://github.com/LerianStudio/midaz/commit/688a16cc5eb56b99b071b1f21e6e43c6f8758b01)) +* insert grpc address and port in environment :bug: ([7813ae3](https://github.com/LerianStudio/midaz/commit/7813ae3dc6df15e7cf5a56c344676e76e930297b)) +* insert ledger grpc address and port into transaction .env :bug: ([4be3771](https://github.com/LerianStudio/midaz/commit/4be377158d02369b317f478ccf333ea043bd4573)) +* make sec, format, tidy and lint :bug: ([11b9d97](https://github.com/LerianStudio/midaz/commit/11b9d973c405f839a9fc64bcbe1e5a6828345260)) +* mongdb connection and wire to save metadata of transaction :bug: ([05f19a5](https://github.com/LerianStudio/midaz/commit/05f19a55ae0b4b241101a865fc464eff203fc5b6)) +* remove account http api reference :bug: ([8189389](https://github.com/LerianStudio/midaz/commit/8189389fe7d39dd3dd182c79923a4d1e593dd944)) +* remove defer because command always be executed before the connection is even used. :bug: ([a5e4d36](https://github.com/LerianStudio/midaz/commit/a5e4d3612123a24ddcb3eec0741116e48f294a1f)) +* remove exemples of dsl gold :bug: ([1daa033](https://github.com/LerianStudio/midaz/commit/1daa03307fbb105d95fdad20cecc37d092bf9838)) +* rename .env.exemple to .env.example and update go.sum :bug: ([b6a2a2d](https://github.com/LerianStudio/midaz/commit/b6a2a2dd8fba36b808fd4efc09cdcc3b53d5e708)) +* some operation adjust :bug: ([0ab9fa3](https://github.com/LerianStudio/midaz/commit/0ab9fa3b0248e0a0c9a6d1f25b5e5dcfd0bd1d65)) +* update convert uint64 make sec alert :bug: ([3779924](https://github.com/LerianStudio/midaz/commit/3779924a809686cb28f9013aa71f6b6611f063e6)) +* update docker compose ledger and transaction to add bridge to use grpc call account :bug: ([4115eb1](https://github.com/LerianStudio/midaz/commit/4115eb1e3522751b875c9bab5ad679d8d8912332)) +* update grpc accounts proto reference on transaction and some adjusts to improve readable :bug: ([9930082](https://github.com/LerianStudio/midaz/commit/99300826c63355d9bb8b419d0ff1931fcc63e83a)) +* update grpc accounts proto reference on transaction and some adjusts to improve readable pt. 2 :bug: ([11e5c71](https://github.com/LerianStudio/midaz/commit/11e5c71576980b9059444a9708abcf430ede85bd)) +* update inject and wire :bug: ([8026c16](https://github.com/LerianStudio/midaz/commit/8026c1653921062738a9a6f3f64ca9907c811daf)) + ## [1.12.0](https://github.com/LerianStudio/midaz/compare/v1.11.0...v1.12.0) (2024-09-27) diff --git a/common/constant/transaction.go b/common/constant/transaction.go new file mode 100644 index 00000000..969afa82 --- /dev/null +++ b/common/constant/transaction.go @@ -0,0 +1,10 @@ +package constant + +const ( + CREATED = "CREATED" + APPROVED = "APPROVED" + PREAPPROVED = "PRE_APPROVED" + SENT = "SENT" + CANCELED = "CANCELED" + DECLINED = "DECLINED" +) diff --git a/common/gold/transaction/model/transaction.go b/common/gold/transaction/model/transaction.go index 35ec2df2..2fcf2569 100644 --- a/common/gold/transaction/model/transaction.go +++ b/common/gold/transaction/model/transaction.go @@ -31,12 +31,12 @@ type Source struct { } type FromTo struct { - Account string `json:"account,omitempty"` - Amount *Amount `json:"amount,omitempty"` - Share *Share `json:"share,omitempty"` - Remaining string `json:"remaining,omitempty"` - Description string `json:"description,omitempty"` - Metadata []Metadata `json:"metadata,omitempty"` + Account string `json:"account,omitempty"` + Amount *Amount `json:"amount,omitempty"` + Share *Share `json:"share,omitempty"` + Remaining string `json:"remaining,omitempty"` + Description string `json:"description,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` } type Distribute struct { @@ -46,11 +46,11 @@ type Distribute struct { } type Transaction struct { - ChartOfAccountsGroupName string `json:"chartOfAccountsGroupName"` - Description string `json:"description,omitempty"` - Code string `json:"code,omitempty"` - Pending bool `json:"pending,omitempty"` - Metadata []Metadata `json:"metadata,omitempty"` - Send Send `json:"send,omitempty"` - Distribute Distribute `json:"distribute,omitempty"` + ChartOfAccountsGroupName string `json:"chartOfAccountsGroupName"` + Description string `json:"description,omitempty"` + Code string `json:"code,omitempty"` + Pending bool `json:"pending,omitempty"` + Metadata map[string]any `json:"metadata,omitempty"` + Send Send `json:"send,omitempty"` + Distribute Distribute `json:"distribute,omitempty"` } diff --git a/common/gold/transaction/parse.go b/common/gold/transaction/parse.go index db2c40e8..de959d0d 100644 --- a/common/gold/transaction/parse.go +++ b/common/gold/transaction/parse.go @@ -35,9 +35,9 @@ func (v *TransactionVisitor) VisitTransaction(ctx *parser.TransactionContext) an pending = v.VisitPending(ctx.Pending().(*parser.PendingContext)).(bool) } - var metadata []model.Metadata + var metadata map[string]any if ctx.Metadata() != nil { - metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).([]model.Metadata) + metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).(map[string]any) } send := v.VisitSend(ctx.Send().(*parser.SendContext)).(model.Send) @@ -86,14 +86,14 @@ func (v *TransactionVisitor) VisitVisitChartOfAccounts(ctx *parser.ChartOfAccoun } func (v *TransactionVisitor) VisitMetadata(ctx *parser.MetadataContext) any { - metas := make([]model.Metadata, 0, len(ctx.AllPair())) + metadata := make(map[string]any, len(ctx.AllPair())) for _, pair := range ctx.AllPair() { - meta := v.VisitPair(pair.(*parser.PairContext)).(model.Metadata) - metas = append(metas, meta) + m := v.VisitPair(pair.(*parser.PairContext)).(model.Metadata) + metadata[m.Key] = m.Value } - return metas + return metadata } func (v *TransactionVisitor) VisitPair(ctx *parser.PairContext) any { @@ -220,9 +220,9 @@ func (v *TransactionVisitor) VisitFrom(ctx *parser.FromContext) any { description = v.VisitDescription(ctx.Description().(*parser.DescriptionContext)).(string) } - var metadata []model.Metadata + var metadata map[string]any if ctx.Metadata() != nil { - metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).([]model.Metadata) + metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).(map[string]any) } var amount model.Amount @@ -262,9 +262,9 @@ func (v *TransactionVisitor) VisitTo(ctx *parser.ToContext) any { description = v.VisitDescription(ctx.Description().(*parser.DescriptionContext)).(string) } - var metadata []model.Metadata + var metadata map[string]any if ctx.Metadata() != nil { - metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).([]model.Metadata) + metadata = v.VisitMetadata(ctx.Metadata().(*parser.MetadataContext)).(map[string]any) } var amount model.Amount diff --git a/common/mgrpc/account/account.pb.go b/common/mgrpc/account/account.pb.go new file mode 100644 index 00000000..0117074a --- /dev/null +++ b/common/mgrpc/account/account.pb.go @@ -0,0 +1,826 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.27.0 +// source: common/mgrpc/account/account.proto + +package account + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Balance struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Available float64 `protobuf:"fixed64,1,opt,name=available,proto3" json:"available,omitempty"` + OnHold float64 `protobuf:"fixed64,2,opt,name=on_hold,json=onHold,proto3" json:"on_hold,omitempty"` + Scale float64 `protobuf:"fixed64,3,opt,name=scale,proto3" json:"scale,omitempty"` +} + +func (x *Balance) Reset() { + *x = Balance{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Balance) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Balance) ProtoMessage() {} + +func (x *Balance) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Balance.ProtoReflect.Descriptor instead. +func (*Balance) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{0} +} + +func (x *Balance) GetAvailable() float64 { + if x != nil { + return x.Available + } + return 0 +} + +func (x *Balance) GetOnHold() float64 { + if x != nil { + return x.OnHold + } + return 0 +} + +func (x *Balance) GetScale() float64 { + if x != nil { + return x.Scale + } + return 0 +} + +type Metadata struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value map[string]string `protobuf:"bytes,1,rep,name=value,proto3" json:"value,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *Metadata) Reset() { + *x = Metadata{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Metadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Metadata) ProtoMessage() {} + +func (x *Metadata) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Metadata.ProtoReflect.Descriptor instead. +func (*Metadata) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{1} +} + +func (x *Metadata) GetValue() map[string]string { + if x != nil { + return x.Value + } + return nil +} + +type Status struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + AllowSending bool `protobuf:"varint,3,opt,name=allow_sending,json=allowSending,proto3" json:"allow_sending,omitempty"` + AllowReceiving bool `protobuf:"varint,4,opt,name=allow_receiving,json=allowReceiving,proto3" json:"allow_receiving,omitempty"` +} + +func (x *Status) Reset() { + *x = Status{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Status) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Status) ProtoMessage() {} + +func (x *Status) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Status.ProtoReflect.Descriptor instead. +func (*Status) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{2} +} + +func (x *Status) GetCode() string { + if x != nil { + return x.Code + } + return "" +} + +func (x *Status) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Status) GetAllowSending() bool { + if x != nil { + return x.AllowSending + } + return false +} + +func (x *Status) GetAllowReceiving() bool { + if x != nil { + return x.AllowReceiving + } + return false +} + +type Account struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + ParentAccountId string `protobuf:"bytes,3,opt,name=parent_account_id,json=parentAccountId,proto3" json:"parent_account_id,omitempty"` + EntityId string `protobuf:"bytes,4,opt,name=entity_id,json=entityId,proto3" json:"entity_id,omitempty"` + AssetCode string `protobuf:"bytes,5,opt,name=asset_code,json=assetCode,proto3" json:"asset_code,omitempty"` + OrganizationId string `protobuf:"bytes,6,opt,name=organization_id,json=organizationId,proto3" json:"organization_id,omitempty"` + LedgerId string `protobuf:"bytes,7,opt,name=ledger_id,json=ledgerId,proto3" json:"ledger_id,omitempty"` + PortfolioId string `protobuf:"bytes,8,opt,name=portfolio_id,json=portfolioId,proto3" json:"portfolio_id,omitempty"` + ProductId string `protobuf:"bytes,9,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Balance *Balance `protobuf:"bytes,10,opt,name=balance,proto3" json:"balance,omitempty"` + Status *Status `protobuf:"bytes,11,opt,name=status,proto3" json:"status,omitempty"` + Alias string `protobuf:"bytes,12,opt,name=alias,proto3" json:"alias,omitempty"` + Type string `protobuf:"bytes,13,opt,name=type,proto3" json:"type,omitempty"` + CreatedAt string `protobuf:"bytes,14,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt string `protobuf:"bytes,15,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` + DeletedAt string `protobuf:"bytes,16,opt,name=deleted_at,json=deletedAt,proto3" json:"deleted_at,omitempty"` + Metadata *Metadata `protobuf:"bytes,17,opt,name=metadata,proto3" json:"metadata,omitempty"` +} + +func (x *Account) Reset() { + *x = Account{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Account) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Account) ProtoMessage() {} + +func (x *Account) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Account.ProtoReflect.Descriptor instead. +func (*Account) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{3} +} + +func (x *Account) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Account) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Account) GetParentAccountId() string { + if x != nil { + return x.ParentAccountId + } + return "" +} + +func (x *Account) GetEntityId() string { + if x != nil { + return x.EntityId + } + return "" +} + +func (x *Account) GetAssetCode() string { + if x != nil { + return x.AssetCode + } + return "" +} + +func (x *Account) GetOrganizationId() string { + if x != nil { + return x.OrganizationId + } + return "" +} + +func (x *Account) GetLedgerId() string { + if x != nil { + return x.LedgerId + } + return "" +} + +func (x *Account) GetPortfolioId() string { + if x != nil { + return x.PortfolioId + } + return "" +} + +func (x *Account) GetProductId() string { + if x != nil { + return x.ProductId + } + return "" +} + +func (x *Account) GetBalance() *Balance { + if x != nil { + return x.Balance + } + return nil +} + +func (x *Account) GetStatus() *Status { + if x != nil { + return x.Status + } + return nil +} + +func (x *Account) GetAlias() string { + if x != nil { + return x.Alias + } + return "" +} + +func (x *Account) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *Account) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +func (x *Account) GetUpdatedAt() string { + if x != nil { + return x.UpdatedAt + } + return "" +} + +func (x *Account) GetDeletedAt() string { + if x != nil { + return x.DeletedAt + } + return "" +} + +func (x *Account) GetMetadata() *Metadata { + if x != nil { + return x.Metadata + } + return nil +} + +type AccountsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` +} + +func (x *AccountsResponse) Reset() { + *x = AccountsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AccountsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccountsResponse) ProtoMessage() {} + +func (x *AccountsResponse) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccountsResponse.ProtoReflect.Descriptor instead. +func (*AccountsResponse) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{4} +} + +func (x *AccountsResponse) GetAccounts() []*Account { + if x != nil { + return x.Accounts + } + return nil +} + +type AccountsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` +} + +func (x *AccountsRequest) Reset() { + *x = AccountsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AccountsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccountsRequest) ProtoMessage() {} + +func (x *AccountsRequest) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccountsRequest.ProtoReflect.Descriptor instead. +func (*AccountsRequest) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{5} +} + +func (x *AccountsRequest) GetAccounts() []*Account { + if x != nil { + return x.Accounts + } + return nil +} + +type AccountsID struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ids []string `protobuf:"bytes,1,rep,name=ids,proto3" json:"ids,omitempty"` +} + +func (x *AccountsID) Reset() { + *x = AccountsID{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AccountsID) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccountsID) ProtoMessage() {} + +func (x *AccountsID) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccountsID.ProtoReflect.Descriptor instead. +func (*AccountsID) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{6} +} + +func (x *AccountsID) GetIds() []string { + if x != nil { + return x.Ids + } + return nil +} + +type AccountsAlias struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Aliases []string `protobuf:"bytes,1,rep,name=aliases,proto3" json:"aliases,omitempty"` +} + +func (x *AccountsAlias) Reset() { + *x = AccountsAlias{} + if protoimpl.UnsafeEnabled { + mi := &file_common_mgrpc_account_account_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AccountsAlias) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccountsAlias) ProtoMessage() {} + +func (x *AccountsAlias) ProtoReflect() protoreflect.Message { + mi := &file_common_mgrpc_account_account_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccountsAlias.ProtoReflect.Descriptor instead. +func (*AccountsAlias) Descriptor() ([]byte, []int) { + return file_common_mgrpc_account_account_proto_rawDescGZIP(), []int{7} +} + +func (x *AccountsAlias) GetAliases() []string { + if x != nil { + return x.Aliases + } + return nil +} + +var File_common_mgrpc_account_account_proto protoreflect.FileDescriptor + +var file_common_mgrpc_account_account_proto_rawDesc = []byte{ + 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x56, 0x0a, + 0x07, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x61, 0x76, 0x61, 0x69, + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x09, 0x61, 0x76, 0x61, + 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x6f, 0x6e, 0x5f, 0x68, 0x6f, 0x6c, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x6f, 0x6e, 0x48, 0x6f, 0x6c, 0x64, 0x12, + 0x14, 0x0a, 0x05, 0x73, 0x63, 0x61, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, + 0x73, 0x63, 0x61, 0x6c, 0x65, 0x22, 0x78, 0x0a, 0x08, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0x12, 0x32, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x1c, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, + 0x61, 0x74, 0x61, 0x2e, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x1a, 0x38, 0x0a, 0x0a, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, + 0x8c, 0x01, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x73, 0x65, 0x6e, 0x64, 0x69, 0x6e, + 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x65, + 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x27, 0x0a, 0x0f, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x72, + 0x65, 0x63, 0x65, 0x69, 0x76, 0x69, 0x6e, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, + 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x69, 0x6e, 0x67, 0x22, 0xa8, + 0x04, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2a, + 0x0a, 0x11, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x61, 0x72, 0x65, 0x6e, + 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x73, 0x73, 0x65, 0x74, + 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x73, 0x73, + 0x65, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, + 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0e, 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, + 0x1b, 0x0a, 0x09, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, + 0x70, 0x6f, 0x72, 0x74, 0x66, 0x6f, 0x6c, 0x69, 0x6f, 0x5f, 0x69, 0x64, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x72, 0x74, 0x66, 0x6f, 0x6c, 0x69, 0x6f, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x2a, + 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x10, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x61, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x0c, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, + 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x64, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x2d, 0x0a, 0x08, 0x6d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, + 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x40, 0x0a, 0x10, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, + 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x10, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x3f, 0x0a, 0x0f, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, + 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, + 0x6e, 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x1e, 0x0a, 0x0a, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x49, 0x44, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x29, 0x0a, 0x0d, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x18, 0x0a, + 0x07, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, + 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x32, 0xea, 0x01, 0x0a, 0x0c, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x44, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x79, 0x49, 0x64, 0x73, 0x12, 0x13, 0x2e, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x49, + 0x44, 0x1a, 0x19, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4b, + 0x0a, 0x14, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x42, 0x79, 0x41, + 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x12, 0x16, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x1a, 0x19, + 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x47, 0x0a, 0x0e, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x18, 0x2e, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_common_mgrpc_account_account_proto_rawDescOnce sync.Once + file_common_mgrpc_account_account_proto_rawDescData = file_common_mgrpc_account_account_proto_rawDesc +) + +func file_common_mgrpc_account_account_proto_rawDescGZIP() []byte { + file_common_mgrpc_account_account_proto_rawDescOnce.Do(func() { + file_common_mgrpc_account_account_proto_rawDescData = protoimpl.X.CompressGZIP(file_common_mgrpc_account_account_proto_rawDescData) + }) + return file_common_mgrpc_account_account_proto_rawDescData +} + +var file_common_mgrpc_account_account_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_common_mgrpc_account_account_proto_goTypes = []any{ + (*Balance)(nil), // 0: account.Balance + (*Metadata)(nil), // 1: account.Metadata + (*Status)(nil), // 2: account.Status + (*Account)(nil), // 3: account.Account + (*AccountsResponse)(nil), // 4: account.AccountsResponse + (*AccountsRequest)(nil), // 5: account.AccountsRequest + (*AccountsID)(nil), // 6: account.AccountsID + (*AccountsAlias)(nil), // 7: account.AccountsAlias + nil, // 8: account.Metadata.ValueEntry +} +var file_common_mgrpc_account_account_proto_depIdxs = []int32{ + 8, // 0: account.Metadata.value:type_name -> account.Metadata.ValueEntry + 0, // 1: account.Account.balance:type_name -> account.Balance + 2, // 2: account.Account.status:type_name -> account.Status + 1, // 3: account.Account.metadata:type_name -> account.Metadata + 3, // 4: account.AccountsResponse.accounts:type_name -> account.Account + 3, // 5: account.AccountsRequest.accounts:type_name -> account.Account + 6, // 6: account.AccountProto.GetAccountsByIds:input_type -> account.AccountsID + 7, // 7: account.AccountProto.GetAccountsByAliases:input_type -> account.AccountsAlias + 5, // 8: account.AccountProto.UpdateAccounts:input_type -> account.AccountsRequest + 4, // 9: account.AccountProto.GetAccountsByIds:output_type -> account.AccountsResponse + 4, // 10: account.AccountProto.GetAccountsByAliases:output_type -> account.AccountsResponse + 4, // 11: account.AccountProto.UpdateAccounts:output_type -> account.AccountsResponse + 9, // [9:12] is the sub-list for method output_type + 6, // [6:9] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_common_mgrpc_account_account_proto_init() } +func file_common_mgrpc_account_account_proto_init() { + if File_common_mgrpc_account_account_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_common_mgrpc_account_account_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*Balance); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*Metadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*Status); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*Account); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*AccountsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*AccountsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*AccountsID); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_common_mgrpc_account_account_proto_msgTypes[7].Exporter = func(v any, i int) any { + switch v := v.(*AccountsAlias); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_common_mgrpc_account_account_proto_rawDesc, + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_common_mgrpc_account_account_proto_goTypes, + DependencyIndexes: file_common_mgrpc_account_account_proto_depIdxs, + MessageInfos: file_common_mgrpc_account_account_proto_msgTypes, + }.Build() + File_common_mgrpc_account_account_proto = out.File + file_common_mgrpc_account_account_proto_rawDesc = nil + file_common_mgrpc_account_account_proto_goTypes = nil + file_common_mgrpc_account_account_proto_depIdxs = nil +} diff --git a/common/mgrpc/account/account.proto b/common/mgrpc/account/account.proto new file mode 100644 index 00000000..e7e01e91 --- /dev/null +++ b/common/mgrpc/account/account.proto @@ -0,0 +1,63 @@ +syntax = "proto3"; + +option go_package = "./account"; +package account; + +message Balance { + double available = 1; + double on_hold = 2; + double scale = 3; +} + +message Metadata { + map value = 1; +} + +message Status { + string code = 1; + string description = 2; + bool allow_sending= 3; + bool allow_receiving = 4; +} + +message Account { + string id = 1; + string name = 2; + string parent_account_id = 3; + string entity_id = 4; + string asset_code = 5; + string organization_id = 6; + string ledger_id = 7; + string portfolio_id = 8; + string product_id = 9; + Balance balance = 10; + Status status = 11; + string alias = 12; + string type = 13; + string created_at = 14; + string updated_at = 15; + string deleted_at = 16; + Metadata metadata = 17; +} + +message AccountsResponse { + repeated Account accounts = 1; +} + +message AccountsRequest { + repeated Account accounts = 1; +} + +message AccountsID { + repeated string ids = 1; +} + +message AccountsAlias { + repeated string aliases = 1; +} + +service AccountProto { + rpc GetAccountsByIds(AccountsID) returns (AccountsResponse) {} + rpc GetAccountsByAliases(AccountsAlias) returns (AccountsResponse) {} + rpc UpdateAccounts(AccountsRequest) returns (AccountsResponse) {} +} \ No newline at end of file diff --git a/components/ledger/proto/account/account_grpc.pb.go b/common/mgrpc/account/account_grpc.pb.go similarity index 51% rename from components/ledger/proto/account/account_grpc.pb.go rename to common/mgrpc/account/account_grpc.pb.go index 601b97bd..77ebb207 100644 --- a/components/ledger/proto/account/account_grpc.pb.go +++ b/common/mgrpc/account/account_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.5.1 // - protoc v5.27.0 -// source: proto/account/account.proto +// source: common/mgrpc/account/account.proto package account @@ -19,18 +19,18 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - AccountProto_GetByIds_FullMethodName = "/account.AccountProto/GetByIds" - AccountProto_GetByAlias_FullMethodName = "/account.AccountProto/GetByAlias" - AccountProto_Update_FullMethodName = "/account.AccountProto/Update" + AccountProto_GetAccountsByIds_FullMethodName = "/account.AccountProto/GetAccountsByIds" + AccountProto_GetAccountsByAliases_FullMethodName = "/account.AccountProto/GetAccountsByAliases" + AccountProto_UpdateAccounts_FullMethodName = "/account.AccountProto/UpdateAccounts" ) // AccountProtoClient is the client API for AccountProto service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type AccountProtoClient interface { - GetByIds(ctx context.Context, in *ManyAccountsID, opts ...grpc.CallOption) (*ManyAccountsResponse, error) - GetByAlias(ctx context.Context, in *ManyAccountsAlias, opts ...grpc.CallOption) (*ManyAccountsResponse, error) - Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*Account, error) + GetAccountsByIds(ctx context.Context, in *AccountsID, opts ...grpc.CallOption) (*AccountsResponse, error) + GetAccountsByAliases(ctx context.Context, in *AccountsAlias, opts ...grpc.CallOption) (*AccountsResponse, error) + UpdateAccounts(ctx context.Context, in *AccountsRequest, opts ...grpc.CallOption) (*AccountsResponse, error) } type accountProtoClient struct { @@ -41,30 +41,30 @@ func NewAccountProtoClient(cc grpc.ClientConnInterface) AccountProtoClient { return &accountProtoClient{cc} } -func (c *accountProtoClient) GetByIds(ctx context.Context, in *ManyAccountsID, opts ...grpc.CallOption) (*ManyAccountsResponse, error) { +func (c *accountProtoClient) GetAccountsByIds(ctx context.Context, in *AccountsID, opts ...grpc.CallOption) (*AccountsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ManyAccountsResponse) - err := c.cc.Invoke(ctx, AccountProto_GetByIds_FullMethodName, in, out, cOpts...) + out := new(AccountsResponse) + err := c.cc.Invoke(ctx, AccountProto_GetAccountsByIds_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } return out, nil } -func (c *accountProtoClient) GetByAlias(ctx context.Context, in *ManyAccountsAlias, opts ...grpc.CallOption) (*ManyAccountsResponse, error) { +func (c *accountProtoClient) GetAccountsByAliases(ctx context.Context, in *AccountsAlias, opts ...grpc.CallOption) (*AccountsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ManyAccountsResponse) - err := c.cc.Invoke(ctx, AccountProto_GetByAlias_FullMethodName, in, out, cOpts...) + out := new(AccountsResponse) + err := c.cc.Invoke(ctx, AccountProto_GetAccountsByAliases_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } return out, nil } -func (c *accountProtoClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*Account, error) { +func (c *accountProtoClient) UpdateAccounts(ctx context.Context, in *AccountsRequest, opts ...grpc.CallOption) (*AccountsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Account) - err := c.cc.Invoke(ctx, AccountProto_Update_FullMethodName, in, out, cOpts...) + out := new(AccountsResponse) + err := c.cc.Invoke(ctx, AccountProto_UpdateAccounts_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -75,9 +75,9 @@ func (c *accountProtoClient) Update(ctx context.Context, in *UpdateRequest, opts // All implementations must embed UnimplementedAccountProtoServer // for forward compatibility. type AccountProtoServer interface { - GetByIds(context.Context, *ManyAccountsID) (*ManyAccountsResponse, error) - GetByAlias(context.Context, *ManyAccountsAlias) (*ManyAccountsResponse, error) - Update(context.Context, *UpdateRequest) (*Account, error) + GetAccountsByIds(context.Context, *AccountsID) (*AccountsResponse, error) + GetAccountsByAliases(context.Context, *AccountsAlias) (*AccountsResponse, error) + UpdateAccounts(context.Context, *AccountsRequest) (*AccountsResponse, error) mustEmbedUnimplementedAccountProtoServer() } @@ -88,14 +88,14 @@ type AccountProtoServer interface { // pointer dereference when methods are called. type UnimplementedAccountProtoServer struct{} -func (UnimplementedAccountProtoServer) GetByIds(context.Context, *ManyAccountsID) (*ManyAccountsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetByIds not implemented") +func (UnimplementedAccountProtoServer) GetAccountsByIds(context.Context, *AccountsID) (*AccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAccountsByIds not implemented") } -func (UnimplementedAccountProtoServer) GetByAlias(context.Context, *ManyAccountsAlias) (*ManyAccountsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetByAlias not implemented") +func (UnimplementedAccountProtoServer) GetAccountsByAliases(context.Context, *AccountsAlias) (*AccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAccountsByAliases not implemented") } -func (UnimplementedAccountProtoServer) Update(context.Context, *UpdateRequest) (*Account, error) { - return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") +func (UnimplementedAccountProtoServer) UpdateAccounts(context.Context, *AccountsRequest) (*AccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateAccounts not implemented") } func (UnimplementedAccountProtoServer) mustEmbedUnimplementedAccountProtoServer() {} func (UnimplementedAccountProtoServer) testEmbeddedByValue() {} @@ -118,56 +118,56 @@ func RegisterAccountProtoServer(s grpc.ServiceRegistrar, srv AccountProtoServer) s.RegisterService(&AccountProto_ServiceDesc, srv) } -func _AccountProto_GetByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ManyAccountsID) +func _AccountProto_GetAccountsByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AccountsID) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(AccountProtoServer).GetByIds(ctx, in) + return srv.(AccountProtoServer).GetAccountsByIds(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: AccountProto_GetByIds_FullMethodName, + FullMethod: AccountProto_GetAccountsByIds_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AccountProtoServer).GetByIds(ctx, req.(*ManyAccountsID)) + return srv.(AccountProtoServer).GetAccountsByIds(ctx, req.(*AccountsID)) } return interceptor(ctx, in, info, handler) } -func _AccountProto_GetByAlias_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ManyAccountsAlias) +func _AccountProto_GetAccountsByAliases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AccountsAlias) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(AccountProtoServer).GetByAlias(ctx, in) + return srv.(AccountProtoServer).GetAccountsByAliases(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: AccountProto_GetByAlias_FullMethodName, + FullMethod: AccountProto_GetAccountsByAliases_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AccountProtoServer).GetByAlias(ctx, req.(*ManyAccountsAlias)) + return srv.(AccountProtoServer).GetAccountsByAliases(ctx, req.(*AccountsAlias)) } return interceptor(ctx, in, info, handler) } -func _AccountProto_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateRequest) +func _AccountProto_UpdateAccounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AccountsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(AccountProtoServer).Update(ctx, in) + return srv.(AccountProtoServer).UpdateAccounts(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: AccountProto_Update_FullMethodName, + FullMethod: AccountProto_UpdateAccounts_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(AccountProtoServer).Update(ctx, req.(*UpdateRequest)) + return srv.(AccountProtoServer).UpdateAccounts(ctx, req.(*AccountsRequest)) } return interceptor(ctx, in, info, handler) } @@ -180,18 +180,18 @@ var AccountProto_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*AccountProtoServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GetByIds", - Handler: _AccountProto_GetByIds_Handler, + MethodName: "GetAccountsByIds", + Handler: _AccountProto_GetAccountsByIds_Handler, }, { - MethodName: "GetByAlias", - Handler: _AccountProto_GetByAlias_Handler, + MethodName: "GetAccountsByAliases", + Handler: _AccountProto_GetAccountsByAliases_Handler, }, { - MethodName: "Update", - Handler: _AccountProto_Update_Handler, + MethodName: "UpdateAccounts", + Handler: _AccountProto_UpdateAccounts_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "proto/account/account.proto", + Metadata: "common/mgrpc/account/account.proto", } diff --git a/common/mgrpc/grpc.go b/common/mgrpc/grpc.go new file mode 100644 index 00000000..3a2dd0a2 --- /dev/null +++ b/common/mgrpc/grpc.go @@ -0,0 +1,43 @@ +package mgrpc + +import ( + "fmt" + "log" + + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +// GRPCConnection is a struct which deal with gRPC connections. +type GRPCConnection struct { + Addr string + Conn *grpc.ClientConn +} + +// Connect keeps a singleton connection with gRPC. +func (c *GRPCConnection) Connect() error { + conn, err := grpc.NewClient(c.Addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + log.Fatal("Failed to connect on gRPC", zap.Error(err)) + return nil + } + + fmt.Println("Connected to gRPC ✅ ") + + c.Conn = conn + + return nil +} + +// GetNewClient returns a connection to gRPC, reconnect it if necessary. +func (c *GRPCConnection) GetNewClient() (*grpc.ClientConn, error) { + if c.Conn == nil { + if err := c.Connect(); err != nil { + log.Printf("ERRCONECT %s", err) + return nil, err + } + } + + return c.Conn, nil +} diff --git a/components/ledger/docker-compose.yml b/components/ledger/docker-compose.yml index 6e400d40..62bc2c55 100644 --- a/components/ledger/docker-compose.yml +++ b/components/ledger/docker-compose.yml @@ -135,4 +135,6 @@ volumes: mongodb_data_container: networks: - app-tier: \ No newline at end of file + app-tier: + driver: bridge + name: app-tier \ No newline at end of file diff --git a/components/ledger/internal/domain/portfolio/account/account.go b/components/ledger/internal/domain/portfolio/account/account.go index 126b608b..b3e2b798 100644 --- a/components/ledger/internal/domain/portfolio/account/account.go +++ b/components/ledger/internal/domain/portfolio/account/account.go @@ -4,6 +4,7 @@ import ( "database/sql" "time" + proto "github.com/LerianStudio/midaz/common/mgrpc/account" "github.com/google/uuid" ) @@ -173,3 +174,52 @@ func (t *AccountPostgreSQLModel) FromEntity(account *Account) { t.DeletedAt = sql.NullTime{Time: deletedAtCopy, Valid: true} } } + +// ToProto converts entity Account to a response protobuf proto +func (e *Account) ToProto() *proto.Account { + status := proto.Status{ + Code: e.Status.Code, + Description: *e.Status.Description, + AllowSending: e.Status.AllowSending, + AllowReceiving: e.Status.AllowReceiving, + } + + balance := proto.Balance{ + Available: *e.Balance.Available, + OnHold: *e.Balance.OnHold, + Scale: *e.Balance.Scale, + } + + account := &proto.Account{ + Id: e.ID, + Name: e.Name, + EntityId: e.EntityID, + AssetCode: e.AssetCode, + OrganizationId: e.OrganizationID, + LedgerId: e.LedgerID, + PortfolioId: e.PortfolioID, + ProductId: *e.ProductID, + Balance: &balance, + Status: &status, + Alias: *e.Alias, + Type: e.Type, + } + + if e.ParentAccountID != nil { + account.ParentAccountId = *e.ParentAccountID + } + + if e.DeletedAt != nil { + account.DeletedAt = e.DeletedAt.String() + } + + if !e.UpdatedAt.IsZero() { + account.UpdatedAt = e.UpdatedAt.String() + } + + if !e.CreatedAt.IsZero() { + account.CreatedAt = e.CreatedAt.String() + } + + return account +} diff --git a/components/ledger/internal/ports/grpc/account.go b/components/ledger/internal/ports/grpc/account.go index d94517b7..11993dd6 100644 --- a/components/ledger/internal/ports/grpc/account.go +++ b/components/ledger/internal/ports/grpc/account.go @@ -3,13 +3,14 @@ package grpc import ( "context" + "github.com/google/uuid" + "github.com/LerianStudio/midaz/common" + proto "github.com/LerianStudio/midaz/common/mgrpc/account" "github.com/LerianStudio/midaz/common/mlog" "github.com/LerianStudio/midaz/components/ledger/internal/app/command" "github.com/LerianStudio/midaz/components/ledger/internal/app/query" a "github.com/LerianStudio/midaz/components/ledger/internal/domain/portfolio/account" - proto "github.com/LerianStudio/midaz/components/ledger/proto/account" - "github.com/google/uuid" ) // AccountProto struct contains an account use case for managing account related operations. @@ -19,13 +20,13 @@ type AccountProto struct { proto.UnimplementedAccountProtoServer } -// GetByIds is a method that retrieves Account information by a given ids. -func (ap *AccountProto) GetByIds(ctx context.Context, ids *proto.ManyAccountsID) (*proto.ManyAccountsResponse, error) { +// GetAccountsByIds is a method that retrieves Account information by a given ids. +func (ap *AccountProto) GetAccountsByIds(ctx context.Context, ids *proto.AccountsID) (*proto.AccountsResponse, error) { logger := mlog.NewLoggerFromContext(ctx) - uuids := make([]uuid.UUID, len(ids.Ids)) - for i, id := range ids.Ids { - uuids[i] = uuid.MustParse(id.Id) + uuids := make([]uuid.UUID, len(ids.GetIds())) + for _, id := range ids.GetIds() { + uuids = append(uuids, uuid.MustParse(id)) } acc, err := ap.Query.ListAccountsByIDs(ctx, uuids) @@ -41,34 +42,21 @@ func (ap *AccountProto) GetByIds(ctx context.Context, ids *proto.ManyAccountsID) accounts := make([]*proto.Account, len(acc)) for _, ac := range acc { - account := proto.Account{ - Id: ac.ID, - Alias: *ac.Alias, - AvailableBalance: *ac.Balance.Available, - OnHoldBalance: *ac.Balance.OnHold, - BalanceScale: *ac.Balance.Scale, - AllowSending: ac.Status.AllowSending, - AllowReceiving: ac.Status.AllowReceiving, - } - accounts = append(accounts, &account) + accounts = append(accounts, ac.ToProto()) } - response := proto.ManyAccountsResponse{ + response := proto.AccountsResponse{ Accounts: accounts, } return &response, nil } -func (ap *AccountProto) GetByAlias(ctx context.Context, aliases *proto.ManyAccountsAlias) (*proto.ManyAccountsResponse, error) { +// GetAccountsByAliases is a method that retrieves Account information by a given aliases. +func (ap *AccountProto) GetAccountsByAliases(ctx context.Context, aliases *proto.AccountsAlias) (*proto.AccountsResponse, error) { logger := mlog.NewLoggerFromContext(ctx) - als := make([]string, len(aliases.Aliases)) - for i, aA := range aliases.Aliases { - als[i] = aA.Alias - } - - acc, err := ap.Query.ListAccountsByAlias(ctx, als) + acc, err := ap.Query.ListAccountsByAlias(ctx, aliases.GetAliases()) if err != nil { logger.Errorf("Failed to retrieve Accounts by aliases for grpc, Error: %s", err.Error()) @@ -81,60 +69,54 @@ func (ap *AccountProto) GetByAlias(ctx context.Context, aliases *proto.ManyAccou accounts := make([]*proto.Account, len(acc)) for _, ac := range acc { - account := proto.Account{ - Id: ac.ID, - Alias: *ac.Alias, - AvailableBalance: *ac.Balance.Available, - OnHoldBalance: *ac.Balance.OnHold, - BalanceScale: *ac.Balance.Scale, - AllowSending: ac.Status.AllowSending, - AllowReceiving: ac.Status.AllowReceiving, - } - accounts = append(accounts, &account) + accounts = append(accounts, ac.ToProto()) } - response := proto.ManyAccountsResponse{ + response := proto.AccountsResponse{ Accounts: accounts, } return &response, nil } -func (ap *AccountProto) Update(ctx context.Context, update *proto.UpdateRequest) (*proto.Account, error) { +// UpdateAccounts is a method that update Account balances by a given ids. +func (ap *AccountProto) UpdateAccounts(ctx context.Context, update *proto.AccountsRequest) (*proto.AccountsResponse, error) { logger := mlog.NewLoggerFromContext(ctx) - if common.IsNilOrEmpty(&update.Id) { - logger.Errorf("Failed to update Accounts because id is empty") + accounts := make([]*proto.Account, len(update.GetAccounts())) - return nil, common.ValidationError{ - Code: "0001", - Message: "Failed to update Accounts because id is empty", + for _, account := range update.GetAccounts() { + if common.IsNilOrEmpty(&account.Id) { + logger.Errorf("Failed to update Accounts because id is empty") + + return nil, common.ValidationError{ + Code: "0001", + Message: "Failed to update Accounts because id is empty", + } } - } - balance := a.Balance{ - Available: &update.AvailableBalance, - OnHold: &update.OnHoldBalance, - Scale: &update.BalanceScale, - } + balance := a.Balance{ + Available: &account.Balance.Available, + OnHold: &account.Balance.OnHold, + Scale: &account.Balance.Scale, + } - acu, err := ap.Command.UpdateAccountByID(ctx, update.Id, &balance) - if err != nil { - logger.Errorf("Failed to update balance in Account by id for grpc, Error: %s", err.Error()) + acu, err := ap.Command.UpdateAccountByID(ctx, account.Id, &balance) + if err != nil { + logger.Errorf("Failed to update balance in Account by id for grpc, Error: %s", err.Error()) - return nil, common.ValidationError{ - Code: "0002", - Message: "Failed to update balance in Account by id for grpc", + return nil, common.ValidationError{ + Code: "0002", + Message: "Failed to update balance in Account by id for grpc", + } } + + accounts = append(accounts, acu.ToProto()) } - account := proto.Account{ - Id: acu.ID, - Alias: update.Alias, - AvailableBalance: *acu.Balance.Available, - OnHoldBalance: *acu.Balance.OnHold, - BalanceScale: *acu.Balance.Scale, + response := proto.AccountsResponse{ + Accounts: accounts, } - return &account, nil + return &response, nil } diff --git a/components/ledger/internal/ports/grpc/routes.go b/components/ledger/internal/ports/grpc/routes.go index 027f57a7..d9ec5d90 100644 --- a/components/ledger/internal/ports/grpc/routes.go +++ b/components/ledger/internal/ports/grpc/routes.go @@ -1,10 +1,10 @@ package grpc import ( + proto "github.com/LerianStudio/midaz/common/mgrpc/account" "github.com/LerianStudio/midaz/components/ledger/internal/app/command" "github.com/LerianStudio/midaz/components/ledger/internal/app/query" "github.com/LerianStudio/midaz/components/ledger/internal/service" - proto "github.com/LerianStudio/midaz/components/ledger/proto/account" "google.golang.org/grpc" "google.golang.org/grpc/reflection" ) diff --git a/components/ledger/proto/account/account.pb.go b/components/ledger/proto/account/account.pb.go deleted file mode 100644 index ecfd1de5..00000000 --- a/components/ledger/proto/account/account.pb.go +++ /dev/null @@ -1,646 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.34.2 -// protoc v5.27.0 -// source: proto/account/account.proto - -package account - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type AccountID struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` -} - -func (x *AccountID) Reset() { - *x = AccountID{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AccountID) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AccountID) ProtoMessage() {} - -func (x *AccountID) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AccountID.ProtoReflect.Descriptor instead. -func (*AccountID) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{0} -} - -func (x *AccountID) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -type AccountAlias struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Alias string `protobuf:"bytes,1,opt,name=alias,proto3" json:"alias,omitempty"` -} - -func (x *AccountAlias) Reset() { - *x = AccountAlias{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AccountAlias) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AccountAlias) ProtoMessage() {} - -func (x *AccountAlias) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AccountAlias.ProtoReflect.Descriptor instead. -func (*AccountAlias) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{1} -} - -func (x *AccountAlias) GetAlias() string { - if x != nil { - return x.Alias - } - return "" -} - -type Account struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Alias string `protobuf:"bytes,2,opt,name=alias,proto3" json:"alias,omitempty"` - AvailableBalance float64 `protobuf:"fixed64,3,opt,name=available_balance,json=availableBalance,proto3" json:"available_balance,omitempty"` - OnHoldBalance float64 `protobuf:"fixed64,4,opt,name=on_hold_balance,json=onHoldBalance,proto3" json:"on_hold_balance,omitempty"` - BalanceScale float64 `protobuf:"fixed64,5,opt,name=balance_scale,json=balanceScale,proto3" json:"balance_scale,omitempty"` - AllowSending bool `protobuf:"varint,6,opt,name=allow_sending,json=allowSending,proto3" json:"allow_sending,omitempty"` - AllowReceiving bool `protobuf:"varint,7,opt,name=allow_receiving,json=allowReceiving,proto3" json:"allow_receiving,omitempty"` -} - -func (x *Account) Reset() { - *x = Account{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Account) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Account) ProtoMessage() {} - -func (x *Account) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Account.ProtoReflect.Descriptor instead. -func (*Account) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{2} -} - -func (x *Account) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *Account) GetAlias() string { - if x != nil { - return x.Alias - } - return "" -} - -func (x *Account) GetAvailableBalance() float64 { - if x != nil { - return x.AvailableBalance - } - return 0 -} - -func (x *Account) GetOnHoldBalance() float64 { - if x != nil { - return x.OnHoldBalance - } - return 0 -} - -func (x *Account) GetBalanceScale() float64 { - if x != nil { - return x.BalanceScale - } - return 0 -} - -func (x *Account) GetAllowSending() bool { - if x != nil { - return x.AllowSending - } - return false -} - -func (x *Account) GetAllowReceiving() bool { - if x != nil { - return x.AllowReceiving - } - return false -} - -type UpdateRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Alias string `protobuf:"bytes,2,opt,name=alias,proto3" json:"alias,omitempty"` - AvailableBalance float64 `protobuf:"fixed64,3,opt,name=available_balance,json=availableBalance,proto3" json:"available_balance,omitempty"` - OnHoldBalance float64 `protobuf:"fixed64,4,opt,name=on_hold_balance,json=onHoldBalance,proto3" json:"on_hold_balance,omitempty"` - BalanceScale float64 `protobuf:"fixed64,5,opt,name=balance_scale,json=balanceScale,proto3" json:"balance_scale,omitempty"` -} - -func (x *UpdateRequest) Reset() { - *x = UpdateRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *UpdateRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UpdateRequest) ProtoMessage() {} - -func (x *UpdateRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UpdateRequest.ProtoReflect.Descriptor instead. -func (*UpdateRequest) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{3} -} - -func (x *UpdateRequest) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *UpdateRequest) GetAlias() string { - if x != nil { - return x.Alias - } - return "" -} - -func (x *UpdateRequest) GetAvailableBalance() float64 { - if x != nil { - return x.AvailableBalance - } - return 0 -} - -func (x *UpdateRequest) GetOnHoldBalance() float64 { - if x != nil { - return x.OnHoldBalance - } - return 0 -} - -func (x *UpdateRequest) GetBalanceScale() float64 { - if x != nil { - return x.BalanceScale - } - return 0 -} - -type ManyAccountsResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Accounts []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` -} - -func (x *ManyAccountsResponse) Reset() { - *x = ManyAccountsResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ManyAccountsResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ManyAccountsResponse) ProtoMessage() {} - -func (x *ManyAccountsResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ManyAccountsResponse.ProtoReflect.Descriptor instead. -func (*ManyAccountsResponse) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{4} -} - -func (x *ManyAccountsResponse) GetAccounts() []*Account { - if x != nil { - return x.Accounts - } - return nil -} - -type ManyAccountsID struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Ids []*AccountID `protobuf:"bytes,1,rep,name=ids,proto3" json:"ids,omitempty"` -} - -func (x *ManyAccountsID) Reset() { - *x = ManyAccountsID{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ManyAccountsID) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ManyAccountsID) ProtoMessage() {} - -func (x *ManyAccountsID) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ManyAccountsID.ProtoReflect.Descriptor instead. -func (*ManyAccountsID) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{5} -} - -func (x *ManyAccountsID) GetIds() []*AccountID { - if x != nil { - return x.Ids - } - return nil -} - -type ManyAccountsAlias struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Aliases []*AccountAlias `protobuf:"bytes,1,rep,name=aliases,proto3" json:"aliases,omitempty"` -} - -func (x *ManyAccountsAlias) Reset() { - *x = ManyAccountsAlias{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_account_account_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ManyAccountsAlias) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ManyAccountsAlias) ProtoMessage() {} - -func (x *ManyAccountsAlias) ProtoReflect() protoreflect.Message { - mi := &file_proto_account_account_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ManyAccountsAlias.ProtoReflect.Descriptor instead. -func (*ManyAccountsAlias) Descriptor() ([]byte, []int) { - return file_proto_account_account_proto_rawDescGZIP(), []int{6} -} - -func (x *ManyAccountsAlias) GetAliases() []*AccountAlias { - if x != nil { - return x.Aliases - } - return nil -} - -var File_proto_account_account_proto protoreflect.FileDescriptor - -var file_proto_account_account_proto_rawDesc = []byte{ - 0x0a, 0x1b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2f, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x1b, 0x0a, 0x09, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x64, 0x22, 0x24, 0x0a, 0x0c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x41, 0x6c, - 0x69, 0x61, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x22, 0xf7, 0x01, 0x0a, 0x07, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x61, - 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x10, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, - 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x26, 0x0a, 0x0f, 0x6f, 0x6e, 0x5f, 0x68, - 0x6f, 0x6c, 0x64, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x01, 0x52, 0x0d, 0x6f, 0x6e, 0x48, 0x6f, 0x6c, 0x64, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x12, 0x23, 0x0a, 0x0d, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x61, 0x6c, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0c, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x53, 0x63, 0x61, 0x6c, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f, 0x73, - 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x61, 0x6c, - 0x6c, 0x6f, 0x77, 0x53, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x27, 0x0a, 0x0f, 0x61, 0x6c, - 0x6c, 0x6f, 0x77, 0x5f, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x69, 0x6e, 0x67, 0x18, 0x07, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x0e, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, - 0x69, 0x6e, 0x67, 0x22, 0xaf, 0x01, 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x61, - 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x10, 0x61, 0x76, 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, - 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x26, 0x0a, 0x0f, 0x6f, 0x6e, 0x5f, 0x68, - 0x6f, 0x6c, 0x64, 0x5f, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x01, 0x52, 0x0d, 0x6f, 0x6e, 0x48, 0x6f, 0x6c, 0x64, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x12, 0x23, 0x0a, 0x0d, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x61, 0x6c, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0c, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x53, 0x63, 0x61, 0x6c, 0x65, 0x22, 0x44, 0x0a, 0x14, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, - 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x10, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x36, 0x0a, 0x0e, 0x4d, - 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x49, 0x44, 0x12, 0x24, 0x0a, - 0x03, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x44, 0x52, 0x03, - 0x69, 0x64, 0x73, 0x22, 0x44, 0x0a, 0x11, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x73, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x2f, 0x0a, 0x07, 0x61, 0x6c, 0x69, 0x61, - 0x73, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x61, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x41, 0x6c, 0x69, 0x61, 0x73, - 0x52, 0x07, 0x61, 0x6c, 0x69, 0x61, 0x73, 0x65, 0x73, 0x32, 0xd5, 0x01, 0x0a, 0x0c, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x44, 0x0a, 0x08, 0x47, 0x65, - 0x74, 0x42, 0x79, 0x49, 0x64, 0x73, 0x12, 0x17, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x2e, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x49, 0x44, 0x1a, - 0x1d, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x49, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x42, 0x79, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x1a, - 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x1a, 0x1d, 0x2e, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x4d, 0x61, 0x6e, 0x79, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x34, 0x0a, 0x06, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x16, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, - 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x2e, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_proto_account_account_proto_rawDescOnce sync.Once - file_proto_account_account_proto_rawDescData = file_proto_account_account_proto_rawDesc -) - -func file_proto_account_account_proto_rawDescGZIP() []byte { - file_proto_account_account_proto_rawDescOnce.Do(func() { - file_proto_account_account_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_account_account_proto_rawDescData) - }) - return file_proto_account_account_proto_rawDescData -} - -var file_proto_account_account_proto_msgTypes = make([]protoimpl.MessageInfo, 7) -var file_proto_account_account_proto_goTypes = []any{ - (*AccountID)(nil), // 0: account.AccountID - (*AccountAlias)(nil), // 1: account.AccountAlias - (*Account)(nil), // 2: account.Account - (*UpdateRequest)(nil), // 3: account.UpdateRequest - (*ManyAccountsResponse)(nil), // 4: account.ManyAccountsResponse - (*ManyAccountsID)(nil), // 5: account.ManyAccountsID - (*ManyAccountsAlias)(nil), // 6: account.ManyAccountsAlias -} -var file_proto_account_account_proto_depIdxs = []int32{ - 2, // 0: account.ManyAccountsResponse.accounts:type_name -> account.Account - 0, // 1: account.ManyAccountsID.ids:type_name -> account.AccountID - 1, // 2: account.ManyAccountsAlias.aliases:type_name -> account.AccountAlias - 5, // 3: account.AccountProto.GetByIds:input_type -> account.ManyAccountsID - 6, // 4: account.AccountProto.GetByAlias:input_type -> account.ManyAccountsAlias - 3, // 5: account.AccountProto.Update:input_type -> account.UpdateRequest - 4, // 6: account.AccountProto.GetByIds:output_type -> account.ManyAccountsResponse - 4, // 7: account.AccountProto.GetByAlias:output_type -> account.ManyAccountsResponse - 2, // 8: account.AccountProto.Update:output_type -> account.Account - 6, // [6:9] is the sub-list for method output_type - 3, // [3:6] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name -} - -func init() { file_proto_account_account_proto_init() } -func file_proto_account_account_proto_init() { - if File_proto_account_account_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_proto_account_account_proto_msgTypes[0].Exporter = func(v any, i int) any { - switch v := v.(*AccountID); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[1].Exporter = func(v any, i int) any { - switch v := v.(*AccountAlias); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[2].Exporter = func(v any, i int) any { - switch v := v.(*Account); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[3].Exporter = func(v any, i int) any { - switch v := v.(*UpdateRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[4].Exporter = func(v any, i int) any { - switch v := v.(*ManyAccountsResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[5].Exporter = func(v any, i int) any { - switch v := v.(*ManyAccountsID); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_account_account_proto_msgTypes[6].Exporter = func(v any, i int) any { - switch v := v.(*ManyAccountsAlias); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_account_account_proto_rawDesc, - NumEnums: 0, - NumMessages: 7, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_proto_account_account_proto_goTypes, - DependencyIndexes: file_proto_account_account_proto_depIdxs, - MessageInfos: file_proto_account_account_proto_msgTypes, - }.Build() - File_proto_account_account_proto = out.File - file_proto_account_account_proto_rawDesc = nil - file_proto_account_account_proto_goTypes = nil - file_proto_account_account_proto_depIdxs = nil -} diff --git a/components/ledger/proto/account/account.proto b/components/ledger/proto/account/account.proto deleted file mode 100644 index a5deda14..00000000 --- a/components/ledger/proto/account/account.proto +++ /dev/null @@ -1,48 +0,0 @@ -syntax = "proto3"; - -option go_package = "./account"; -package account; - -message AccountID { - string id = 1; -} - -message AccountAlias { - string alias = 1; -} - -message Account { - string id = 1; - string alias = 2; - double available_balance = 3; - double on_hold_balance = 4; - double balance_scale = 5; - bool allow_sending= 6; - bool allow_receiving = 7; -} - -message UpdateRequest { - string id = 1; - string alias = 2; - double available_balance = 3; - double on_hold_balance = 4; - double balance_scale = 5; -} - -message ManyAccountsResponse { - repeated Account accounts = 1; -} - -message ManyAccountsID { - repeated AccountID ids = 1; -} - -message ManyAccountsAlias { - repeated AccountAlias aliases = 1; -} - -service AccountProto { - rpc GetByIds(ManyAccountsID) returns (ManyAccountsResponse) {} - rpc GetByAlias(ManyAccountsAlias) returns (ManyAccountsResponse) {} - rpc Update(UpdateRequest) returns (Account) {} -} \ No newline at end of file diff --git a/components/transaction/.env.exemple b/components/transaction/.env.example similarity index 90% rename from components/transaction/.env.exemple rename to components/transaction/.env.example index 4bbfb140..5bcd043c 100644 --- a/components/transaction/.env.exemple +++ b/components/transaction/.env.example @@ -42,4 +42,8 @@ ADMINER_PORT=8080 # TRILLIAN LOG SERVER AND SIGNER RPC_PORT=8090 HTTP_PORT=8091 -SIGNER_PORT=8092 \ No newline at end of file +SIGNER_PORT=8092 + +# LEDGER gRPC +LEDGER_GRPC_ADDR=localhost +LEDGER_GRPC_PORT=50051 \ No newline at end of file diff --git a/components/transaction/docker-compose.yml b/components/transaction/docker-compose.yml index 03756b67..046151d4 100644 --- a/components/transaction/docker-compose.yml +++ b/components/transaction/docker-compose.yml @@ -55,6 +55,7 @@ services: environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} + command: mongod --port ${MONGO_PORT} ports: - ${MONGO_PORT}:${MONGO_PORT} volumes: @@ -174,4 +175,6 @@ volumes: mongodb_data_container: networks: - app-tier: \ No newline at end of file + app-tier: + driver: bridge + name: app-tier \ No newline at end of file diff --git a/components/transaction/examples/empty.gold b/components/transaction/examples/empty.gold deleted file mode 100644 index e69de29b..00000000 diff --git a/components/transaction/examples/error.gold b/components/transaction/examples/error.gold deleted file mode 100644 index 3b654c4f..00000000 --- a/components/transaction/examples/error.gold +++ /dev/null @@ -1,19 +0,0 @@ -(transaction - (chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981) - (metadata - (m 1) - (Cpf 43049498x) - ) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4) - (description "description for the transaction not for the operation") - (send BRL 30|4 :from - (sources - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining) - ) - ) - (distribute - (to @McGeegor :share 50 :of 25 :desc whatever) - (to @jeff :amount BRL 2|4) - (to @cl3v_ :remaining) - ) -) \ No newline at end of file diff --git a/components/transaction/examples/transaction-template.gold b/components/transaction/examples/transaction-template.gold deleted file mode 100644 index c45077f4..00000000 --- a/components/transaction/examples/transaction-template.gold +++ /dev/null @@ -1,38 +0,0 @@ -(transaction V1 - (chart-of-accounts-group-name p2p_transfer_group) - (description "P2P sent") - (code P2P_TRANSFER) - (pending false) - (metadata - (anyKey anyValue) - (anotherKey anotherValue) - ) - (send BRL $amount|$scale - (source - (from $sourceAccount :amount BRL $amount|2 - (description "P2P sent to $destination") - (chart-of-accounts p2p_debit_source_8123891) - (metadata - (anyKey anyValue) - (anotherKey anotherValue) - ) - ) - ) - ) - (distribute - (to $destination :amount BRL $amount|$scale - (description "P2P sent $destination") - (chart-of-accounts p2p_credit_destination_1231412) - ) - (distribute :remaining - (to $destination :remaining - (description "P2P sent $destination") - (chart-of-accounts p2p_credit_destination_1231412) - (metadata - (anyKey anyValue) - (anotherKey anotherValue) - ) - ) - ) - ) -) \ No newline at end of file diff --git a/components/transaction/examples/transaction.gold b/components/transaction/examples/transaction.gold deleted file mode 100644 index ccac48d3..00000000 --- a/components/transaction/examples/transaction.gold +++ /dev/null @@ -1,85 +0,0 @@ -(transaction V1 - (chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981) - (description "mcgregor for the transaction not for the operation") - (metadata - (m 1) - (Cpf 43049498x) - ) - (send BRL 30|4 - (source - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 100 :of 25 :desc whatever) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining) - (from 3172933b-50d2-4b17-96aa-9b378d6a6eac :amount BRL 2|4 - (description "description for the transaction not for the operation") - ) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 50 :of 100 :desc whatever - (description "description for the transaction not for the operation") - ) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining - (description "description for the transaction not for the operation") - ) - (from 3172933b-50d2-4b17-96aa-9b378d6a6eac :amount BRL 2|4 - (metadata - (Cpf 43049498x) - (1 m) - ) - ) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 100 :of 25 :desc whatever - (metadata - (Cpf 43049498x) - (1 m) - ) - ) - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :remaining - (metadata - (Cpf 43049498x) - (1 m) - ) - ) - (source :remaining - (from 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4) - ) - ) - ) - (distribute - (to @McGeegor :share 50 :of 25 :desc whatever) - (to @jeff :amount BRL 2|4) - (to @cl3v_ :remaining) - (to 1a9ba2dd-d778-415f-a61a-387d64994eeb :share 50 :of 100 :desc whatever - (description "description for the transaction not for the operation") - ) - (to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4 - (description "description for the transaction not for the operation") - ) - (to 9fe618ed-cec1-4a5b-90d8-2f5819a8c3dd :remaining - (description "description for the transaction not for the operation") - ) - (to 540b504c-8f9d-480f-9354-3728cf7025ef :share 50 :of 25 :desc whatever - (description "description for the transaction not for the operation") - (metadata - (m m) - (Cpf 43049498x) - ) - ) - (to 540b504c-8f9d-480f-9354-3728cf7025ef :amount BRL 2|4 - (description "description for the transaction not for the operation") - (metadata - (m m) - (Cpf 43049498x) - ) - ) - (to 540b504c-8f9d-480f-9354-3728cf7025ef :remaining - (description "description for the transaction not for the operation") - (metadata - (m m) - (Cpf 43049498x) - ) - ) - (distribute :remaining - (to 540b504c-8f9d-480f-9354-3728cf7025ef :share 38) - (to @McGregor :share 50 :of 25 :desc whatever) - (to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4) - ) - ) -) \ No newline at end of file diff --git a/components/transaction/examples/transaction.yml b/components/transaction/examples/transaction.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/components/transaction/internal/adapters/database/postgres/operation.postgresql.go b/components/transaction/internal/adapters/database/postgres/operation.postgresql.go new file mode 100644 index 00000000..d9570889 --- /dev/null +++ b/components/transaction/internal/adapters/database/postgres/operation.postgresql.go @@ -0,0 +1,355 @@ +package postgres + +import ( + "context" + "database/sql" + "errors" + "reflect" + "strconv" + "strings" + "time" + + "github.com/LerianStudio/midaz/common" + "github.com/LerianStudio/midaz/common/mpostgres" + o "github.com/LerianStudio/midaz/components/transaction/internal/domain/operation" + sqrl "github.com/Masterminds/squirrel" + "github.com/google/uuid" + "github.com/lib/pq" +) + +// OperationPostgreSQLRepository is a Postgresql-specific implementation of the OperationRepository. +type OperationPostgreSQLRepository struct { + connection *mpostgres.PostgresConnection + tableName string +} + +// NewOperationPostgreSQLRepository returns a new instance of OperationPostgreSQLRepository using the given Postgres connection. +func NewOperationPostgreSQLRepository(pc *mpostgres.PostgresConnection) *OperationPostgreSQLRepository { + c := &OperationPostgreSQLRepository{ + connection: pc, + tableName: "operation", + } + + _, err := c.connection.GetDB() + if err != nil { + panic("Failed to connect database") + } + + return c +} + +// Create a new Operation entity into Postgresql and returns it. +func (r *OperationPostgreSQLRepository) Create(ctx context.Context, operation *o.Operation) (*o.Operation, error) { + db, err := r.connection.GetDB() + if err != nil { + return nil, err + } + + record := &o.OperationPostgreSQLModel{} + record.FromEntity(operation) + + result, err := db.ExecContext(ctx, `INSERT INTO operation VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25) RETURNING *`, + record.ID, + record.TransactionID, + record.Description, + record.Type, + record.InstrumentCode, + record.Amount, + record.AmountScale, + record.AvailableBalance, + record.BalanceScale, + record.OnHoldBalance, + record.AvailableBalanceAfter, + record.OnHoldBalanceAfter, + record.BalanceScaleAfter, + record.Status, + record.StatusDescription, + record.AccountID, + record.AccountAlias, + record.PortfolioID, + record.ChartOfAccounts, + record.OrganizationID, + record.LedgerID, + record.CreatedAt, + record.UpdatedAt, + record.DeletedAt, + ) + if err != nil { + return nil, err + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return nil, err + } + + if rowsAffected == 0 { + return nil, common.EntityNotFoundError{ + EntityType: reflect.TypeOf(o.Operation{}).Name(), + Title: "Entity not found.", + Code: "0007", + Message: "No entity was found matching the provided ID. Ensure the correct ID is being used for the entity you are attempting to manage.", + } + } + + return record.ToEntity(), nil +} + +// FindAll retrieves Operations entities from the database. +func (r *OperationPostgreSQLRepository) FindAll(ctx context.Context, organizationID, ledgerID, transactionID uuid.UUID, limit, page int) ([]*o.Operation, error) { + db, err := r.connection.GetDB() + if err != nil { + return nil, err + } + + var operations []*o.Operation + + findAll := sqrl.Select("*"). + From(r.tableName). + Where(sqrl.Expr("organization_id = ?", organizationID)). + Where(sqrl.Expr("ledger_id = ?", ledgerID)). + Where(sqrl.Expr("transaction_id = ?", transactionID)). + Where(sqrl.Eq{"deleted_at": nil}). + OrderBy("created_at DESC"). + Limit(common.SafeIntToUint64(limit)). + Offset(common.SafeIntToUint64((page - 1) * limit)). + PlaceholderFormat(sqrl.Dollar) + + query, args, err := findAll.ToSql() + if err != nil { + return nil, err + } + + rows, err := db.QueryContext(ctx, query, args...) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var operation o.OperationPostgreSQLModel + if err := rows.Scan( + &operation.ID, + &operation.TransactionID, + &operation.Description, + &operation.Type, + &operation.InstrumentCode, + &operation.Amount, + &operation.AmountScale, + &operation.AvailableBalance, + &operation.BalanceScale, + &operation.OnHoldBalance, + &operation.AvailableBalanceAfter, + &operation.OnHoldBalanceAfter, + &operation.BalanceScaleAfter, + &operation.Status, + &operation.StatusDescription, + &operation.AccountID, + &operation.AccountAlias, + &operation.PortfolioID, + &operation.ChartOfAccounts, + &operation.OrganizationID, + &operation.LedgerID, + &operation.CreatedAt, + &operation.UpdatedAt, + &operation.DeletedAt, + ); err != nil { + return nil, err + } + + operations = append(operations, operation.ToEntity()) + } + + if err := rows.Err(); err != nil { + return nil, err + } + + return operations, nil +} + +// ListByIDs retrieves Operation entities from the database using the provided IDs. +func (r *OperationPostgreSQLRepository) ListByIDs(ctx context.Context, organizationID, ledgerID uuid.UUID, ids []uuid.UUID) ([]*o.Operation, error) { + db, err := r.connection.GetDB() + if err != nil { + return nil, err + } + + var operations []*o.Operation + + rows, err := db.QueryContext(ctx, "SELECT * FROM operation WHERE organization_id = $1 AND ledger_id = $2 AND id = ANY($3) AND deleted_at IS NULL ORDER BY created_at DESC", + organizationID, ledgerID, pq.Array(ids)) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var operation o.OperationPostgreSQLModel + if err := rows.Scan( + &operation.ID, + &operation.TransactionID, + &operation.Description, + &operation.Type, + &operation.InstrumentCode, + &operation.Amount, + &operation.AmountScale, + &operation.AvailableBalance, + &operation.BalanceScale, + &operation.OnHoldBalance, + &operation.AvailableBalanceAfter, + &operation.OnHoldBalanceAfter, + &operation.BalanceScaleAfter, + &operation.Status, + &operation.StatusDescription, + &operation.AccountID, + &operation.AccountAlias, + &operation.PortfolioID, + &operation.ChartOfAccounts, + &operation.OrganizationID, + &operation.LedgerID, + &operation.CreatedAt, + &operation.UpdatedAt, + &operation.DeletedAt, + ); err != nil { + return nil, err + } + + operations = append(operations, operation.ToEntity()) + } + + if err := rows.Err(); err != nil { + return nil, err + } + + return operations, nil +} + +// Find retrieves a Operation entity from the database using the provided ID. +func (r *OperationPostgreSQLRepository) Find(ctx context.Context, organizationID, ledgerID, id uuid.UUID) (*o.Operation, error) { + db, err := r.connection.GetDB() + if err != nil { + return nil, err + } + + operation := &o.OperationPostgreSQLModel{} + + row := db.QueryRowContext(ctx, "SELECT * FROM operation WHERE organization_id = $1 AND ledger_id = $2 AND id = $3 AND deleted_at IS NULL", + organizationID, ledgerID, id) + if err := row.Scan( + &operation.ID, + &operation.TransactionID, + &operation.Description, + &operation.Type, + &operation.InstrumentCode, + &operation.Amount, + &operation.AmountScale, + &operation.AvailableBalance, + &operation.BalanceScale, + &operation.OnHoldBalance, + &operation.AvailableBalanceAfter, + &operation.OnHoldBalanceAfter, + &operation.BalanceScaleAfter, + &operation.Status, + &operation.StatusDescription, + &operation.AccountID, + &operation.AccountAlias, + &operation.PortfolioID, + &operation.ChartOfAccounts, + &operation.OrganizationID, + &operation.LedgerID, + &operation.CreatedAt, + &operation.UpdatedAt, + &operation.DeletedAt, + ); err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, common.EntityNotFoundError{ + EntityType: reflect.TypeOf(o.Operation{}).Name(), + Title: "Entity not found.", + Code: "0007", + Message: "No entity was found matching the provided ID. Ensure the correct ID is being used for the entity you are attempting to manage.", + } + } + + return nil, err + } + + return operation.ToEntity(), nil +} + +// Update a Operation entity into Postgresql and returns the Operation updated. +func (r *OperationPostgreSQLRepository) Update(ctx context.Context, organizationID, ledgerID, id uuid.UUID, operation *o.Operation) (*o.Operation, error) { + db, err := r.connection.GetDB() + if err != nil { + return nil, err + } + + record := &o.OperationPostgreSQLModel{} + record.FromEntity(operation) + + var updates []string + + var args []any + + record.UpdatedAt = time.Now() + + updates = append(updates, "updated_at = $"+strconv.Itoa(len(args)+1)) + + args = append(args, record.UpdatedAt, organizationID, ledgerID, id) + + query := `UPDATE operation SET ` + strings.Join(updates, ", ") + + ` WHERE organization_id = $` + strconv.Itoa(len(args)-2) + + ` AND ledger_id = $` + strconv.Itoa(len(args)-1) + + ` AND id = $` + strconv.Itoa(len(args)) + + ` AND deleted_at IS NULL` + + result, err := db.ExecContext(ctx, query, args...) + if err != nil { + return nil, err + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return nil, err + } + + if rowsAffected == 0 { + return nil, common.EntityNotFoundError{ + EntityType: reflect.TypeOf(o.Operation{}).Name(), + Title: "Entity not found.", + Code: "0007", + Message: "No entity was found matching the provided ID. Ensure the correct ID is being used for the entity you are attempting to manage.", + } + } + + return record.ToEntity(), nil +} + +// Delete removes a Operation entity from the database using the provided IDs. +func (r *OperationPostgreSQLRepository) Delete(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error { + db, err := r.connection.GetDB() + if err != nil { + return err + } + + result, err := db.ExecContext(ctx, `UPDATE operation SET deleted_at = now() WHERE organization_id = $1 AND ledger_id = $2 AND id = $3 AND deleted_at IS NULL`, + organizationID, ledgerID, id) + if err != nil { + return err + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return err + } + + if rowsAffected == 0 { + return common.EntityNotFoundError{ + EntityType: reflect.TypeOf(o.Operation{}).Name(), + Title: "Entity not found.", + Code: "0007", + Message: "No entity was found matching the provided ID. Ensure the correct ID is being used for the entity you are attempting to manage.", + } + } + + return nil +} diff --git a/components/transaction/internal/adapters/database/postgres/transaction.postgresql.go b/components/transaction/internal/adapters/database/postgres/transaction.postgresql.go index ad292e1b..87c4613e 100644 --- a/components/transaction/internal/adapters/database/postgres/transaction.postgresql.go +++ b/components/transaction/internal/adapters/database/postgres/transaction.postgresql.go @@ -48,12 +48,13 @@ func (r *TransactionPostgreSQLRepository) Create(ctx context.Context, transactio record := &t.TransactionPostgreSQLModel{} record.FromEntity(transaction) - result, err := db.ExecContext(ctx, `INSERT INTO transaction VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *`, + result, err := db.ExecContext(ctx, `INSERT INTO transaction VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *`, record.ID, record.ParentTransactionID, record.Description, record.Template, record.Status, + record.StatusDescription, record.Amount, record.AmountScale, record.AssetCode, diff --git a/components/transaction/internal/adapters/grpc/account.grpc.go b/components/transaction/internal/adapters/grpc/account.grpc.go new file mode 100644 index 00000000..17f2849a --- /dev/null +++ b/components/transaction/internal/adapters/grpc/account.grpc.go @@ -0,0 +1,74 @@ +package grpc + +import ( + "context" + + "github.com/LerianStudio/midaz/common/mgrpc" + proto "github.com/LerianStudio/midaz/common/mgrpc/account" +) + +// AccountGRPCRepository is a gRPC implementation of the account.proto +type AccountGRPCRepository struct { + conn *mgrpc.GRPCConnection +} + +// NewAccountGRPC returns a new instance of AccountGRPCRepository using the given gRPC connection. +func NewAccountGRPC(c *mgrpc.GRPCConnection) *AccountGRPCRepository { + agrpc := &AccountGRPCRepository{ + conn: c, + } + + _, err := c.GetNewClient() + if err != nil { + panic("Failed to connect gRPC") + } + + return agrpc +} + +// GetAccountsByIds returns a grpc accounts on ledger bi given ids. +func (a *AccountGRPCRepository) GetAccountsByIds(ctx context.Context, ids []string) (*proto.AccountsResponse, error) { + conn, err := a.conn.GetNewClient() + if err != nil { + return nil, err + } + + account := proto.NewAccountProtoClient(conn) + + accountsID := &proto.AccountsID{ + Ids: ids, + } + + accountsResponse, err := account.GetAccountsByIds(ctx, accountsID) + if err != nil { + return nil, err + } + + return accountsResponse, nil +} + +// GetAccountsByAlias returns a grpc accounts on ledger bi given aliases. +func (a *AccountGRPCRepository) GetAccountsByAlias(ctx context.Context, aliases []string) (*proto.AccountsResponse, error) { + conn, err := a.conn.GetNewClient() + if err != nil { + return nil, err + } + + account := proto.NewAccountProtoClient(conn) + + accountsAlias := &proto.AccountsAlias{ + Aliases: aliases, + } + + accountsResponse, err := account.GetAccountsByAliases(ctx, accountsAlias) + if err != nil { + return nil, err + } + + return accountsResponse, nil +} + +// UpdateAccounts update a grpc accounts on ledger. +func (a *AccountGRPCRepository) UpdateAccounts(ctx context.Context, accounts []*proto.Account) (*proto.AccountsResponse, error) { + return nil, nil +} diff --git a/components/transaction/internal/app/command/command.go b/components/transaction/internal/app/command/command.go index e364654b..a054846b 100644 --- a/components/transaction/internal/app/command/command.go +++ b/components/transaction/internal/app/command/command.go @@ -1,6 +1,8 @@ package command import ( + a "github.com/LerianStudio/midaz/components/transaction/internal/domain/account" + m "github.com/LerianStudio/midaz/components/transaction/internal/domain/metadata" t "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction" ) @@ -8,4 +10,10 @@ import ( type UseCase struct { // TransactionRepo provides an abstraction on top of the transaction data source. TransactionRepo t.Repository + + // AccountGRPCRepo provides an abstraction on top of the account grpc. + AccountGRPCRepo a.Repository + + // MetadataRepo provides an abstraction on top of the metadata data source. + MetadataRepo m.Repository } diff --git a/components/transaction/internal/app/command/create-transaction.go b/components/transaction/internal/app/command/create-transaction.go index 6875aa64..9adbcd91 100644 --- a/components/transaction/internal/app/command/create-transaction.go +++ b/components/transaction/internal/app/command/create-transaction.go @@ -2,12 +2,84 @@ package command import ( "context" + "reflect" + "strconv" + "time" + "github.com/LerianStudio/midaz/common" + "github.com/LerianStudio/midaz/common/constant" gold "github.com/LerianStudio/midaz/common/gold/transaction/model" + "github.com/LerianStudio/midaz/common/mlog" + m "github.com/LerianStudio/midaz/components/transaction/internal/domain/metadata" t "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction" + "github.com/google/uuid" ) -// CreateTransaction creates a new transaction persists data in the repository. -func (uc *UseCase) CreateTransaction(ctx context.Context, template *gold.Transaction) (*t.Transaction, error) { - return nil, nil +// CreateTransaction creates a new transaction persisting data in the repository. +func (uc *UseCase) CreateTransaction(ctx context.Context, organizationID, ledgerID string, transaction *gold.Transaction) (*t.Transaction, error) { + logger := mlog.NewLoggerFromContext(ctx) + logger.Infof("Trying to create new transaction") + + description := constant.CREATED + status := t.Status{ + Code: description, + Description: &description, + } + + amount, err := strconv.ParseFloat(transaction.Send.Value, 64) + if err != nil { + logger.Errorf("Error converting amount string to float64: %v", err) + return nil, err + } + + scale, err := strconv.ParseFloat(transaction.Send.Scale, 64) + if err != nil { + logger.Errorf("Error converting scale string to float64: %v", err) + return nil, err + } + + save := &t.Transaction{ + ID: uuid.New().String(), + ParentTransactionID: nil, + OrganizationID: organizationID, + LedgerID: ledgerID, + Description: transaction.Description, + Template: transaction.ChartOfAccountsGroupName, + Status: status, + Amount: &amount, + AmountScale: &scale, + AssetCode: transaction.Send.Asset, + ChartOfAccountsGroupName: transaction.ChartOfAccountsGroupName, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + + tran, err := uc.TransactionRepo.Create(ctx, save) + if err != nil { + logger.Errorf("Error creating transaction: %v", err) + return nil, err + } + + if transaction.Metadata != nil { + if err := common.CheckMetadataKeyAndValueLength(100, transaction.Metadata); err != nil { + return nil, err + } + + meta := m.Metadata{ + EntityID: tran.ID, + EntityName: reflect.TypeOf(t.Transaction{}).Name(), + Data: transaction.Metadata, + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + } + + if err := uc.MetadataRepo.Create(ctx, reflect.TypeOf(t.Transaction{}).Name(), &meta); err != nil { + logger.Errorf("Error into creating transaction metadata: %v", err) + return nil, err + } + + tran.Metadata = transaction.Metadata + } + + return tran, nil } diff --git a/components/transaction/internal/app/query/query.go b/components/transaction/internal/app/query/query.go index 45b5b710..3d1ada84 100644 --- a/components/transaction/internal/app/query/query.go +++ b/components/transaction/internal/app/query/query.go @@ -1,6 +1,8 @@ package query import ( + a "github.com/LerianStudio/midaz/components/transaction/internal/domain/account" + m "github.com/LerianStudio/midaz/components/transaction/internal/domain/metadata" t "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction" ) @@ -8,4 +10,10 @@ import ( type UseCase struct { // TransactionRepo provides an abstraction on top of the transaction data source. TransactionRepo t.Repository + + // AccountGRPCRepo provides an abstraction on top of the account grpc. + AccountGRPCRepo a.Repository + + // MetadataRepo provides an abstraction on top of the metadata data source. + MetadataRepo m.Repository } diff --git a/components/transaction/internal/domain/account/account_repository.go b/components/transaction/internal/domain/account/account_repository.go new file mode 100644 index 00000000..ce2144f0 --- /dev/null +++ b/components/transaction/internal/domain/account/account_repository.go @@ -0,0 +1,16 @@ +package account + +import ( + "context" + + proto "github.com/LerianStudio/midaz/common/mgrpc/account" +) + +// Repository provides an interface for gRPC operations related to account in the Ledger. +// +//go:generate mockgen --destination=../../gen/mock/account/account_mock.go --package=mock . Repository +type Repository interface { + GetAccountsByIds(ctx context.Context, ids []string) (*proto.AccountsResponse, error) + GetAccountsByAlias(ctx context.Context, aliases []string) (*proto.AccountsResponse, error) + UpdateAccounts(ctx context.Context, accounts []*proto.Account) (*proto.AccountsResponse, error) +} diff --git a/components/transaction/internal/domain/operation/operation.go b/components/transaction/internal/domain/operation/operation.go new file mode 100644 index 00000000..d3bc22c3 --- /dev/null +++ b/components/transaction/internal/domain/operation/operation.go @@ -0,0 +1,179 @@ +package operation + +import ( + "database/sql" + "time" + + "github.com/google/uuid" +) + +// OperationPostgreSQLModel represents the entity OperationPostgreSQLModel into SQL context in Database +type OperationPostgreSQLModel struct { + ID string + TransactionID string + Description string + Type string + InstrumentCode string + Amount *float64 + AmountScale *float64 + AvailableBalance *float64 + BalanceScale *float64 + OnHoldBalance *float64 + AvailableBalanceAfter *float64 + OnHoldBalanceAfter *float64 + BalanceScaleAfter *float64 + Status string + StatusDescription *string + AccountID string + AccountAlias string + PortfolioID string + ChartOfAccounts string + OrganizationID string + LedgerID string + CreatedAt time.Time + UpdatedAt time.Time + DeletedAt sql.NullTime + Metadata map[string]any +} + +// Status structure for marshaling/unmarshalling JSON. +type Status struct { + Code string `json:"code"` + Description *string `json:"description"` +} + +// IsEmpty method that set empty or nil in fields +func (s Status) IsEmpty() bool { + return s.Code == "" && s.Description == nil +} + +// Amount structure for marshaling/unmarshalling JSON. +type Amount struct { + Amount *float64 `json:"amount"` + Scale *float64 `json:"scale"` +} + +// IsEmpty method that set empty or nil in fields +func (a Amount) IsEmpty() bool { + return a.Amount == nil && a.Scale == nil +} + +// Balance structure for marshaling/unmarshalling JSON. +type Balance struct { + Available *float64 `json:"available"` + OnHold *float64 `json:"onHold"` + Scale *float64 `json:"scale"` +} + +// IsEmpty method that set empty or nil in fields +func (b Balance) IsEmpty() bool { + return b.Available == nil && b.OnHold == nil && b.Scale == nil +} + +// Operation is a struct designed to encapsulate response payload data. +type Operation struct { + ID string `json:"id"` + TransactionID string `json:"transactionId"` + Description string `json:"description"` + Type string `json:"type"` + InstrumentCode string `json:"instrumentCode"` + ChartOfAccounts string `json:"chartOfAccounts"` + Amount Amount `json:"amount"` + Balance Balance `json:"balance"` + BalanceAfter Balance `json:"balanceAfter"` + Status Status `json:"status"` + AccountID string `json:"accountId"` + AccountAlias string `json:"accountAlias"` + PortfolioID string `json:"portfolioId"` + OrganizationID string `json:"organizationId"` + LedgerID string `json:"ledgerId"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt *time.Time `json:"deletedAt"` + Metadata map[string]any `json:"metadata"` +} + +// ToEntity converts an OperationPostgreSQLModel to entity Operation +func (t *OperationPostgreSQLModel) ToEntity() *Operation { + status := Status{ + Code: t.Status, + Description: t.StatusDescription, + } + + amount := Amount{ + Amount: t.Amount, + Scale: t.AmountScale, + } + + balance := Balance{ + Available: t.AvailableBalance, + OnHold: t.OnHoldBalance, + Scale: t.BalanceScale, + } + + balanceAfter := Balance{ + Available: t.AvailableBalanceAfter, + OnHold: t.OnHoldBalanceAfter, + Scale: t.BalanceScaleAfter, + } + + Operation := &Operation{ + ID: t.ID, + TransactionID: t.TransactionID, + Description: t.Description, + Type: t.Type, + InstrumentCode: t.InstrumentCode, + ChartOfAccounts: t.ChartOfAccounts, + Amount: amount, + Balance: balance, + BalanceAfter: balanceAfter, + Status: status, + AccountID: t.AccountID, + AccountAlias: t.AccountAlias, + LedgerID: t.LedgerID, + OrganizationID: t.OrganizationID, + CreatedAt: t.CreatedAt, + UpdatedAt: t.UpdatedAt, + DeletedAt: nil, + } + + if !t.DeletedAt.Time.IsZero() { + deletedAtCopy := t.DeletedAt.Time + Operation.DeletedAt = &deletedAtCopy + } + + return Operation +} + +// FromEntity converts an entity Operation to OperationPostgreSQLModel +func (t *OperationPostgreSQLModel) FromEntity(operation *Operation) { + *t = OperationPostgreSQLModel{ + ID: uuid.New().String(), + TransactionID: operation.TransactionID, + Description: operation.Description, + Type: operation.Type, + InstrumentCode: operation.InstrumentCode, + ChartOfAccounts: operation.ChartOfAccounts, + Amount: operation.Amount.Amount, + AmountScale: operation.Amount.Scale, + BalanceScale: operation.Balance.Scale, + OnHoldBalance: operation.Balance.OnHold, + AvailableBalance: operation.Balance.Available, + BalanceScaleAfter: operation.BalanceAfter.Scale, + AvailableBalanceAfter: operation.BalanceAfter.Available, + OnHoldBalanceAfter: operation.BalanceAfter.Scale, + Status: operation.Status.Code, + StatusDescription: operation.Status.Description, + AccountID: operation.AccountID, + AccountAlias: operation.AccountAlias, + LedgerID: operation.LedgerID, + OrganizationID: operation.OrganizationID, + CreatedAt: operation.CreatedAt, + UpdatedAt: operation.UpdatedAt, + } + + if operation.DeletedAt != nil { + deletedAtCopy := *operation.DeletedAt + t.DeletedAt = sql.NullTime{Time: deletedAtCopy, Valid: true} + } +} diff --git a/components/transaction/internal/domain/operation/operation_repository.go b/components/transaction/internal/domain/operation/operation_repository.go new file mode 100644 index 00000000..1b335d70 --- /dev/null +++ b/components/transaction/internal/domain/operation/operation_repository.go @@ -0,0 +1,19 @@ +package operation + +import ( + "context" + + "github.com/google/uuid" +) + +// Repository provides an interface for operations related to operation template entities. +// +//go:generate mockgen --destination=../../gen/mock/operation/operation_mock.go --package=mock . Repository +type Repository interface { + Create(ctx context.Context, operation *Operation) (*Operation, error) + FindAll(ctx context.Context, organizationID, ledgerID, transactionID uuid.UUID, limit, page int) ([]*Operation, error) + Find(ctx context.Context, organizationID, ledgerID, id uuid.UUID) (*Operation, error) + ListByIDs(ctx context.Context, organizationID, ledgerID uuid.UUID, ids []uuid.UUID) ([]*Operation, error) + Update(ctx context.Context, organizationID, ledgerID, id uuid.UUID, operation *Operation) (*Operation, error) + Delete(ctx context.Context, organizationID, ledgerID, id uuid.UUID) error +} diff --git a/components/transaction/internal/gen/inject.go b/components/transaction/internal/gen/inject.go index 5ae224c6..fa64f65a 100644 --- a/components/transaction/internal/gen/inject.go +++ b/components/transaction/internal/gen/inject.go @@ -5,17 +5,24 @@ package gen import ( "fmt" - "github.com/LerianStudio/midaz/components/transaction/internal/adapters/database/postgres" - "github.com/LerianStudio/midaz/components/transaction/internal/ports" "sync" "github.com/LerianStudio/midaz/common" + "github.com/LerianStudio/midaz/common/mgrpc" "github.com/LerianStudio/midaz/common/mmongo" "github.com/LerianStudio/midaz/common/mpostgres" "github.com/LerianStudio/midaz/common/mzap" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/database/mongodb" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/database/postgres" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/grpc" + adapter "github.com/LerianStudio/midaz/components/transaction/internal/adapters/grpc" "github.com/LerianStudio/midaz/components/transaction/internal/app/command" "github.com/LerianStudio/midaz/components/transaction/internal/app/query" + a "github.com/LerianStudio/midaz/components/transaction/internal/domain/account" + m "github.com/LerianStudio/midaz/components/transaction/internal/domain/metadata" + o "github.com/LerianStudio/midaz/components/transaction/internal/domain/operation" t "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction" + "github.com/LerianStudio/midaz/components/transaction/internal/ports" httpHandler "github.com/LerianStudio/midaz/components/transaction/internal/ports/http" "github.com/LerianStudio/midaz/components/transaction/internal/service" "github.com/google/wire" @@ -47,6 +54,15 @@ func setupMongoDBConnection(cfg *service.Config) *mmongo.MongoConnection { return &mmongo.MongoConnection{ ConnectionStringSource: connStrSource, + Database: cfg.MongoDBName, + } +} + +func setupGRPCConnection(cfg *service.Config) *mgrpc.GRPCConnection { + addr := fmt.Sprintf("%s:%s", cfg.LedgerGRPCAddr, cfg.LedgerGRPCPort) + + return &mgrpc.GRPCConnection{ + Addr: addr, } } @@ -56,14 +72,21 @@ var ( mzap.InitializeLogger, setupPostgreSQLConnection, setupMongoDBConnection, + setupGRPCConnection, service.NewConfig, httpHandler.NewRouter, service.NewServer, postgres.NewTransactionPostgreSQLRepository, + postgres.NewOperationPostgreSQLRepository, + mongodb.NewMetadataMongoDBRepository, + grpc.NewAccountGRPC, wire.Struct(new(ports.TransactionHandler), "*"), wire.Struct(new(command.UseCase), "*"), wire.Struct(new(query.UseCase), "*"), wire.Bind(new(t.Repository), new(*postgres.TransactionPostgreSQLRepository)), + wire.Bind(new(o.Repository), new(*postgres.OperationPostgreSQLRepository)), + wire.Bind(new(a.Repository), new(*adapter.AccountGRPCRepository)), + wire.Bind(new(m.Repository), new(*mongodb.MetadataMongoDBRepository)), ) svcSet = wire.NewSet( diff --git a/components/transaction/internal/gen/mock/account/account_mock.go b/components/transaction/internal/gen/mock/account/account_mock.go new file mode 100644 index 00000000..fe52c232 --- /dev/null +++ b/components/transaction/internal/gen/mock/account/account_mock.go @@ -0,0 +1,86 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/LerianStudio/midaz/components/transaction/internal/domain/account (interfaces: Repository) +// +// Generated by this command: +// +// mockgen --destination=../../gen/mock/account/account_mock.go --package=mock . Repository +// + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + account "github.com/LerianStudio/midaz/common/mgrpc/account" + gomock "go.uber.org/mock/gomock" +) + +// MockRepository is a mock of Repository interface. +type MockRepository struct { + ctrl *gomock.Controller + recorder *MockRepositoryMockRecorder +} + +// MockRepositoryMockRecorder is the mock recorder for MockRepository. +type MockRepositoryMockRecorder struct { + mock *MockRepository +} + +// NewMockRepository creates a new mock instance. +func NewMockRepository(ctrl *gomock.Controller) *MockRepository { + mock := &MockRepository{ctrl: ctrl} + mock.recorder = &MockRepositoryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder { + return m.recorder +} + +// GetAccountsByAlias mocks base method. +func (m *MockRepository) GetAccountsByAlias(arg0 context.Context, arg1 []string) (*account.AccountsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountsByAlias", arg0, arg1) + ret0, _ := ret[0].(*account.AccountsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAccountsByAlias indicates an expected call of GetAccountsByAlias. +func (mr *MockRepositoryMockRecorder) GetAccountsByAlias(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountsByAlias", reflect.TypeOf((*MockRepository)(nil).GetAccountsByAlias), arg0, arg1) +} + +// GetAccountsByIds mocks base method. +func (m *MockRepository) GetAccountsByIds(arg0 context.Context, arg1 []string) (*account.AccountsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountsByIds", arg0, arg1) + ret0, _ := ret[0].(*account.AccountsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAccountsByIds indicates an expected call of GetAccountsByIds. +func (mr *MockRepositoryMockRecorder) GetAccountsByIds(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountsByIds", reflect.TypeOf((*MockRepository)(nil).GetAccountsByIds), arg0, arg1) +} + +// UpdateAccounts mocks base method. +func (m *MockRepository) UpdateAccounts(arg0 context.Context, arg1 []*account.Account) (*account.AccountsResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateAccounts", arg0, arg1) + ret0, _ := ret[0].(*account.AccountsResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateAccounts indicates an expected call of UpdateAccounts. +func (mr *MockRepositoryMockRecorder) UpdateAccounts(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAccounts", reflect.TypeOf((*MockRepository)(nil).UpdateAccounts), arg0, arg1) +} diff --git a/components/transaction/internal/gen/mock/operation/operation_mock.go b/components/transaction/internal/gen/mock/operation/operation_mock.go new file mode 100644 index 00000000..dfbd1570 --- /dev/null +++ b/components/transaction/internal/gen/mock/operation/operation_mock.go @@ -0,0 +1,131 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/LerianStudio/midaz/components/transaction/internal/domain/operation (interfaces: Repository) +// +// Generated by this command: +// +// mockgen --destination=../../gen/mock/operation/operation_mock.go --package=mock . Repository +// + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + operation "github.com/LerianStudio/midaz/components/transaction/internal/domain/operation" + uuid "github.com/google/uuid" + gomock "go.uber.org/mock/gomock" +) + +// MockRepository is a mock of Repository interface. +type MockRepository struct { + ctrl *gomock.Controller + recorder *MockRepositoryMockRecorder +} + +// MockRepositoryMockRecorder is the mock recorder for MockRepository. +type MockRepositoryMockRecorder struct { + mock *MockRepository +} + +// NewMockRepository creates a new mock instance. +func NewMockRepository(ctrl *gomock.Controller) *MockRepository { + mock := &MockRepository{ctrl: ctrl} + mock.recorder = &MockRepositoryMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRepository) EXPECT() *MockRepositoryMockRecorder { + return m.recorder +} + +// Create mocks base method. +func (m *MockRepository) Create(arg0 context.Context, arg1 *operation.Operation) (*operation.Operation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Create", arg0, arg1) + ret0, _ := ret[0].(*operation.Operation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Create indicates an expected call of Create. +func (mr *MockRepositoryMockRecorder) Create(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockRepository)(nil).Create), arg0, arg1) +} + +// Delete mocks base method. +func (m *MockRepository) Delete(arg0 context.Context, arg1, arg2, arg3 uuid.UUID) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// Delete indicates an expected call of Delete. +func (mr *MockRepositoryMockRecorder) Delete(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockRepository)(nil).Delete), arg0, arg1, arg2, arg3) +} + +// Find mocks base method. +func (m *MockRepository) Find(arg0 context.Context, arg1, arg2, arg3 uuid.UUID) (*operation.Operation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Find", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*operation.Operation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Find indicates an expected call of Find. +func (mr *MockRepositoryMockRecorder) Find(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockRepository)(nil).Find), arg0, arg1, arg2, arg3) +} + +// FindAll mocks base method. +func (m *MockRepository) FindAll(arg0 context.Context, arg1, arg2, arg3 uuid.UUID, arg4, arg5 int) ([]*operation.Operation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindAll", arg0, arg1, arg2, arg3, arg4, arg5) + ret0, _ := ret[0].([]*operation.Operation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindAll indicates an expected call of FindAll. +func (mr *MockRepositoryMockRecorder) FindAll(arg0, arg1, arg2, arg3, arg4, arg5 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindAll", reflect.TypeOf((*MockRepository)(nil).FindAll), arg0, arg1, arg2, arg3, arg4, arg5) +} + +// ListByIDs mocks base method. +func (m *MockRepository) ListByIDs(arg0 context.Context, arg1, arg2 uuid.UUID, arg3 []uuid.UUID) ([]*operation.Operation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListByIDs", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].([]*operation.Operation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListByIDs indicates an expected call of ListByIDs. +func (mr *MockRepositoryMockRecorder) ListByIDs(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByIDs", reflect.TypeOf((*MockRepository)(nil).ListByIDs), arg0, arg1, arg2, arg3) +} + +// Update mocks base method. +func (m *MockRepository) Update(arg0 context.Context, arg1, arg2, arg3 uuid.UUID, arg4 *operation.Operation) (*operation.Operation, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(*operation.Operation) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Update indicates an expected call of Update. +func (mr *MockRepositoryMockRecorder) Update(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockRepository)(nil).Update), arg0, arg1, arg2, arg3, arg4) +} diff --git a/components/transaction/internal/gen/wire_gen.go b/components/transaction/internal/gen/wire_gen.go index 4324f76c..4682331f 100644 --- a/components/transaction/internal/gen/wire_gen.go +++ b/components/transaction/internal/gen/wire_gen.go @@ -9,12 +9,18 @@ package gen import ( "fmt" "github.com/LerianStudio/midaz/common" + "github.com/LerianStudio/midaz/common/mgrpc" "github.com/LerianStudio/midaz/common/mmongo" "github.com/LerianStudio/midaz/common/mpostgres" "github.com/LerianStudio/midaz/common/mzap" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/database/mongodb" "github.com/LerianStudio/midaz/components/transaction/internal/adapters/database/postgres" + "github.com/LerianStudio/midaz/components/transaction/internal/adapters/grpc" "github.com/LerianStudio/midaz/components/transaction/internal/app/command" "github.com/LerianStudio/midaz/components/transaction/internal/app/query" + "github.com/LerianStudio/midaz/components/transaction/internal/domain/account" + "github.com/LerianStudio/midaz/components/transaction/internal/domain/metadata" + "github.com/LerianStudio/midaz/components/transaction/internal/domain/operation" "github.com/LerianStudio/midaz/components/transaction/internal/domain/transaction" "github.com/LerianStudio/midaz/components/transaction/internal/ports" "github.com/LerianStudio/midaz/components/transaction/internal/ports/http" @@ -30,11 +36,19 @@ func InitializeService() *service.Service { config := service.NewConfig() postgresConnection := setupPostgreSQLConnection(config) transactionPostgreSQLRepository := postgres.NewTransactionPostgreSQLRepository(postgresConnection) + grpcConnection := setupGRPCConnection(config) + accountGRPCRepository := grpc.NewAccountGRPC(grpcConnection) + mongoConnection := setupMongoDBConnection(config) + metadataMongoDBRepository := mongodb.NewMetadataMongoDBRepository(mongoConnection) useCase := &command.UseCase{ TransactionRepo: transactionPostgreSQLRepository, + AccountGRPCRepo: accountGRPCRepository, + MetadataRepo: metadataMongoDBRepository, } queryUseCase := &query.UseCase{ TransactionRepo: transactionPostgreSQLRepository, + AccountGRPCRepo: accountGRPCRepository, + MetadataRepo: metadataMongoDBRepository, } transactionHandler := &ports.TransactionHandler{ Command: useCase, @@ -78,12 +92,22 @@ func setupMongoDBConnection(cfg *service.Config) *mmongo.MongoConnection { return &mmongo.MongoConnection{ ConnectionStringSource: connStrSource, + Database: cfg.MongoDBName, + } +} + +func setupGRPCConnection(cfg *service.Config) *mgrpc.GRPCConnection { + addr := fmt.Sprintf("%s:%s", cfg.LedgerGRPCAddr, cfg.LedgerGRPCPort) + + return &mgrpc.GRPCConnection{ + Addr: addr, } } var ( serviceSet = wire.NewSet(common.InitLocalEnvConfig, mzap.InitializeLogger, setupPostgreSQLConnection, - setupMongoDBConnection, service.NewConfig, http.NewRouter, service.NewServer, postgres.NewTransactionPostgreSQLRepository, wire.Struct(new(ports.TransactionHandler), "*"), wire.Struct(new(command.UseCase), "*"), wire.Struct(new(query.UseCase), "*"), wire.Bind(new(transaction.Repository), new(*postgres.TransactionPostgreSQLRepository)), + setupMongoDBConnection, + setupGRPCConnection, service.NewConfig, http.NewRouter, service.NewServer, postgres.NewTransactionPostgreSQLRepository, postgres.NewOperationPostgreSQLRepository, mongodb.NewMetadataMongoDBRepository, grpc.NewAccountGRPC, wire.Struct(new(ports.TransactionHandler), "*"), wire.Struct(new(command.UseCase), "*"), wire.Struct(new(query.UseCase), "*"), wire.Bind(new(transaction.Repository), new(*postgres.TransactionPostgreSQLRepository)), wire.Bind(new(operation.Repository), new(*postgres.OperationPostgreSQLRepository)), wire.Bind(new(account.Repository), new(*grpc.AccountGRPCRepository)), wire.Bind(new(metadata.Repository), new(*mongodb.MetadataMongoDBRepository)), ) svcSet = wire.NewSet(wire.Struct(new(service.Service), "Server", "Logger")) diff --git a/components/transaction/internal/ports/http/routes.go b/components/transaction/internal/ports/http/routes.go index 99b711b1..8b78b97a 100644 --- a/components/transaction/internal/ports/http/routes.go +++ b/components/transaction/internal/ports/http/routes.go @@ -25,8 +25,7 @@ func NewRouter(th *ports.TransactionHandler) *fiber.App { f.Post("/v1/organizations/:organization_id/ledgers/:ledger_id/transactions", th.CreateTransaction) f.Post("/v1/organizations/:organization_id/ledgers/:ledger_id/transactions/:transaction_id/commit", th.CommitTransaction) f.Post("/v1/organizations/:organization_id/ledgers/:ledger_id/transactions/:transaction_id/revert", th.RevertTransaction) - - // f.Patch("/v1/organizations/:organization_id/ledgers/:ledger_id/transactions/:transaction_id", nil) + f.Get("/v1/organizations/:organization_id/ledgers/:ledger_id/transactions/:transaction_id", th.GetTransaction) // Transactions Templates f.Post("/v1/organizations/:organization_id/ledgers/:ledger_id/transaction-templates", lib.WithBody(new(t.InputDSL), th.CreateTransactionTemplate)) diff --git a/components/transaction/internal/ports/transaction.go b/components/transaction/internal/ports/transaction.go index 9dc09130..96a2b3a6 100644 --- a/components/transaction/internal/ports/transaction.go +++ b/components/transaction/internal/ports/transaction.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/LerianStudio/midaz/common/gold/transaction" + gold "github.com/LerianStudio/midaz/common/gold/transaction/model" "github.com/LerianStudio/midaz/common/mlog" commonHTTP "github.com/LerianStudio/midaz/common/net/http" "github.com/LerianStudio/midaz/components/transaction/internal/app/command" @@ -21,6 +22,9 @@ type TransactionHandler struct { func (handler *TransactionHandler) CreateTransaction(c *fiber.Ctx) error { logger := mlog.NewLoggerFromContext(c.UserContext()) + organizationID := c.Params("organization_id") + ledgerID := c.Params("ledger_id") + dsl, err := commonHTTP.GetFileFromHeader(c) if err != nil { logger.Error("Failed to validate and parse transaction", err.Error()) @@ -42,11 +46,41 @@ func (handler *TransactionHandler) CreateTransaction(c *fiber.Ctx) error { return c.Status(http.StatusBadRequest).JSON(err) } - tran := transaction.Parse(dsl) + parsed := transaction.Parse(dsl) logger.Infof("Transaction parsed and validated") - return commonHTTP.Created(c, tran) + transactionParsed, ok := parsed.(gold.Transaction) + if !ok { + return c.Status(http.StatusBadRequest).JSON("Type assertion failed") + } + + alias := make([]string, len(transactionParsed.Send.Source.From)+len(transactionParsed.Distribute.To)) + for _, from := range transactionParsed.Send.Source.From { + alias = append(alias, from.Account) + } + + for _, to := range transactionParsed.Distribute.To { + alias = append(alias, to.Account) + } + + ret, err := handler.Query.AccountGRPCRepo.GetAccountsByAlias(c.Context(), alias) + if err != nil { + logger.Error("Failed to get account gRPC on Ledger", err.Error()) + return commonHTTP.WithError(c, err) + } + + for _, ac := range ret.Accounts { + logger.Infof("Account %s founded on Ledger", ac.Alias) + } + + entity, err := handler.Command.CreateTransaction(c.Context(), organizationID, ledgerID, &transactionParsed) + if err != nil { + logger.Error("Failed to create transaction", err.Error()) + return commonHTTP.WithError(c, err) + } + + return commonHTTP.Created(c, entity) } // CreateTransactionTemplate method that create transaction template @@ -72,3 +106,10 @@ func (handler *TransactionHandler) RevertTransaction(c *fiber.Ctx) error { return commonHTTP.Created(c, logger) } + +// GetTransaction method that get transaction created before +func (handler *TransactionHandler) GetTransaction(c *fiber.Ctx) error { + logger := mlog.NewLoggerFromContext(c.UserContext()) + + return commonHTTP.Created(c, logger) +} diff --git a/components/transaction/internal/service/config.go b/components/transaction/internal/service/config.go index 3702d0ad..8e34cb15 100644 --- a/components/transaction/internal/service/config.go +++ b/components/transaction/internal/service/config.go @@ -23,6 +23,8 @@ type Config struct { MongoDBUser string `env:"MONGO_USER"` MongoDBPassword string `env:"MONGO_PASSWORD"` MongoDBPort string `env:"MONGO_PORT"` + LedgerGRPCAddr string `env:"LEDGER_GRPC_ADDR"` + LedgerGRPCPort string `env:"LEDGER_GRPC_PORT"` } // NewConfig creates an instance of Config.