diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/catalog/models/attribute_product.go b/catalog/models/attribute_product.go new file mode 100644 index 0000000..64bb402 --- /dev/null +++ b/catalog/models/attribute_product.go @@ -0,0 +1,10 @@ +package models + +type AttributeProduct struct{ + Code string `json:"code"` + Value string `json:"value"` + Value_pt string `json:"value_pt"` + Value_en string `json:"value_en"` + Value_br string `json:"value_br"` + Value_es string `json:"value_es"` +} diff --git a/catalog/models/group_item.go b/catalog/models/group_item.go new file mode 100644 index 0000000..e720202 --- /dev/null +++ b/catalog/models/group_item.go @@ -0,0 +1,8 @@ +package models + +type GroupItem struct{ + GroupId string `json:"groupId"` + StoreId string `json:"storeId"` + Products []string `json:"products"` +} + diff --git a/catalog/models/hierarchy_category.go b/catalog/models/hierarchy_category.go new file mode 100644 index 0000000..09a5602 --- /dev/null +++ b/catalog/models/hierarchy_category.go @@ -0,0 +1,11 @@ +package models + +type HierarchyCategory struct { + LevelRoot string `json:"levelRoot"` + LevelOne string `json:"levelOne"` + LevelTwo string `json:"levelTwo"` + LevelThree string `json:"levelThree"` + LevelFour string `json:"levelFour"` + LevelFive string `json:"levelFive"` + LevelSix string `json:"levelSix"` +} \ No newline at end of file diff --git a/catalog/models/product.go b/catalog/models/product.go new file mode 100644 index 0000000..f9d8cfb --- /dev/null +++ b/catalog/models/product.go @@ -0,0 +1,37 @@ +package models + + +type Product struct { + + Id string `json:"_id"` + Name string `json:"name"` + Name_pt string `json:"name_pt"` + Name_en string `json:"name_en"` + Name_br string `json:"name_br"` + Name_es string `json:"name_es"` + Desc string `json:"desc"` + Desc_pt string `json:"desc_pt"` + Desc_en string `json:"desc_en"` + Desc_br string `json:"desc_br"` + Desc_es string `json:"desc_es"` + LongDesc string `json:"longDesc"` + LongDesc_pt string `json:"longDesc_pt"` + LongDesc_en string `json:"longDesc_en"` + LongDesc_br string `json:"longDesc_br"` + LongDesc_es string `json:"longDesc_es"` + Status string `json:"status"` + SupplierId string `json:"supplierId"` + Brand string `json:"brand"` + Brand_pt string `json:"brand_pt"` + Brand_en string `json:"brand_en"` + Brand_br string `json:"brand_br"` + Brand_es string `json:"brand_es"` + CategoryId string `json:"categoryId"` + MediaId []string `json:"mediaId"` + HierarchyCategory HierarchyCategory `json:"hierarchyCategory"` + Attributes []ProductAttribute `json:"attributes"` + Stores []ProductStore `json:"stores"` + ScanCodes []ScanCode `json:"scanCodes"` + Promotions []PromotionItem `json:"promotions"` + Groups []GroupItem `json:"groups"` +} \ No newline at end of file diff --git a/catalog/models/product_attribute.go b/catalog/models/product_attribute.go new file mode 100644 index 0000000..d7d56b0 --- /dev/null +++ b/catalog/models/product_attribute.go @@ -0,0 +1,10 @@ +package models + +type ProductAttribute struct{ + Code string `json:"code"` + Value string `json:"value"` + Value_pt string `json:"value_pt"` + Value_en string `json:"value_en"` + Value_br string `json:"value_br"` + Value_es string `json:"value_es"` +} diff --git a/catalog/models/product_store.go b/catalog/models/product_store.go new file mode 100644 index 0000000..7f0bd23 --- /dev/null +++ b/catalog/models/product_store.go @@ -0,0 +1,11 @@ +package models + +type ProductStore struct{ + StoreId string `json:"storeId"` + OldPrice float64 `json:"oldPrice"` + SellPrice float64 `json:"sellPrice"` + Discontinued bool `json:"discontinued"` + Attributes []ProductAttribute `json:"attributes"` + Status string `json:"status"` + StockOnHand float64 `json:"stockOnHand"` +} \ No newline at end of file diff --git a/catalog/models/promotion_item.go b/catalog/models/promotion_item.go new file mode 100644 index 0000000..c8976e9 --- /dev/null +++ b/catalog/models/promotion_item.go @@ -0,0 +1,27 @@ +package models + +import "time" + +type PromotionItem struct{ + Type string `json:"type"` + GroupId string `json:"groupId"` + StoreId string `json:"storeId"` + StartDate time.Time `json:"startDate"` + EndDate time.Time `json:"endDate"` + Desc string `json:"desc"` + Desc_pt string `json:"desc_pt"` + Desc_en string `json:"desc_en"` + Desc_br string `json:"desc_br"` + Desc_es string `json:"desc_es"` + Desc2 string `json:"desc2"` + Desc2_pt string `json:"desc2_pt"` + Desc2_en string `json:"desc2_en"` + Desc2_br string `json:"desc2_br"` + Desc2_es string `json:"desc2_es"` + Desc3 string `json:"desc3"` + Desc3_pt string `json:"desc3_pt"` + Desc3_en string `json:"desc3_en"` + Desc3_br string `json:"desc3_br"` + Desc3_es string `json:"desc3_es"` + Price float64 `json:"price"` +} \ No newline at end of file diff --git a/catalog/models/scan_code.go b/catalog/models/scan_code.go new file mode 100644 index 0000000..52ff82f --- /dev/null +++ b/catalog/models/scan_code.go @@ -0,0 +1,7 @@ +package models + +type ScanCode struct{ + Ean string `json:"ean"` + Primary string `json:"primary"` + Type string `json:"type"` +} \ No newline at end of file diff --git a/task.go b/task.go deleted file mode 100644 index 682e78d..0000000 --- a/task.go +++ /dev/null @@ -1,110 +0,0 @@ -package mrs_service_go_sdk - -type TaskSummary struct { - Status string `json:"status"` - Result struct { - PriceAudit struct { - Total int `json:"total"` - } `json:"priceAudit"` - StockCount struct { - Total int `json:"total"` - } `json:"stockCount"` - StockOut struct { - Total int `json:"total"` - } `json:"stockOut"` - Replenish struct { - Total int `json:"total"` - } `json:"replenish"` - QueueBust struct { - Total int `json:"total"` - } `json:"queueBust"` - Checklist struct { - Total int `json:"total"` - } `json:"checklist"` - Shrinkage struct { - Total int `json:"total"` - } `json:"shrinkage"` - Planogram struct { - Total int `json:"total"` - } `json:"planogram"` - Markdown struct { - Total int `json:"total"` - } `json:"markdown"` - QualClas struct { - Total int `json:"total"` - } `json:"qualClas"` - RecepDir struct { - Total int `json:"total"` - } `json:"recepDir"` - RecepCen struct { - Total int `json:"total"` - } `json:"recepCen"` - RecepTsf struct { - Total int `json:"total"` - } `json:"recepTsf"` - PriceChang struct { - Total int `json:"total"` - } `json:"priceChang"` - RecepCS struct { - Total int `json:"total"` - } `json:"recepCS"` - ReplenPrep struct { - Total int `json:"total"` - } `json:"replenPrep"` - ReplenConf struct { - Total int `json:"total"` - } `json:"replenConf"` - StockOutFA struct { - Total int `json:"total"` - } `json:"stockOutFA"` - } `json:"result"` -} - -type TasksRequest struct { - Status string `json:"status"` - Result []Task `json:"result"` -} - - -type Task struct { - Status string `json:"status"` - OwnerID string `json:"ownerId"` - LastUpdateUser string `json:"lastUpdateUser"` - TaskType string `json:"taskType"` - Counter int `json:"counter"` - SetupID string `json:"setupId"` - TaskName string `json:"taskName"` - Description string `json:"description"` - ProfileID string `json:"profileId"` - DeviceID string `json:"deviceId"` - StoreID string `json:"storeId"` - Priority int `json:"priority"` - Shared bool `json:"shared"` - DocumentID string `json:"documentId"` - ScheduledDate int64 `json:"scheduledDate"` - ApplicationID string `json:"applicationId"` - Type string `json:"_type"` - UID string `json:"_uId"` - UpdateDate int `json:"_updateDate"` - CreateDate int `json:"_createDate"` - UpdateUser string `json:"_updateUser"` - CreateUser string `json:"_createUser"` - Items []TaskItem `json:"items"` -} - - - -type TaskItem struct { - ItemID string `json:"itemId"` - Status string `json:"status"` - TaskID string `json:"taskId"` - Type string `json:"type,omitempty"` - ApplicationID string `json:"applicationId"` - _Type string `json:"_type"` - UID string `json:"_uId"` - UpdateDate int `json:"_updateDate"` - CreateDate int `json:"_createDate"` - UpdateUser string `json:"_updateUser,omitempty"` - CreateUser string `json:"_createUser,omitempty"` - ItemEan string `json:"itemEan,omitempty"` -} \ No newline at end of file diff --git a/tasks.go b/tasks.go index 4ab5618..f093faa 100644 --- a/tasks.go +++ b/tasks.go @@ -4,12 +4,15 @@ package mrs_service_go_sdk import ( "net/http" "fmt" + + "github.com/Tlantic/mrs-service-go-sdk/tasks/models" ) const TASKS_MODULE_NAME = "tasks" -func (c *Client) Summary() (*TaskSummary, error) { - p := TaskSummary{} +// Retrieves a task summary +func (c *Client) Summary() (*models.TaskSummary, error) { + p := models.TaskSummary{} url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application,"summary")) @@ -29,9 +32,11 @@ func (c *Client) Summary() (*TaskSummary, error) { return &p, nil } - -func (c *Client) GetTasks(items bool) (*TasksRequest, error) { - p := TasksRequest{} +// GetTasks retrieves all available tasks. +// +// Whe items is true, it also retrieves its items. +func (c *Client) GetTasks(items bool) (*models.TasksRequest, error) { + p := models.TasksRequest{} url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, fmt.Sprintf("?items=%t", items))) @@ -51,6 +56,28 @@ func (c *Client) GetTasks(items bool) (*TasksRequest, error) { return &p, nil } +// Create a task and its items. +func (c *Client) CreateTask( task *models.Task ) (*models.TasksRequest, error) { + p := models.TasksRequest{} + + url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, "")) + + req, err := http.NewRequest("POST", url , nil) + req.Header.Set("mrs-application-id", c.AppId) + + if err != nil { + return &p, err + } + + err = c.Send(req, &p) + if err != nil { + return &p, err + } + + + return &p, nil +} + func createPath(org, app, extra string) string{ return fmt.Sprintf("%s/orgs/%s/apps/%s/%s/%s", TASKS_MODULE_NAME, org, app, TASKS_MODULE_NAME, extra) } diff --git a/tasks/models/checklist_task_item.go b/tasks/models/checklist_task_item.go new file mode 100644 index 0000000..a267082 --- /dev/null +++ b/tasks/models/checklist_task_item.go @@ -0,0 +1,36 @@ +package models + +type ChecklistTaskItem_v1 struct { + + UniqueId string `json:"_uId"` + ApplicationId string `json:"applicationId"` + TaskId string `json:"taskId"` + Type string `json:"type"` + Status string `json:"status"` + Observation string `json:"observation"` + StartDate int `json:"startDate"` + + + ItemId string `json:"itemId"` +} + + +func ( item *ChecklistTaskItem_v1 ) GetUniqueId() string { + return item.UniqueId +} + +func ( item *ChecklistTaskItem_v1 ) GetItemId() string { + return item.ItemId +} + +func ( item *ChecklistTaskItem_v1 ) GetType() string { + return item.Type +} + +func ( item *ChecklistTaskItem_v1 ) GetStatus() string { + return item.Status +} + +func ( item *ChecklistTaskItem_v1 ) GetStartDate() int { + return item.StartDate +} diff --git a/tasks/models/product_task_item.go b/tasks/models/product_task_item.go new file mode 100644 index 0000000..8e66673 --- /dev/null +++ b/tasks/models/product_task_item.go @@ -0,0 +1,69 @@ +package models + +import "github.com/Tlantic/mrs-service-go-sdk/catalog/models" + +type ProductTaskItem_v1 struct { + + UniqueId string `json:"_uId"` + ApplicationId string `json:"applicationId"` + TaskId string `json:"taskId"` + Type string `json:"type"` + Status string `json:"status"` + Observation string `json:"observation"` + StartDate int `json:"startDate"` + + + + ItemId string `json:"itemId"` + ItemEAN string `json:"itemEAN"` + ItemName string `json:"itemName"` + ExpirationDate int `json:"expirationDate"` + HierarchyCategory models.HierarchyCategory `json:"hierarchyCategory"` + + + PosPrice int `json:"posPrice"` + LabelPrice int `json:"labelPrice"` + OldERPPrice int `json:"oldERPPrice"` + PriceDivergence bool `json:"priceDivergence"` + + + Quantity int `json:"quantity"` + ExpectedQuantity int `json:"expectedQuantity"` + + CheckExpirationDate bool `json:"checkExpirationDate"` + + PickCount int `json:"pickCount"` + FirstPickingTime int `json:"firstPickingTime"` + ReceptionUnit int `json:"receptionUnit"` + ReceptionUnitQuantity int `json:"receptionUnitQuantity"` + +} + + +func ( item *ProductTaskItem_v1 ) GetUniqueId() string { + return item.UniqueId +} + +func ( item *ProductTaskItem_v1 ) GetItemId() string { + return item.ItemId +} + +func ( item *ProductTaskItem_v1 ) GetItemEAN() string { + return item.ItemEAN +} + +func ( item *ProductTaskItem_v1 ) GetName() string { + return item.ItemEAN +} + +func ( item *ProductTaskItem_v1 ) GetType( ) string { + return item.Type +} + +func ( item *ProductTaskItem_v1 ) GetStatus() string { + return item.Status +} + +func ( item *ProductTaskItem_v1 ) GetStartDate() int { + return item.StartDate +} diff --git a/tasks/models/request.go b/tasks/models/request.go new file mode 100644 index 0000000..c9d7f75 --- /dev/null +++ b/tasks/models/request.go @@ -0,0 +1,6 @@ +package models + +type TasksRequest struct { + Status string `json:"status"` + Result []Task `json:"result"` +} \ No newline at end of file diff --git a/tasks/models/task.go b/tasks/models/task.go new file mode 100644 index 0000000..1491e73 --- /dev/null +++ b/tasks/models/task.go @@ -0,0 +1,31 @@ +package models + +type Task struct { + UID string `json:"_uId"` + ParentTaskId string `json:"parentTaskId"` + TaskName string `json:"taskName"` + TaskType string `json:"taskType"` + TaskSubType string `json:"taskSubType"` + Items []TaskItem `json:"items"` + Description string `json:"description"` + ProfileID string `json:"profileId"` + DeviceID string `json:"deviceId"` + Status string `json:"status"` + OwnerID string `json:"ownerId"` + LastUpdateUser string `json:"lastUpdateUser"` + Counter int `json:"counter"` + SetupID string `json:"setupId"` + StoreID string `json:"storeId"` + Priority int `json:"priority"` + Shared bool `json:"shared"` + DocumentID string `json:"documentId"` + ScheduledDate int64 `json:"scheduledDate"` + + ApplicationID string `json:"applicationId"` + Type string `json:"_type"` + UpdateDate int `json:"_updateDate"` + CreateDate int `json:"_createDate"` + UpdateUser string `json:"_updateUser"` + CreateUser string `json:"_createUser"` + +} \ No newline at end of file diff --git a/tasks/models/task_item.go b/tasks/models/task_item.go new file mode 100644 index 0000000..41774b7 --- /dev/null +++ b/tasks/models/task_item.go @@ -0,0 +1,10 @@ +package models + +type TaskItem interface { + GetUniqueId() string + GetItemId() string + GetName() string + GetType() string + GetStatus() string + GetStartDate() int +} \ No newline at end of file diff --git a/tasks/models/task_summary.go b/tasks/models/task_summary.go new file mode 100644 index 0000000..274f83b --- /dev/null +++ b/tasks/models/task_summary.go @@ -0,0 +1,62 @@ +package models + + +type TaskSummary struct { + Status string `json:"status"` + Result struct { + PriceAudit struct { + Total int `json:"total"` + } `json:"priceAudit"` + StockCount struct { + Total int `json:"total"` + } `json:"stockCount"` + StockOut struct { + Total int `json:"total"` + } `json:"stockOut"` + Replenish struct { + Total int `json:"total"` + } `json:"replenish"` + QueueBust struct { + Total int `json:"total"` + } `json:"queueBust"` + Checklist struct { + Total int `json:"total"` + } `json:"checklist"` + Shrinkage struct { + Total int `json:"total"` + } `json:"shrinkage"` + Planogram struct { + Total int `json:"total"` + } `json:"planogram"` + Markdown struct { + Total int `json:"total"` + } `json:"markdown"` + QualClas struct { + Total int `json:"total"` + } `json:"qualClas"` + RecepDir struct { + Total int `json:"total"` + } `json:"recepDir"` + RecepCen struct { + Total int `json:"total"` + } `json:"recepCen"` + RecepTsf struct { + Total int `json:"total"` + } `json:"recepTsf"` + PriceChang struct { + Total int `json:"total"` + } `json:"priceChang"` + RecepCS struct { + Total int `json:"total"` + } `json:"recepCS"` + ReplenPrep struct { + Total int `json:"total"` + } `json:"replenPrep"` + ReplenConf struct { + Total int `json:"total"` + } `json:"replenConf"` + StockOutFA struct { + Total int `json:"total"` + } `json:"stockOutFA"` + } `json:"result"` +} \ No newline at end of file diff --git a/tasks_test.go b/tasks_test.go index 2ab74e3..dd6a112 100644 --- a/tasks_test.go +++ b/tasks_test.go @@ -2,6 +2,7 @@ package mrs_service_go_sdk import ( "testing" + "github.com/Tlantic/mrs-service-go-sdk/tasks/models" ) @@ -48,3 +49,29 @@ func TestGetTasks(t *testing.T) { } + +func TestCreateTask(t *testing.T) { + + cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707") + if err != nil { + t.Errorf( err.Error()) + } + + tasks, err := cl.CreateTask(&models.Task{ + + }) + + if err != nil{ + t.Errorf( err.Error()) + } + + t.Log(tasks.Result) + + if(len(tasks.Result)>0){ + task := tasks.Result[0] + t.Log(task.TaskName) + t.Log(task.Items) + } + + +}