Skip to content

Commit

Permalink
get events implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Dysar committed Aug 18, 2020
1 parent 15a3699 commit 68aec69
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
1 change: 1 addition & 0 deletions pkg/api/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ const (
logProcessingOfCustomerDataMethod = "logProcessingOfCustomerData"
createInstallationMethod = "createInstallation"
SaveEventMethod = "saveEvent"
GetEvents = "getEvents"
)
54 changes: 47 additions & 7 deletions pkg/api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,54 @@ type Country struct {
Added uint64 `json:"added"`
}

type Event struct {
EventID string `json:"eventID"`
ID string `json:"id"`
Description string `json:"description"`
TypeID string `json:"typeID"`
StartTime string `json:"startTime"`
EndTime string `json:"endTime"`
CustomerID string `json:"customerID"`
ContactID string `json:"contactID"`
ProjectID string `json:"projectID"`
EmployeeID string `json:"employeeID"`
SubmitterID string `json:"submitterID"`
SupplierID string `json:"supplierID"`
SupplierName string `json:"supplierName"`
StatusID string `json:"statusID"`
ResourceID string `json:"resourceID"`
Notes string `json:"notes"`
LastModified string `json:"lastModified"`
ContactName string `json:"contactName"`
CustomerName string `json:"customerName"`
EmployeeName string `json:"employeeName"`
SubmitterName string `json:"submitterName"`
ProjectName string `json:"projectName"`
ResourceName string `json:"resourceName"`
StatusName string `json:"statusName"`
TypeName string `json:"typeName"`
Completed string `json:"completed"`
}

type GetEventsResponse struct {
Status sharedCommon.Status `json:"status"`
Events []Event `json:"records"`
}

type SaveEventResponse struct {
Status sharedCommon.Status
Records []struct {
EventID int `json:"eventID"`
} `json:"records"`
}
type Employee struct {
EmployeeID string `json:"employeeID"`
FullName string `json:"fullName"`
EmployeeName string `json:"employeeName"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Phone string `json:"phone"`
Mobile string `json:"mobile"`
EmployeeID string `json:"employeeID"`
FullName string `json:"fullName"`
EmployeeName string `json:"employeeName"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Phone string `json:"phone"`
Mobile string `json:"mobile"`
Email string `json:"email"`
Fax string `json:"fax"`
Code string `json:"code"`
Expand Down
23 changes: 17 additions & 6 deletions pkg/api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Manager interface {
GetBusinessAreas(ctx context.Context, filters map[string]string) ([]BusinessArea, error)
GetCurrencies(ctx context.Context, filters map[string]string) ([]Currency, error)
SaveEvent(ctx context.Context, filters map[string]string) (int, error)
GetEvents(ctx context.Context, filters map[string]string) ([]Event, error)
LogProcessingOfCustomerData(ctx context.Context, filters map[string]string) error
}

Expand Down Expand Up @@ -127,12 +128,7 @@ func (c *Client) SaveEvent(ctx context.Context, filters map[string]string) (int,
if err != nil {
return 0, err
}
var res = struct {
Status common2.Status
Records []struct {
EventID int `json:"eventID"`
} `json:"records"`
}{}
var res SaveEventResponse
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
return 0, erro.NewFromError(fmt.Sprintf("failed to unmarshal %s response", SaveEventMethod), err)
}
Expand All @@ -141,3 +137,18 @@ func (c *Client) SaveEvent(ctx context.Context, filters map[string]string) (int,
}
return res.Records[0].EventID, nil
}

func (c *Client) GetEvents(ctx context.Context, filters map[string]string) ([]Event, error) {
resp, err := c.commonClient.SendRequest(ctx, GetEvents, filters)
if err != nil {
return nil, err
}
var res GetEventsResponse
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
return nil, erro.NewFromError("failed to unmarshal GetEmployeesResponse", err)
}
if !common.IsJSONResponseOK(&res.Status) {
return nil, erro.NewFromResponseStatus(&res.Status)
}
return res.Events, nil
}
6 changes: 6 additions & 0 deletions pkg/api/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ func TestApiRequests(t *testing.T) {
assert.NoError(t, err)
assert.NotEqual(t, 0, eventID)
})

t.Run("test GetEvents", func(t *testing.T) {
events, err := cli.GetEvents(context.Background(), map[string]string{})
assert.NoError(t, err)
t.Log(events)
})
}

0 comments on commit 68aec69

Please sign in to comment.