Skip to content

Commit fd94ae3

Browse files
add the points_count field to the rates/chart method
1 parent 9718286 commit fd94ae3

7 files changed

+123
-10
lines changed

api/openapi.json

+12
Original file line numberDiff line numberDiff line change
@@ -8717,6 +8717,18 @@
87178717
"format": "int64",
87188718
"type": "integer"
87198719
}
8720+
},
8721+
{
8722+
"in": "query",
8723+
"name": "points_count",
8724+
"required": false,
8725+
"schema": {
8726+
"default": 200,
8727+
"format": "int",
8728+
"maximum": 200,
8729+
"minimum": 0,
8730+
"type": "integer"
8731+
}
87208732
}
87218733
],
87228734
"responses": {

api/openapi.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,15 @@ paths:
16981698
type: integer
16991699
format: int64
17001700
example: 1668436763
1701+
- name: points_count
1702+
in: query
1703+
required: false
1704+
schema:
1705+
type: integer
1706+
format: int
1707+
maximum: 200
1708+
minimum: 0
1709+
default: 200
17011710
responses:
17021711
'200':
17031712
description: token chart

pkg/api/interfaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ type addressBook interface {
157157

158158
type ratesSource interface {
159159
GetRates(date int64) (map[string]float64, error)
160-
GetRatesChart(token string, currency string, startDate *int64, endDate *int64) ([][]any, error)
160+
GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([][]any, error)
161161
GetMarketsTonPrice() []rates.Market
162162
}
163163

pkg/api/rates_handlers.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ func (h *Handler) GetChartRates(ctx context.Context, params oas.GetChartRatesPar
3737
if params.EndDate.Set {
3838
endDate = &params.EndDate.Value
3939
}
40-
charts, err := h.ratesSource.GetRatesChart(token, params.Currency.Value, startDate, endDate)
40+
var defaultPointsCount = 200
41+
if params.PointsCount.Set {
42+
if params.PointsCount.Value > defaultPointsCount {
43+
return nil, toError(http.StatusBadRequest, fmt.Errorf("max points: %v", defaultPointsCount))
44+
} else {
45+
defaultPointsCount = params.PointsCount.Value
46+
}
47+
}
48+
charts, err := h.ratesSource.GetRatesChart(token, params.Currency.Value, defaultPointsCount, startDate, endDate)
4149
if err != nil {
4250
return nil, toError(http.StatusInternalServerError, err)
4351
}

pkg/oas/oas_handlers_gen.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oas/oas_parameters_gen.go

+84-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/rates/calculator.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type ratesSource interface {
1111
GetRates(date int64) (map[string]float64, error)
12-
GetRatesChart(token string, currency string, startDate *int64, endDate *int64) ([][]any, error)
12+
GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([][]any, error)
1313
GetMarketsTonPrice() []Market
1414
}
1515

@@ -103,8 +103,8 @@ func (c *calculator) GetRates(date int64) (map[string]float64, error) {
103103
return nil, fmt.Errorf("invalid period")
104104
}
105105

106-
func (c *calculator) GetRatesChart(token string, currency string, startDate *int64, endDate *int64) ([][]any, error) {
107-
return c.source.GetRatesChart(token, currency, startDate, endDate)
106+
func (c *calculator) GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([][]any, error) {
107+
return c.source.GetRatesChart(token, currency, pointsCount, startDate, endDate)
108108
}
109109

110110
func (c *calculator) GetMarketsTonPrice() []Market {
@@ -123,6 +123,6 @@ func (m Mock) GetMarketsTonPrice() []Market {
123123
return m.GetCurrentMarketsTonPrice()
124124
}
125125

126-
func (m Mock) GetRatesChart(token string, currency string, startDate *int64, endDate *int64) ([][]any, error) {
126+
func (m Mock) GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([][]any, error) {
127127
return [][]any{}, nil
128128
}

0 commit comments

Comments
 (0)