Skip to content

Commit

Permalink
feat<GetTaskById>: Added method to retrieve task by Id
Browse files Browse the repository at this point in the history
  • Loading branch information
manujvieira committed Aug 30, 2016
1 parent 1048ff0 commit 17dfaad
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 53 deletions.
43 changes: 33 additions & 10 deletions tasks.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package mrs_service_go_sdk


import (
"net/http"
"fmt"

"github.com/Tlantic/mrs-service-go-sdk/tasks/models"
)

const TASKS_MODULE_NAME = "tasks"
const TASKS_MODULE_NAME = "tasks"

// 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"))
url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, "summary"))

req, err := http.NewRequest("GET", url , nil)
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("mrs-application-id", c.AppId)

if err != nil {
Expand All @@ -28,7 +27,6 @@ func (c *Client) Summary() (*models.TaskSummary, error) {
return &p, err
}


return &p, nil
}

Expand All @@ -40,7 +38,7 @@ func (c *Client) GetTasks(items bool) (*models.TasksRequest, error) {

url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, fmt.Sprintf("?items=%t", items)))

req, err := http.NewRequest("GET", url , nil)
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("mrs-application-id", c.AppId)

if err != nil {
Expand All @@ -52,17 +50,43 @@ func (c *Client) GetTasks(items bool) (*models.TasksRequest, error) {
return &p, err
}

return &p, nil
}

func (c *Client) GetTaskById(taskUId string, items bool) (*models.TaskRequest, error) {
p := models.TaskRequest{}

url := fmt.Sprintf("%s/%s", c.BaseApi, createPath(c.Organization, c.Application, fmt.Sprintf("%s?items=%t", taskUId, items)))

fmt.Print(url)

req, err := http.NewRequest("GET", 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
}

if (p.Result.TaskType == "checklist") {
p.Result.ItemType = models.ChecklistTaskItem{}
} else {
p.Result.ItemType = models.ProductTaskItem{}
}
return &p, nil
}

// Create a task and its items.
func (c *Client) CreateTask( task *models.Task ) (*models.TasksRequest, error) {
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, err := http.NewRequest("POST", url, nil)
req.Header.Set("mrs-application-id", c.AppId)

if err != nil {
Expand All @@ -74,11 +98,10 @@ func (c *Client) CreateTask( task *models.Task ) (*models.TasksRequest, error) {
return &p, err
}


return &p, nil
}

func createPath(org, app, extra string) string{
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)
}

12 changes: 6 additions & 6 deletions tasks/models/checklist_task_item.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package models

type ChecklistTaskItem_v1 struct {
type ChecklistTaskItem struct {

UniqueId string `json:"_uId"`
ApplicationId string `json:"applicationId"`
Expand All @@ -15,22 +15,22 @@ type ChecklistTaskItem_v1 struct {
}


func ( item *ChecklistTaskItem_v1 ) GetUniqueId() string {
func ( item *ChecklistTaskItem ) GetUniqueId() string {
return item.UniqueId
}

func ( item *ChecklistTaskItem_v1 ) GetItemId() string {
func ( item *ChecklistTaskItem ) GetItemId() string {
return item.ItemId
}

func ( item *ChecklistTaskItem_v1 ) GetType() string {
func ( item *ChecklistTaskItem ) GetType() string {
return item.Type
}

func ( item *ChecklistTaskItem_v1 ) GetStatus() string {
func ( item *ChecklistTaskItem ) GetStatus() string {
return item.Status
}

func ( item *ChecklistTaskItem_v1 ) GetStartDate() int {
func ( item *ChecklistTaskItem ) GetStartDate() int {
return item.StartDate
}
18 changes: 9 additions & 9 deletions tasks/models/product_task_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package models

import "github.com/Tlantic/mrs-service-go-sdk/catalog/models"

type ProductTaskItem_v1 struct {
type ProductTaskItem struct {

UniqueId string `json:"_uId"`
ApplicationId string `json:"applicationId"`
Expand Down Expand Up @@ -40,30 +40,30 @@ type ProductTaskItem_v1 struct {
}


func ( item *ProductTaskItem_v1 ) GetUniqueId() string {
return item.UniqueId
func ( item *ProductTaskItem ) GetUniqueId() string {
return item.UniqueId
}

func ( item *ProductTaskItem_v1 ) GetItemId() string {
func ( item *ProductTaskItem ) GetItemId() string {
return item.ItemId
}

func ( item *ProductTaskItem_v1 ) GetItemEAN() string {
func ( item *ProductTaskItem ) GetItemEAN() string {
return item.ItemEAN
}

func ( item *ProductTaskItem_v1 ) GetName() string {
func ( item *ProductTaskItem ) GetName() string {
return item.ItemEAN
}

func ( item *ProductTaskItem_v1 ) GetType( ) string {
func ( item *ProductTaskItem ) GetType( ) string {
return item.Type
}

func ( item *ProductTaskItem_v1 ) GetStatus() string {
func ( item *ProductTaskItem ) GetStatus() string {
return item.Status
}

func ( item *ProductTaskItem_v1 ) GetStartDate() int {
func ( item *ProductTaskItem ) GetStartDate() int {
return item.StartDate
}
5 changes: 5 additions & 0 deletions tasks/models/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ package models
type TasksRequest struct {
Status string `json:"status"`
Result []Task `json:"result"`
}

type TaskRequest struct {
Status string `json:"status"`
Result Task `json:"result"`
}
2 changes: 1 addition & 1 deletion tasks/models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ type Task struct {
CreateDate int `json:"_createDate"`
UpdateUser string `json:"_updateUser"`
CreateUser string `json:"_createUser"`

ItemType interface{} `json:"itemType"`
}
69 changes: 61 additions & 8 deletions tasks/models/task_item.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
package models

type TaskItem interface {
GetUniqueId() string
GetItemId() string
GetName() string
GetType() string
GetStatus() string
GetStartDate() int
}
import "github.com/Tlantic/mrs-service-go-sdk/catalog/models"

type TaskItem 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 *TaskItem ) GetUniqueId() string {
return item.UniqueId
}

func ( item *TaskItem ) GetItemId() string {
return item.ItemId
}

func ( item *TaskItem ) GetItemEAN() string {
return item.ItemEAN
}

func ( item *TaskItem ) GetName() string {
return item.ItemEAN
}

func ( item *TaskItem ) GetType() string {
return item.Type
}

func ( item *TaskItem ) GetStatus() string {
return item.Status
}

func ( item *TaskItem ) GetStartDate() int {
return item.StartDate
}

58 changes: 39 additions & 19 deletions tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,93 @@ import (
"github.com/Tlantic/mrs-service-go-sdk/tasks/models"
)


func TestTaskSummary(t *testing.T) {

cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
cl, err := NewClient("http://52.50.91.27:8067", "tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
if err != nil {
t.Errorf( err.Error())
t.Errorf(err.Error())
}

summary, err := cl.Summary()

if err != nil{
t.Errorf( err.Error())
if err != nil {
t.Errorf(err.Error())
}

t.Log(summary.Result.PriceChang.Total)


}


func TestGetTasks(t *testing.T) {

cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
cl, err := NewClient("http://52.50.91.27:8067", "tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
if err != nil {
t.Errorf( err.Error())
t.Errorf(err.Error())
}

tasks, err := cl.GetTasks(true)

if err != nil{
t.Errorf( err.Error())
if err != nil {
t.Errorf(err.Error())
}

t.Log(tasks.Result)

if(len(tasks.Result)>0){
if (len(tasks.Result) > 0) {
task := tasks.Result[0]
t.Log(task.TaskName)
t.Log(task.Items)
}


}

func TestGetTaskById(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.GetTaskById("589f3517-0c98-4071-9fea-ab3e91dbe7ec", true)

if err != nil {
t.Errorf(err.Error())
}

t.Log(tasks.Result)

task := tasks.Result
t.Log(task.TaskName)
t.Log(task.Items)

for _, item := range task.Items {
t.Log(models.ProductTaskItem(item))
}

t.Log(task.Items)
}

func TestCreateTask(t *testing.T) {

cl, err := NewClient("http://52.50.91.27:8067","tlantic", "instore", "489a598e-259c-4e25-974e-5de00b29f707")
cl, err := NewClient("http://52.50.91.27", "tlantic", "instore", "")
if err != nil {
t.Errorf( err.Error())
t.Errorf(err.Error())
}

tasks, err := cl.CreateTask(&models.Task{

})

if err != nil{
t.Errorf( err.Error())
if err != nil {
t.Errorf(err.Error())
}

t.Log(tasks.Result)

if(len(tasks.Result)>0){
if (len(tasks.Result) > 0) {
task := tasks.Result[0]
t.Log(task.TaskName)
t.Log(task.Items)
}


}

0 comments on commit 17dfaad

Please sign in to comment.