-
Notifications
You must be signed in to change notification settings - Fork 0
/
fiat.resolvers.go
382 lines (305 loc) · 13.3 KB
/
fiat.resolvers.go
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package graphql
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.49
import (
"context"
"errors"
"fmt"
"strconv"
"github.com/gofrs/uuid"
"github.com/shopspring/decimal"
"github.com/surahman/FTeX/pkg/common"
graphql_generated "github.com/surahman/FTeX/pkg/graphql/generated"
"github.com/surahman/FTeX/pkg/models"
"github.com/surahman/FTeX/pkg/postgres"
)
// Currency is the resolver for the currency field.
func (r *fiatAccountResolver) Currency(ctx context.Context, obj *postgres.FiatAccount) (string, error) {
return string(obj.Currency), nil
}
// Balance is the resolver for the balance field.
func (r *fiatAccountResolver) Balance(ctx context.Context, obj *postgres.FiatAccount) (float64, error) {
return obj.Balance.InexactFloat64(), nil
}
// LastTx is the resolver for the lastTx field.
func (r *fiatAccountResolver) LastTx(ctx context.Context, obj *postgres.FiatAccount) (float64, error) {
return obj.LastTx.InexactFloat64(), nil
}
// LastTxTs is the resolver for the lastTxTs field.
func (r *fiatAccountResolver) LastTxTs(ctx context.Context, obj *postgres.FiatAccount) (string, error) {
return obj.LastTxTs.Time.String(), nil
}
// CreatedAt is the resolver for the createdAt field.
func (r *fiatAccountResolver) CreatedAt(ctx context.Context, obj *postgres.FiatAccount) (string, error) {
return obj.CreatedAt.Time.String(), nil
}
// ClientID is the resolver for the clientID field.
func (r *fiatAccountResolver) ClientID(ctx context.Context, obj *postgres.FiatAccount) (string, error) {
return obj.ClientID.String(), nil
}
// TxID is the resolver for the txId field.
func (r *fiatDepositResponseResolver) TxID(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return obj.TxID.String(), nil
}
// ClientID is the resolver for the clientId field.
func (r *fiatDepositResponseResolver) ClientID(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return obj.ClientID.String(), nil
}
// TxTimestamp is the resolver for the txTimestamp field.
func (r *fiatDepositResponseResolver) TxTimestamp(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return obj.TxTS.Time.String(), nil
}
// Balance is the resolver for the balance field.
func (r *fiatDepositResponseResolver) Balance(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return obj.Balance.String(), nil
}
// LastTx is the resolver for the lastTx field.
func (r *fiatDepositResponseResolver) LastTx(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return obj.LastTx.String(), nil
}
// Currency is the resolver for the currency field.
func (r *fiatDepositResponseResolver) Currency(ctx context.Context, obj *postgres.FiatAccountTransferResult) (string, error) {
return string(obj.Currency), nil
}
// SourceReceipt is the resolver for the sourceReceipt field.
func (r *fiatExchangeTransferResponseResolver) SourceReceipt(ctx context.Context, obj *models.HTTPFiatTransferResponse) (*postgres.FiatAccountTransferResult, error) {
return obj.SrcTxReceipt, nil
}
// DestinationReceipt is the resolver for the destinationReceipt field.
func (r *fiatExchangeTransferResponseResolver) DestinationReceipt(ctx context.Context, obj *models.HTTPFiatTransferResponse) (*postgres.FiatAccountTransferResult, error) {
return obj.DstTxReceipt, nil
}
// Currency is the resolver for the currency field.
func (r *fiatJournalResolver) Currency(ctx context.Context, obj *postgres.FiatJournal) (string, error) {
return string(obj.Currency), nil
}
// Amount is the resolver for the amount field.
func (r *fiatJournalResolver) Amount(ctx context.Context, obj *postgres.FiatJournal) (float64, error) {
return obj.Amount.InexactFloat64(), nil
}
// TransactedAt is the resolver for the transactedAt field.
func (r *fiatJournalResolver) TransactedAt(ctx context.Context, obj *postgres.FiatJournal) (string, error) {
return obj.TransactedAt.Time.String(), nil
}
// ClientID is the resolver for the clientID field.
func (r *fiatJournalResolver) ClientID(ctx context.Context, obj *postgres.FiatJournal) (string, error) {
return obj.ClientID.String(), nil
}
// TxID is the resolver for the txID field.
func (r *fiatJournalResolver) TxID(ctx context.Context, obj *postgres.FiatJournal) (string, error) {
return obj.TxID.String(), nil
}
// Transactions is the resolver for the transactions field.
func (r *fiatTransactionsPaginatedResolver) Transactions(ctx context.Context, obj *models.HTTPFiatTransactionsPaginated) ([]postgres.FiatJournal, error) {
return obj.TransactionDetails, nil
}
// OpenFiat is the resolver for the openFiat field.
func (r *mutationResolver) OpenFiat(ctx context.Context, currency string) (*models.FiatOpenAccountResponse, error) {
var (
clientID uuid.UUID
errMessage string
err error
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if _, errMessage, err = common.HTTPFiatOpen(r.db, r.logger, clientID, currency); err != nil {
return nil, errors.New(errMessage)
}
return &models.FiatOpenAccountResponse{ClientID: clientID.String(), Currency: currency}, nil
}
// DepositFiat is the resolver for the depositFiat field.
func (r *mutationResolver) DepositFiat(ctx context.Context, input models.HTTPDepositCurrencyRequest) (*postgres.FiatAccountTransferResult, error) {
var (
clientID uuid.UUID
err error
httpMessage string
transferReceipt *postgres.FiatAccountTransferResult
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if transferReceipt, _, httpMessage, _, err =
common.HTTPFiatDeposit(r.db, r.logger, clientID, &input); err != nil {
return nil, errors.New(httpMessage)
}
return transferReceipt, nil
}
// ExchangeOfferFiat is the resolver for the exchangeOfferFiat field.
func (r *mutationResolver) ExchangeOfferFiat(ctx context.Context, input models.HTTPExchangeOfferRequest) (*models.HTTPExchangeOfferResponse, error) {
var (
clientID uuid.UUID
err error
httpMessage string
payload any
offer *models.HTTPExchangeOfferResponse
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if offer, _, httpMessage, payload, err =
common.HTTPFiatOffer(r.auth, r.cache, r.logger, r.quotes, clientID, &input); err != nil {
return nil, fmt.Errorf("%s: %v", httpMessage, payload)
}
return offer, nil
}
// ExchangeTransferFiat is the resolver for the exchangeTransferFiat field.
func (r *mutationResolver) ExchangeTransferFiat(ctx context.Context, offerID string) (*models.HTTPFiatTransferResponse, error) {
var (
err error
clientID uuid.UUID
httpMessage string
payload any
receipt *models.HTTPFiatTransferResponse
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if receipt, _, httpMessage, payload, err = common.HTTPFiatTransfer(r.auth, r.cache, r.db, r.logger,
clientID, &models.HTTPTransferRequest{OfferID: offerID}); err != nil {
return nil, fmt.Errorf("%s: %v", httpMessage, payload)
}
return receipt, nil
}
// BalanceFiat is the resolver for the balanceFiat field.
func (r *queryResolver) BalanceFiat(ctx context.Context, currencyCode string) (*postgres.FiatAccount, error) {
var (
accDetails *postgres.FiatAccount
clientID uuid.UUID
err error
httpMessage string
payload any
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if accDetails, _, httpMessage, payload, err =
common.HTTPFiatBalance(r.db, r.logger, clientID, currencyCode); err != nil {
return nil, fmt.Errorf("%s: %v", httpMessage, payload)
}
return accDetails, nil
}
// BalanceAllFiat is the resolver for the balanceAllFiat field.
func (r *queryResolver) BalanceAllFiat(ctx context.Context, pageCursor *string, pageSize *int32) (*models.HTTPFiatDetailsPaginated, error) {
var (
accDetails *models.HTTPFiatDetailsPaginated
clientID uuid.UUID
err error
httpMessage string
)
if pageSize == nil {
pageSize = new(int32)
}
if pageCursor == nil {
pageCursor = new(string)
}
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if accDetails, _, httpMessage, err = common.HTTPFiatBalancePaginated(r.auth, r.db, r.logger,
clientID, *pageCursor, strconv.Itoa(int(*pageSize)), false); err != nil {
return nil, errors.New(httpMessage)
}
return accDetails, nil
}
// TransactionDetailsFiat is the resolver for the transactionDetailsFiat field.
func (r *queryResolver) TransactionDetailsFiat(ctx context.Context, transactionID string) ([]any, error) {
var (
journalEntries []any
clientID uuid.UUID
err error
httpMessage string
)
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if journalEntries, _, httpMessage, err = common.HTTPTxDetails(r.db, r.logger, clientID, transactionID); err != nil {
return nil, errors.New(httpMessage)
}
return journalEntries, nil
}
// TransactionDetailsAllFiat is the resolver for the transactionDetailsAllFiat field.
func (r *queryResolver) TransactionDetailsAllFiat(ctx context.Context, input models.FiatPaginatedTxDetailsRequest) (*models.HTTPFiatTransactionsPaginated, error) {
var (
journalEntries *models.HTTPFiatTransactionsPaginated
clientID uuid.UUID
err error
params common.HTTPPaginatedTxParams
httpMessage string
payload any
)
if input.PageSize == nil {
input.PageSize = new(string)
}
params.PageSizeStr = *input.PageSize
if input.PageCursor == nil {
input.PageCursor = new(string)
}
params.PageCursorStr = *input.PageCursor
if input.Timezone == nil {
input.Timezone = new(string)
}
params.TimezoneStr = *input.Timezone
if input.Month == nil {
input.Month = new(string)
}
params.MonthStr = *input.Month
if input.Year == nil {
input.Year = new(string)
}
params.YearStr = *input.Year
if clientID, _, err = AuthorizationCheck(ctx, r.auth, r.db, r.logger, r.authHeaderKey); err != nil {
return nil, errors.New("authorization failure")
}
if journalEntries, _, httpMessage, payload, err = common.HTTPFiatTransactionsPaginated(r.auth, r.db,
r.logger, clientID, input.Currency, ¶ms, false); err != nil {
return nil, fmt.Errorf("%s: %v", httpMessage, payload)
}
return journalEntries, nil
}
// Amount is the resolver for the amount field.
func (r *fiatDepositRequestResolver) Amount(ctx context.Context, obj *models.HTTPDepositCurrencyRequest, data float64) error {
obj.Amount = decimal.NewFromFloat(data)
return nil
}
// SourceAmount is the resolver for the sourceAmount field.
func (r *fiatExchangeOfferRequestResolver) SourceAmount(ctx context.Context, obj *models.HTTPExchangeOfferRequest, data float64) error {
obj.SourceAmount = decimal.NewFromFloat(data)
return nil
}
// FiatAccount returns graphql_generated.FiatAccountResolver implementation.
func (r *Resolver) FiatAccount() graphql_generated.FiatAccountResolver {
return &fiatAccountResolver{r}
}
// FiatDepositResponse returns graphql_generated.FiatDepositResponseResolver implementation.
func (r *Resolver) FiatDepositResponse() graphql_generated.FiatDepositResponseResolver {
return &fiatDepositResponseResolver{r}
}
// FiatExchangeTransferResponse returns graphql_generated.FiatExchangeTransferResponseResolver implementation.
func (r *Resolver) FiatExchangeTransferResponse() graphql_generated.FiatExchangeTransferResponseResolver {
return &fiatExchangeTransferResponseResolver{r}
}
// FiatJournal returns graphql_generated.FiatJournalResolver implementation.
func (r *Resolver) FiatJournal() graphql_generated.FiatJournalResolver {
return &fiatJournalResolver{r}
}
// FiatTransactionsPaginated returns graphql_generated.FiatTransactionsPaginatedResolver implementation.
func (r *Resolver) FiatTransactionsPaginated() graphql_generated.FiatTransactionsPaginatedResolver {
return &fiatTransactionsPaginatedResolver{r}
}
// FiatDepositRequest returns graphql_generated.FiatDepositRequestResolver implementation.
func (r *Resolver) FiatDepositRequest() graphql_generated.FiatDepositRequestResolver {
return &fiatDepositRequestResolver{r}
}
// FiatExchangeOfferRequest returns graphql_generated.FiatExchangeOfferRequestResolver implementation.
func (r *Resolver) FiatExchangeOfferRequest() graphql_generated.FiatExchangeOfferRequestResolver {
return &fiatExchangeOfferRequestResolver{r}
}
type fiatAccountResolver struct{ *Resolver }
type fiatDepositResponseResolver struct{ *Resolver }
type fiatExchangeTransferResponseResolver struct{ *Resolver }
type fiatJournalResolver struct{ *Resolver }
type fiatTransactionsPaginatedResolver struct{ *Resolver }
type fiatDepositRequestResolver struct{ *Resolver }
type fiatExchangeOfferRequestResolver struct{ *Resolver }