Repository navigation
Expand file tree
/
Copy pathtransaction_queries.go
More file actions
128 lines (107 loc) · 4.65 KB
/
Copy pathtransaction_queries.go
File metadata and controls
128 lines (107 loc) · 4.65 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Copyright 2024 Blnk Finance Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package blnk
import (
"context"
"github.com/blnkfinance/blnk/internal/filter"
"github.com/blnkfinance/blnk/model"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func (l *Blnk) GetTransaction(ctx context.Context, TransactionID string) (*model.Transaction, error) {
ctx, span := tracer.Start(ctx, "GetTransaction")
defer span.End()
// Fetch the transaction from the datasource
transaction, err := l.datasource.GetTransaction(ctx, TransactionID)
if err != nil {
span.RecordError(err)
return nil, err
}
span.AddEvent("Transaction retrieved", trace.WithAttributes(attribute.String("transaction.id", TransactionID)))
return transaction, nil
}
// GetAllTransactions retrieves all transactions from the datasource.
// It starts a tracing span, fetches all transactions, and records relevant events and errors.
//
// Returns:
// - []model.Transaction: A slice of all retrieved Transaction models.
// - error: An error if the transactions could not be retrieved.
func (l *Blnk) GetAllTransactions(limit, offset int) ([]model.Transaction, error) {
ctx, span := tracer.Start(context.Background(), "GetAllTransactions")
defer span.End()
// Fetch all transactions from the datasource
transactions, err := l.datasource.GetAllTransactions(ctx, limit, offset)
if err != nil {
span.RecordError(err)
return nil, err
}
span.AddEvent("All transactions retrieved")
return transactions, nil
}
// GetAllTransactionsWithFilter retrieves transactions using advanced filters.
// It starts a tracing span, fetches transactions matching the filter criteria, and records relevant events.
//
// Parameters:
// - ctx context.Context: The context for the operation.
// - filters *filter.QueryFilterSet: Filter conditions to apply.
// - limit int: Maximum number of transactions to return.
// - offset int: Offset for pagination.
//
// Returns:
// - []model.Transaction: A slice of Transaction models matching the filter criteria.
// - error: An error if the transactions could not be retrieved.
func (l *Blnk) GetAllTransactionsWithFilter(ctx context.Context, filters *filter.QueryFilterSet, limit, offset int) ([]model.Transaction, error) {
ctx, span := tracer.Start(ctx, "GetAllTransactionsWithFilter")
defer span.End()
transactions, err := l.datasource.GetAllTransactionsWithFilter(ctx, filters, limit, offset)
if err != nil {
span.RecordError(err)
return nil, err
}
span.AddEvent("Transactions with filter retrieved")
return transactions, nil
}
// GetAllTransactionsWithFilterAndOptions retrieves transactions with advanced filters, sorting, and optional count.
func (l *Blnk) GetAllTransactionsWithFilterAndOptions(ctx context.Context, filters *filter.QueryFilterSet, opts *filter.QueryOptions, limit, offset int) ([]model.Transaction, *int64, error) {
ctx, span := tracer.Start(ctx, "GetAllTransactionsWithFilterAndOptions")
defer span.End()
transactions, count, err := l.datasource.GetAllTransactionsWithFilterAndOptions(ctx, filters, opts, limit, offset)
if err != nil {
span.RecordError(err)
return nil, nil, err
}
span.AddEvent("Transactions with filter and options retrieved")
return transactions, count, nil
}
// GetTransactionByRef retrieves a transaction by its reference from the datasource.
// It starts a tracing span, fetches the transaction by reference, and records relevant events and errors.
//
// Parameters:
// - ctx context.Context: The context for the operation.
// - reference string: The reference of the transaction to be retrieved.
//
// Returns:
// - model.Transaction: The retrieved Transaction model.
// - error: An error if the transaction could not be retrieved.
func (l *Blnk) GetTransactionByRef(ctx context.Context, reference string) (model.Transaction, error) {
ctx, span := tracer.Start(ctx, "GetTransactionByRef")
defer span.End()
// Fetch the transaction by reference from the datasource
transaction, err := l.datasource.GetTransactionByRef(ctx, reference)
if err != nil {
span.RecordError(err)
return model.Transaction{}, err
}
span.AddEvent("Transaction retrieved by reference", trace.WithAttributes(attribute.String("transaction.reference", reference)))
return transaction, nil
}