Skip to content
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

Change the data structure of chat response according to the updates from Ozon #102

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions ozon/chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ListChatsResponse struct {
core.CommonResponse

// Chats data
Chats []ListChatsChat `json:"chats"`
Chats []ListChatsChatData `json:"chats"`

// Total number of chats
TotalChatsCount int64 `json:"total_chats_count"`
Expand All @@ -48,20 +48,6 @@ type ListChatsResponse struct {
TotalUnreadCount int64 `json:"total_unread_count"`
}

type ListChatsChat struct {
// Chat data
Chat ListChatsChatData `json:"chat"`

// Identifier of the first unread chat message
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`

// Identifier of the last message in the chat
LastMessageId uint64 `json:"last_message_id"`

// Number of unread messages in the chat
UnreadCount int64 `json:"unread_count"`
}

type ListChatsChatData struct {
// Chat identifier
ChatId string `json:"chat_id"`
Expand All @@ -79,6 +65,15 @@ type ListChatsChatData struct {

// Chat creation date
CreatedAt time.Time `json:"created_at"`

// Identifier of the first unread chat message
FirstUnreadMessageId uint64 `json:"first_unread_message_id"`

// Identifier of the last message in the chat
LastMessageId uint64 `json:"last_message_id"`

// Number of unread messages in the chat
UnreadCount int64 `json:"unread_count"`
}

// Returns information about chats by specified filters
Expand Down
20 changes: 9 additions & 11 deletions ozon/chats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ func TestListChats(t *testing.T) {
`{
"chats": [
{
"chat": {
"created_at": "2022-07-22T08:07:19.581Z",
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
"chat_status": "Opened",
"chat_type": "Seller_Support"
},
"first_unread_message_id": 3000000000118021931,
"last_message_id": 3000000000128004274,
"unread_count": 1
"chat_id": "5e767w03-b400-4y1b-a841-75319ca8a5c8",
"chat_status": "Opened",
"chat_type": "Seller_Support",
"created_at": "2022-07-22T08:07:19.581Z",
"unread_count": 1,
"last_message_id": 3000000000128004274,
"first_unread_message_id": 3000000000118021931
}
],
"total_chats_count": 25,
Expand Down Expand Up @@ -77,10 +75,10 @@ func TestListChats(t *testing.T) {

if resp.StatusCode == http.StatusOK {
if len(resp.Chats) > 0 {
if resp.Chats[0].Chat.ChatStatus == "" {
if resp.Chats[0].ChatStatus == "" {
t.Errorf("Chat status cannot be empty")
}
if resp.Chats[0].Chat.ChatType == "" {
if resp.Chats[0].ChatType == "" {
t.Errorf("Chat type cannot be empty")
}
}
Expand Down
Loading