-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom date type for /v1/analytics/data #79
Conversation
@zloyleshiy Спасибо, что нашел проблему и предложил ее решение. Думаю, что такое решение вполне подходит. В будущем, скорее всего, перейдем на использование тэгов, когда это добавят (golang/go#63397 Секция |
да уж, будем ждать :) |
@zloyleshiy Привет. Не тороплю, но хотелось бы узнать статус PR :) |
ozon/common.go
Outdated
|
||
const layout = "2006-01-02" | ||
|
||
type RequestDate struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай здесь добавим функцию NewRequestDate(t time.Time, layout string) *RequestDate
, чтобы можно было легко создавать этот тип данных и маршалить в любой формат.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавил
ozon/common.go
Outdated
@@ -804,3 +808,25 @@ const ( | |||
// reissue of returns at the pick-up point | |||
TransactionServiceRedistributionReturnsPVZ TransactionOperationService = "MarketplaceServiceItemRedistributionReturnsPVZ" | |||
) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай это перенесем в core.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
перетащил
ozon/common.go
Outdated
|
||
func (rd *RequestDate) MarshalJSON() ([]byte, error) { | ||
if rd.Time.IsZero() { | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, здесь будет ошибка, т.к. encoding/json проверяет на валидность. Может стоит возвращать что-то типа return []byte(`""`), nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Формально все корректно: []byte это слайс байтов, и он вполне себе может быть nil
Предлагаю пока оставить как есть и потестировать когда найдется ручка которая возвращает дату в каком то виде
ozon/common.go
Outdated
|
||
func (rd *RequestDate) UnmarshalJSON(b []byte) (err error) { | ||
s := strings.Trim(string(b), `"`) // remove quotes | ||
if s == "null" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, что encoding/json пропускает такие поля и не вызывает функцию UnmarshalJSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не уверен, но пока тыркался были какието ошибки, в том виде в котором сейчас - вполне себе работает
дико извиняюсь, но как то пропустил замечания к МРу |
причина: time.Time маршалится в формате который не понимает api ozon (date_from=2024-03-18+00%3A00%3A00+%2B0000+UTC)
https://api-seller.ozon.ru/v1/analytics/data
в ответе данные за 90 дней, а не за 30
без изменений: в ответе данные за 90 дней, а не за 30
меняем в структуре GetAnalyticsDataParams тип полей 'DateFrom' и 'DateTo' с time.Time на string
получаем данные как и ожидалось за 30 дней
вводим новый тип данных, со своим маршалингом
получаем данные как и ожидалось за 30 дней