-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmenu.go
More file actions
61 lines (55 loc) · 2.22 KB
/
Copy pathmenu.go
File metadata and controls
61 lines (55 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package goiikoapi
import (
"context"
"encoding/json"
)
// Menu содержит методы для работы с меню
type Menu struct {
client *Client
}
// Проверяем, что Menu реализует IMenu
var _ IMenu = (*Menu)(nil)
// Nomenclature реплицирует Menu.nomenclature
func (m *Menu) Nomenclature(ctx context.Context, organizationID string, startRevision *int) (*BaseNomenclatureModel, *CustomErrorModel, error) {
data := map[string]any{"organizationId": organizationID}
if startRevision != nil {
data["startRevision"] = *startRevision
}
body, status, err := m.client.post(ctx, "/api/1/nomenclature", data)
if err != nil { return nil, nil, err }
if msg, ok := DetectAPIError(body); ok {
return nil, &CustomErrorModel{ErrorModel: ErrorModel{ErrorDescription: msg}, StatusCode: status}, nil
}
var out BaseNomenclatureModel
if err := json.Unmarshal(body, &out); err != nil { return nil, nil, err }
return &out, nil, nil
}
// Menu реплицирует Menu.menu
func (m *Menu) Menu(ctx context.Context) (*BaseMenuModel, *CustomErrorModel, error) {
body, status, err := m.client.post(ctx, "/api/2/menu", map[string]any{})
if err != nil { return nil, nil, err }
if msg, ok := DetectAPIError(body); ok {
return nil, &CustomErrorModel{ErrorModel: ErrorModel{ErrorDescription: msg}, StatusCode: status}, nil
}
var out BaseMenuModel
if err := json.Unmarshal(body, &out); err != nil { return nil, nil, err }
return &out, nil, nil
}
// MenuByID реплицирует Menu.menu_by_id
func (m *Menu) MenuByID(ctx context.Context, externalMenuID string, organizationIDs []string, priceCategoryID *string) (*BaseMenuByIdModel, *CustomErrorModel, error) {
data := map[string]any{
"externalMenuId": externalMenuID,
"organizationIds": organizationIDs,
}
if priceCategoryID != nil {
data["priceCategoryId"] = *priceCategoryID
}
body, status, err := m.client.post(ctx, "/api/2/menu/by_id", data)
if err != nil { return nil, nil, err }
if msg, ok := DetectAPIError(body); ok {
return nil, &CustomErrorModel{ErrorModel: ErrorModel{ErrorDescription: msg}, StatusCode: status}, nil
}
var out BaseMenuByIdModel
if err := json.Unmarshal(body, &out); err != nil { return nil, nil, err }
return &out, nil, nil
}