Skip to content

Commit

Permalink
Merge pull request #208 from IOTechSystems/EDX-4384-branch
Browse files Browse the repository at this point in the history
EDX-4384 Update client interfaces to use int64 for time range
  • Loading branch information
cloudxxx8 authored Nov 6, 2023
2 parents 5844c11 + 62d6121 commit 6679ca3
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 99 deletions.
4 changes: 2 additions & 2 deletions clients/http/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func (ec *eventClient) DeleteByDeviceName(ctx context.Context, name string) (dto
return res, nil
}

func (ec *eventClient) EventsByTimeRange(ctx context.Context, start, end, offset, limit int) (
func (ec *eventClient) EventsByTimeRange(ctx context.Context, start, end int64, offset, limit int) (
responses.MultiEventsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiEventRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
requestPath := utils.EscapeAndJoinPath(common.ApiEventRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand Down
6 changes: 3 additions & 3 deletions clients/http/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func TestDeleteEventsByDeviceName(t *testing.T) {
}

func TestQueryEventsByTimeRange(t *testing.T) {
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiEventRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiEventRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiEventsResponse{})
defer ts.Close()

Expand Down
4 changes: 2 additions & 2 deletions clients/http/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (client *NotificationClient) NotificationsByStatus(ctx context.Context, sta
}

// NotificationsByTimeRange query notifications with time range, offset and limit
func (client *NotificationClient) NotificationsByTimeRange(ctx context.Context, start int, end int, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (client *NotificationClient) NotificationsByTimeRange(ctx context.Context, start, end int64, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand Down
6 changes: 3 additions & 3 deletions clients/http/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func TestNotificationClient_NotificationsBySubscriptionName(t *testing.T) {
}

func TestNotificationClient_NotificationsByTimeRange(t *testing.T) {
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL)
Expand Down
16 changes: 8 additions & 8 deletions clients/http/reading.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (rc readingClient) ReadingsByResourceName(ctx context.Context, name string,
return res, nil
}

func (rc readingClient) ReadingsByTimeRange(ctx context.Context, start, end, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (rc readingClient) ReadingsByTimeRange(ctx context.Context, start, end int64, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand All @@ -100,8 +100,8 @@ func (rc readingClient) ReadingsByTimeRange(ctx context.Context, start, end, off
}

// ReadingsByResourceNameAndTimeRange returns readings by resource name and specified time range. Readings are sorted in descending order of origin time.
func (rc readingClient) ReadingsByResourceNameAndTimeRange(ctx context.Context, name string, start, end, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.ResourceName, name, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (rc readingClient) ReadingsByResourceNameAndTimeRange(ctx context.Context, name string, start, end int64, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.ResourceName, name, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand All @@ -127,8 +127,8 @@ func (rc readingClient) ReadingsByDeviceNameAndResourceName(ctx context.Context,

}

func (rc readingClient) ReadingsByDeviceNameAndResourceNameAndTimeRange(ctx context.Context, deviceName, resourceName string, start, end, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.ResourceName, resourceName, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (rc readingClient) ReadingsByDeviceNameAndResourceNameAndTimeRange(ctx context.Context, deviceName, resourceName string, start, end int64, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.ResourceName, resourceName, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand All @@ -140,8 +140,8 @@ func (rc readingClient) ReadingsByDeviceNameAndResourceNameAndTimeRange(ctx cont
return res, nil
}

func (rc readingClient) ReadingsByDeviceNameAndResourceNamesAndTimeRange(ctx context.Context, deviceName string, resourceNames []string, start, end, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (rc readingClient) ReadingsByDeviceNameAndResourceNamesAndTimeRange(ctx context.Context, deviceName string, resourceNames []string, start, end int64, offset, limit int) (responses.MultiReadingsResponse, errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand Down
24 changes: 12 additions & 12 deletions clients/http/reading_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func TestQueryReadingsByResourceName(t *testing.T) {
}

func TestQueryReadingsByTimeRange(t *testing.T) {
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiReadingsResponse{})
defer ts.Close()

Expand All @@ -91,9 +91,9 @@ func TestQueryReadingsByTimeRange(t *testing.T) {

func TestQueryReadingsByResourceNameAndTimeRange(t *testing.T) {
resourceName := "resource"
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.ResourceName, resourceName, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.ResourceName, resourceName, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiReadingsResponse{})
defer ts.Close()

Expand All @@ -119,9 +119,9 @@ func TestQueryReadingsByDeviceNameAndResourceName(t *testing.T) {
func TestQueryReadingsByDeviceNameAndResourceNameAndTimeRange(t *testing.T) {
deviceName := "device"
resourceName := "resource"
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.ResourceName, resourceName, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.ResourceName, resourceName, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiReadingsResponse{})
defer ts.Close()

Expand All @@ -134,9 +134,9 @@ func TestQueryReadingsByDeviceNameAndResourceNameAndTimeRange(t *testing.T) {
func TestQueryReadingsByDeviceNameAndResourceNamesAndTimeRange(t *testing.T) {
deviceName := "device"
resourceNames := []string{"resource01", "resource02"}
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiReadingRoute, common.Device, common.Name, deviceName, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiReadingsResponse{})
defer ts.Close()

Expand Down
4 changes: 2 additions & 2 deletions clients/http/transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (client *TransmissionClient) TransmissionById(ctx context.Context, id strin
}

// TransmissionsByTimeRange query transmissions with time range, offset and limit
func (client *TransmissionClient) TransmissionsByTimeRange(ctx context.Context, start int, end int, offset int, limit int) (res responses.MultiTransmissionsResponse, err errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiTransmissionRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
func (client *TransmissionClient) TransmissionsByTimeRange(ctx context.Context, start, end int64, offset int, limit int) (res responses.MultiTransmissionsResponse, err errors.EdgeX) {
requestPath := utils.EscapeAndJoinPath(common.ApiTransmissionRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
Expand Down
6 changes: 3 additions & 3 deletions clients/http/transmission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func TestTransmissionClient_TransmissionsBySubscriptionName(t *testing.T) {
}

func TestTransmissionClient_TransmissionsByTimeRange(t *testing.T) {
start := 1
end := 10
urlPath := utils.EscapeAndJoinPath(common.ApiTransmissionRoute, common.Start, strconv.Itoa(start), common.End, strconv.Itoa(end))
start := int64(1)
end := int64(10)
urlPath := utils.EscapeAndJoinPath(common.ApiTransmissionRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
ts := newTestServer(http.MethodGet, urlPath, responses.MultiTransmissionsResponse{})
defer ts.Close()
client := NewTransmissionClient(ts.URL)
Expand Down
2 changes: 1 addition & 1 deletion clients/interfaces/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type EventClient interface {
// start, end: Unix timestamp, indicating the date/time range.
// offset: The number of items to skip before starting to collect the result set. Default is 0.
// limit: The number of items to return. Specify -1 will return all remaining items after offset. The maximum will be the MaxResultCount as defined in the configuration of service. Default is 20.
EventsByTimeRange(ctx context.Context, start, end, offset, limit int) (responses.MultiEventsResponse, errors.EdgeX)
EventsByTimeRange(ctx context.Context, start, end int64, offset, limit int) (responses.MultiEventsResponse, errors.EdgeX)
// DeleteByAge deletes events that are older than the given age. Age is supposed in milliseconds from created timestamp.
DeleteByAge(ctx context.Context, age int) (common.BaseResponse, errors.EdgeX)
}
23 changes: 19 additions & 4 deletions clients/interfaces/mocks/EventClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6679ca3

Please sign in to comment.