Skip to content

Commit 895ef8b

Browse files
authored
Change the data structure of chat response according to the updates from Ozon (#102)
1 parent ccd3610 commit 895ef8b

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

ozon/chats.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ListChatsResponse struct {
3939
core.CommonResponse
4040

4141
// Chats data
42-
Chats []ListChatsChat `json:"chats"`
42+
Chats []ListChatsChatData `json:"chats"`
4343

4444
// Total number of chats
4545
TotalChatsCount int64 `json:"total_chats_count"`
@@ -48,20 +48,6 @@ type ListChatsResponse struct {
4848
TotalUnreadCount int64 `json:"total_unread_count"`
4949
}
5050

51-
type ListChatsChat struct {
52-
// Chat data
53-
Chat ListChatsChatData `json:"chat"`
54-
55-
// Identifier of the first unread chat message
56-
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`
57-
58-
// Identifier of the last message in the chat
59-
LastMessageId uint64 `json:"last_message_id"`
60-
61-
// Number of unread messages in the chat
62-
UnreadCount int64 `json:"unread_count"`
63-
}
64-
6551
type ListChatsChatData struct {
6652
// Chat identifier
6753
ChatId string `json:"chat_id"`
@@ -79,6 +65,15 @@ type ListChatsChatData struct {
7965

8066
// Chat creation date
8167
CreatedAt time.Time `json:"created_at"`
68+
69+
// Identifier of the first unread chat message
70+
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`
71+
72+
// Identifier of the last message in the chat
73+
LastMessageId uint64 `json:"last_message_id"`
74+
75+
// Number of unread messages in the chat
76+
UnreadCount int64 `json:"unread_count"`
8277
}
8378

8479
// Returns information about chats by specified filters

ozon/chats_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ func TestListChats(t *testing.T) {
3232
`{
3333
"chats": [
3434
{
35-
"chat": {
36-
"created_at": "2022-07-22T08:07:19.581Z",
37-
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
38-
"chat_status": "Opened",
39-
"chat_type": "Seller_Support"
40-
},
41-
"first_unread_message_id": 3000000000118021931,
42-
"last_message_id": 3000000000128004274,
43-
"unread_count": 1
35+
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
36+
"chat_status": "Opened",
37+
"chat_type": "Seller_Support",
38+
"created_at": "2022-07-22T08:07:19.581Z",
39+
"unread_count": 1,
40+
"last_message_id": 3000000000128004274,
41+
"first_unread_message_id": 3000000000118021931
4442
}
4543
],
4644
"total_chats_count": 25,
@@ -77,10 +75,10 @@ func TestListChats(t *testing.T) {
7775

7876
if resp.StatusCode == http.StatusOK {
7977
if len(resp.Chats) > 0 {
80-
if resp.Chats[0].Chat.ChatStatus == "" {
78+
if resp.Chats[0].ChatStatus == "" {
8179
t.Errorf("Chat status cannot be empty")
8280
}
83-
if resp.Chats[0].Chat.ChatType == "" {
81+
if resp.Chats[0].ChatType == "" {
8482
t.Errorf("Chat type cannot be empty")
8583
}
8684
}

0 commit comments

Comments
 (0)