Skip to content

Commit 73370f7

Browse files
authored
Merge pull request #105 from Neur0toxine/fix-favorites
fix broken favorites methods
2 parents 8bf793a + c954f49 commit 73370f7

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed

client.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,10 +2213,12 @@ func (c *Client) GetFavorites(site, customer string, filter FavoritesFilter) (Fa
22132213
// var client = retailcrm.New("https://demo.url", "09jIJ")
22142214
//
22152215
// data, status, err := client.AddFavorite("site_id", "customer_external_id", retailcrm.FavoritesFilter{SiteBy: "id", By: "externalId"},
2216-
// retailcrm.AddFavoriteRequest{
2217-
// ID: 1,
2218-
// ExternalID: "ext_id",
2219-
// XMLID: "xml_id",
2216+
// retailcrm.ChangeFavoritesRequest{
2217+
// Offer: retailcrm.SerializedRelationOffer{
2218+
// ID: 1,
2219+
// ExternalID: "ext_id",
2220+
// XMLID: "xml_id",
2221+
// },
22202222
// },
22212223
// )
22222224
//
@@ -2227,7 +2229,7 @@ func (c *Client) GetFavorites(site, customer string, filter FavoritesFilter) (Fa
22272229
//
22282230
// log.Fatalf("http status: %d, error: %s", status, err)
22292231
// }
2230-
func (c *Client) AddFavorite(site, customer string, filter FavoritesFilter, req AddFavoriteRequest) (
2232+
func (c *Client) AddFavorite(site, customer string, filter FavoritesFilter, req ChangeFavoritesRequest) (
22312233
SuccessfulResponse, int, error,
22322234
) {
22332235
var resp SuccessfulResponse
@@ -2265,10 +2267,12 @@ func (c *Client) AddFavorite(site, customer string, filter FavoritesFilter, req
22652267
// var client = retailcrm.New("https://demo.url", "09jIJ")
22662268
//
22672269
// data, status, err := client.RemoveFavorite("site_id", "customer_external_id", retailcrm.FavoritesFilter{SiteBy: "id", By: "externalId"},
2268-
// retailcrm.AddFavoriteRequest{
2269-
// ID: 1,
2270-
// ExternalID: "ext_id",
2271-
// XMLID: "xml_id",
2270+
// retailcrm.ChangeFavoritesRequest{
2271+
// Offer: retailcrm.SerializedRelationOffer{
2272+
// ID: 1,
2273+
// ExternalID: "ext_id",
2274+
// XMLID: "xml_id",
2275+
// },
22722276
// },
22732277
// )
22742278
//
@@ -2279,7 +2283,7 @@ func (c *Client) AddFavorite(site, customer string, filter FavoritesFilter, req
22792283
//
22802284
// log.Fatalf("http status: %d, error: %s", status, err)
22812285
// }
2282-
func (c *Client) RemoveFavorite(site, customer string, filter FavoritesFilter, req AddFavoriteRequest) (
2286+
func (c *Client) RemoveFavorite(site, customer string, filter FavoritesFilter, req ChangeFavoritesRequest) (
22832287
SuccessfulResponse, int, error,
22842288
) {
22852289
var resp SuccessfulResponse

client_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,10 +2194,12 @@ func TestClient_AddFavorite(t *testing.T) {
21942194
site := "site_id"
21952195
customer := "customer_id"
21962196
filter := FavoritesFilter{SiteBy: "id"}
2197-
request := AddFavoriteRequest{
2198-
ID: 1,
2199-
ExternalID: "ext_id",
2200-
XMLID: "xml_id",
2197+
request := ChangeFavoritesRequest{
2198+
Offer: SerializedRelationOffer{
2199+
ID: 1,
2200+
ExternalID: "ext_id",
2201+
XMLID: "xml_id",
2202+
},
22012203
}
22022204

22032205
defer gock.Off()
@@ -2212,12 +2214,12 @@ func TestClient_AddFavorite(t *testing.T) {
22122214
require.NoError(t, err)
22132215

22142216
data := val.Get("favorite")
2215-
var incoming AddFavoriteRequest
2217+
var incoming ChangeFavoritesRequest
22162218
require.NoError(t, json.Unmarshal([]byte(data), &incoming))
22172219

2218-
equal := assert.Equal(t, 1, incoming.ID) &&
2219-
assert.Equal(t, "ext_id", incoming.ExternalID) &&
2220-
assert.Equal(t, "xml_id", incoming.XMLID)
2220+
equal := assert.Equal(t, 1, incoming.Offer.ID) &&
2221+
assert.Equal(t, "ext_id", incoming.Offer.ExternalID) &&
2222+
assert.Equal(t, "xml_id", incoming.Offer.XMLID)
22212223

22222224
if !equal {
22232225
return false, errors.New("unequal values")
@@ -2249,10 +2251,12 @@ func TestClient_RemoveFavorite(t *testing.T) {
22492251
site := "site_id"
22502252
customer := "customer_id"
22512253
filter := FavoritesFilter{SiteBy: "id"}
2252-
request := AddFavoriteRequest{
2253-
ID: 1,
2254-
ExternalID: "ext_id",
2255-
XMLID: "xml_id",
2254+
request := ChangeFavoritesRequest{
2255+
Offer: SerializedRelationOffer{
2256+
ID: 1,
2257+
ExternalID: "ext_id",
2258+
XMLID: "xml_id",
2259+
},
22562260
}
22572261

22582262
defer gock.Off()
@@ -2267,12 +2271,12 @@ func TestClient_RemoveFavorite(t *testing.T) {
22672271
require.NoError(t, err)
22682272

22692273
data := val.Get("favorite")
2270-
var incoming AddFavoriteRequest
2274+
var incoming ChangeFavoritesRequest
22712275
require.NoError(t, json.Unmarshal([]byte(data), &incoming))
22722276

2273-
equal := assert.Equal(t, 1, incoming.ID) &&
2274-
assert.Equal(t, "ext_id", incoming.ExternalID) &&
2275-
assert.Equal(t, "xml_id", incoming.XMLID)
2277+
equal := assert.Equal(t, 1, incoming.Offer.ID) &&
2278+
assert.Equal(t, "ext_id", incoming.Offer.ExternalID) &&
2279+
assert.Equal(t, "xml_id", incoming.Offer.XMLID)
22762280

22772281
if !equal {
22782282
return false, errors.New("unequal values")

request.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,8 @@ type SetCartRequest struct {
210210
Items []SetCartItem `json:"items,omitempty"`
211211
}
212212

213-
type AddFavoriteRequest struct {
214-
ID int `json:"id,omitempty"`
215-
ExternalID string `json:"externalId,omitempty"`
216-
XMLID string `json:"xmlId,omitempty"`
213+
type ChangeFavoritesRequest struct {
214+
Offer SerializedRelationOffer `json:"offer"`
217215
}
218216

219217
// CostsRequest type.

types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,3 +1710,9 @@ type MGChannelTemplate struct {
17101710
MGChannelID int `json:"mgChannelId"`
17111711
Active bool `json:"active"`
17121712
}
1713+
1714+
type SerializedRelationOffer struct {
1715+
ID int `json:"id,omitempty"`
1716+
ExternalID string `json:"externalId,omitempty"`
1717+
XMLID string `json:"xmlId,omitempty"`
1718+
}

0 commit comments

Comments
 (0)