Skip to content

Commit

Permalink
update(tasks) added new models
Browse files Browse the repository at this point in the history
  • Loading branch information
joaolpinho committed Aug 29, 2016
1 parent b67ede2 commit 1048ff0
Show file tree
Hide file tree
Showing 18 changed files with 395 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
10 changes: 10 additions & 0 deletions catalog/models/attribute_product.go
Original file line number Diff line number Diff line change
@@ -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"`
}
8 changes: 8 additions & 0 deletions catalog/models/group_item.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

type GroupItem struct{
GroupId string `json:"groupId"`
StoreId string `json:"storeId"`
Products []string `json:"products"`
}

11 changes: 11 additions & 0 deletions catalog/models/hierarchy_category.go
Original file line number Diff line number Diff line change
@@ -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"`
}
37 changes: 37 additions & 0 deletions catalog/models/product.go
Original file line number Diff line number Diff line change
@@ -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"`
}
10 changes: 10 additions & 0 deletions catalog/models/product_attribute.go
Original file line number Diff line number Diff line change
@@ -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"`
}
11 changes: 11 additions & 0 deletions catalog/models/product_store.go
Original file line number Diff line number Diff line change
@@ -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"`
}
27 changes: 27 additions & 0 deletions catalog/models/promotion_item.go
Original file line number Diff line number Diff line change
@@ -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"`
}
7 changes: 7 additions & 0 deletions catalog/models/scan_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package models

type ScanCode struct{
Ean string `json:"ean"`
Primary string `json:"primary"`
Type string `json:"type"`
}
110 changes: 0 additions & 110 deletions task.go

This file was deleted.

37 changes: 32 additions & 5 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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)))

Expand All @@ -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)
}
Expand Down
36 changes: 36 additions & 0 deletions tasks/models/checklist_task_item.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 1048ff0

Please sign in to comment.