Skip to content

Commit 68aec69

Browse files
author
David Zingerman
committed
get events implemented
1 parent 15a3699 commit 68aec69

File tree

4 files changed

+71
-13
lines changed

4 files changed

+71
-13
lines changed

pkg/api/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ const (
99
logProcessingOfCustomerDataMethod = "logProcessingOfCustomerData"
1010
createInstallationMethod = "createInstallation"
1111
SaveEventMethod = "saveEvent"
12+
GetEvents = "getEvents"
1213
)

pkg/api/models.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,54 @@ type Country struct {
3838
Added uint64 `json:"added"`
3939
}
4040

41+
type Event struct {
42+
EventID string `json:"eventID"`
43+
ID string `json:"id"`
44+
Description string `json:"description"`
45+
TypeID string `json:"typeID"`
46+
StartTime string `json:"startTime"`
47+
EndTime string `json:"endTime"`
48+
CustomerID string `json:"customerID"`
49+
ContactID string `json:"contactID"`
50+
ProjectID string `json:"projectID"`
51+
EmployeeID string `json:"employeeID"`
52+
SubmitterID string `json:"submitterID"`
53+
SupplierID string `json:"supplierID"`
54+
SupplierName string `json:"supplierName"`
55+
StatusID string `json:"statusID"`
56+
ResourceID string `json:"resourceID"`
57+
Notes string `json:"notes"`
58+
LastModified string `json:"lastModified"`
59+
ContactName string `json:"contactName"`
60+
CustomerName string `json:"customerName"`
61+
EmployeeName string `json:"employeeName"`
62+
SubmitterName string `json:"submitterName"`
63+
ProjectName string `json:"projectName"`
64+
ResourceName string `json:"resourceName"`
65+
StatusName string `json:"statusName"`
66+
TypeName string `json:"typeName"`
67+
Completed string `json:"completed"`
68+
}
69+
70+
type GetEventsResponse struct {
71+
Status sharedCommon.Status `json:"status"`
72+
Events []Event `json:"records"`
73+
}
74+
75+
type SaveEventResponse struct {
76+
Status sharedCommon.Status
77+
Records []struct {
78+
EventID int `json:"eventID"`
79+
} `json:"records"`
80+
}
4181
type Employee struct {
42-
EmployeeID string `json:"employeeID"`
43-
FullName string `json:"fullName"`
44-
EmployeeName string `json:"employeeName"`
45-
FirstName string `json:"firstName"`
46-
LastName string `json:"lastName"`
47-
Phone string `json:"phone"`
48-
Mobile string `json:"mobile"`
82+
EmployeeID string `json:"employeeID"`
83+
FullName string `json:"fullName"`
84+
EmployeeName string `json:"employeeName"`
85+
FirstName string `json:"firstName"`
86+
LastName string `json:"lastName"`
87+
Phone string `json:"phone"`
88+
Mobile string `json:"mobile"`
4989
Email string `json:"email"`
5090
Fax string `json:"fax"`
5191
Code string `json:"code"`

pkg/api/requests.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Manager interface {
1919
GetBusinessAreas(ctx context.Context, filters map[string]string) ([]BusinessArea, error)
2020
GetCurrencies(ctx context.Context, filters map[string]string) ([]Currency, error)
2121
SaveEvent(ctx context.Context, filters map[string]string) (int, error)
22+
GetEvents(ctx context.Context, filters map[string]string) ([]Event, error)
2223
LogProcessingOfCustomerData(ctx context.Context, filters map[string]string) error
2324
}
2425

@@ -127,12 +128,7 @@ func (c *Client) SaveEvent(ctx context.Context, filters map[string]string) (int,
127128
if err != nil {
128129
return 0, err
129130
}
130-
var res = struct {
131-
Status common2.Status
132-
Records []struct {
133-
EventID int `json:"eventID"`
134-
} `json:"records"`
135-
}{}
131+
var res SaveEventResponse
136132
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
137133
return 0, erro.NewFromError(fmt.Sprintf("failed to unmarshal %s response", SaveEventMethod), err)
138134
}
@@ -141,3 +137,18 @@ func (c *Client) SaveEvent(ctx context.Context, filters map[string]string) (int,
141137
}
142138
return res.Records[0].EventID, nil
143139
}
140+
141+
func (c *Client) GetEvents(ctx context.Context, filters map[string]string) ([]Event, error) {
142+
resp, err := c.commonClient.SendRequest(ctx, GetEvents, filters)
143+
if err != nil {
144+
return nil, err
145+
}
146+
var res GetEventsResponse
147+
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
148+
return nil, erro.NewFromError("failed to unmarshal GetEmployeesResponse", err)
149+
}
150+
if !common.IsJSONResponseOK(&res.Status) {
151+
return nil, erro.NewFromResponseStatus(&res.Status)
152+
}
153+
return res.Events, nil
154+
}

pkg/api/requests_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,10 @@ func TestApiRequests(t *testing.T) {
6969
assert.NoError(t, err)
7070
assert.NotEqual(t, 0, eventID)
7171
})
72+
73+
t.Run("test GetEvents", func(t *testing.T) {
74+
events, err := cli.GetEvents(context.Background(), map[string]string{})
75+
assert.NoError(t, err)
76+
t.Log(events)
77+
})
7278
}

0 commit comments

Comments
 (0)