-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
121 lines (103 loc) · 5.81 KB
/
http.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
package models
import (
"github.com/shopspring/decimal"
modelsPostgres "github.com/surahman/FTeX/pkg/models/postgres"
"github.com/surahman/FTeX/pkg/postgres"
)
// JWTAuthResponse is the response to a successful login and token refresh.
// The client uses the expires field on to know when to refresh the token.
//
//nolint:lll
type JWTAuthResponse struct {
Token string `json:"token" validate:"required" yaml:"token"` // JWT string sent to and validated by the server.
Expires int64 `json:"expires" validate:"required" yaml:"expires"` // Expiration time as unix time stamp. Strictly used by client to gauge when to refresh the token.
Threshold int64 `json:"threshold" validate:"required" yaml:"threshold"` // The window in seconds before expiration during which the token can be refreshed.
}
// HTTPError is a generic error message that is returned to the requester.
type HTTPError struct {
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Payload any `json:"payload,omitempty" yaml:"payload,omitempty"`
}
// HTTPSuccess is a generic success message that is returned to the requester.
type HTTPSuccess struct {
Message string `json:"message,omitempty" yaml:"message,omitempty"`
Payload any `json:"payload,omitempty" yaml:"payload,omitempty"`
}
// HTTPDeleteUserRequest is the request to mark a user account as deleted. The user must supply their login credentials
// as well as a confirmation message.
type HTTPDeleteUserRequest struct {
modelsPostgres.UserLoginCredentials
Confirmation string `json:"confirmation" validate:"required" yaml:"confirmation"`
}
// HTTPOpenCurrencyAccountRequest is a request to open an account in a specified Fiat currency.
type HTTPOpenCurrencyAccountRequest struct {
Currency string `json:"currency" validate:"required" yaml:"currency"`
}
// HTTPDepositCurrencyRequest is a request to deposit currency in to a specified Fiat currency.
type HTTPDepositCurrencyRequest struct {
Amount decimal.Decimal `json:"amount" validate:"required" yaml:"amount"`
Currency string `json:"currency" validate:"required" yaml:"currency"`
}
// HTTPExchangeOfferRequest is a request to convert a source to destination currency in the source currency amount.
type HTTPExchangeOfferRequest struct {
SourceCurrency string `json:"sourceCurrency" validate:"required" yaml:"sourceCurrency"`
DestinationCurrency string `json:"destinationCurrency" validate:"required" yaml:"destinationCurrency"`
SourceAmount decimal.Decimal `json:"sourceAmount" validate:"required" yaml:"sourceAmount"`
}
// HTTPCryptoOfferRequest is a request to convert a source to destination currency in the source currency amount.
type HTTPCryptoOfferRequest struct {
HTTPExchangeOfferRequest `json:"request" validate:"required" yaml:"request"`
IsPurchase *bool `json:"isPurchase" validate:"required" yaml:"isPurchase"`
}
// HTTPExchangeOfferResponse is an offer to convert a source to destination currency in the source currency amount.
type HTTPExchangeOfferResponse struct {
PriceQuote `json:"offer" yaml:"offer"`
DebitAmount decimal.Decimal `json:"debitAmount" yaml:"debitAmount"`
OfferID string `json:"offerId" yaml:"offerId"`
Expires int64 `json:"expires" yaml:"expires"`
IsCryptoPurchase bool `json:"isCryptoPurchase,omitempty" yaml:"isCryptoPurchase,omitempty"`
IsCryptoSale bool `json:"isCryptoSale,omitempty" yaml:"isCryptoSale,omitempty"`
}
// HTTPTransferRequest is the request to accept and execute an existing exchange offer.
type HTTPTransferRequest struct {
OfferID string `json:"offerId" validate:"required" yaml:"offerId"`
}
// HTTPFiatTransferResponse is the response to a successful Fiat exchange conversion request.
type HTTPFiatTransferResponse struct {
SrcTxReceipt *postgres.FiatAccountTransferResult `json:"sourceReceipt" yaml:"sourceReceipt"`
DstTxReceipt *postgres.FiatAccountTransferResult `json:"destinationReceipt" yaml:"destinationReceipt"`
}
// HTTPCryptoTransferResponse is the response to a successful Cryptocurrency purchase/sale request.
type HTTPCryptoTransferResponse struct {
FiatTxReceipt *postgres.FiatJournal `json:"fiatReceipt" yaml:"fiatReceipt"`
CryptoTxReceipt *postgres.CryptoJournal `json:"cryptoReceipt" yaml:"cryptoReceipt"`
}
// HTTPFiatDetailsPaginated is the response to paginated account details request. It returns a link to the next page of
// information.
type HTTPFiatDetailsPaginated struct {
AccountBalances []postgres.FiatAccount `json:"accountBalances"`
Links HTTPLinks `json:"links"`
}
// HTTPFiatTransactionsPaginated is the response to paginated account transactions request. It returns a link to the
// next page of information.
type HTTPFiatTransactionsPaginated struct {
TransactionDetails []postgres.FiatJournal `json:"transactionDetails"`
Links HTTPLinks `json:"links,omitempty"`
}
// HTTPLinks are links used in HTTP responses to retrieve pages of information.
type HTTPLinks struct {
NextPage string `json:"nextPage,omitempty"`
PageCursor string `json:"pageCursor,omitempty"`
}
// HTTPCryptoDetailsPaginated is the response to paginated account details request. It returns a link to the next page
// of information.
type HTTPCryptoDetailsPaginated struct {
AccountBalances []postgres.CryptoAccount `json:"accountBalances"`
Links HTTPLinks `json:"links"`
}
// HTTPCryptoTransactionsPaginated is the response to paginated account transactions request. It returns a link to the
// next page of information.
type HTTPCryptoTransactionsPaginated struct {
TransactionDetails []postgres.CryptoJournal `json:"transactionDetails"`
Links HTTPLinks `json:"links,omitempty"`
}