Skip to content

Commit

Permalink
feat!: add device service name in Add Event API endpoint
Browse files Browse the repository at this point in the history
BREAKING CHANGE: update EventClient 'Add' method signature

closes #799

Signed-off-by: Chris Hung <[email protected]>
  • Loading branch information
Chris Hung committed Feb 16, 2023
1 parent 57cbd60 commit 61bd91a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions clients/http/event.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021 IOTech Ltd
// Copyright (C) 2021-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -31,9 +31,9 @@ func NewEventClient(baseUrl string) interfaces.EventClient {
}
}

func (ec *eventClient) Add(ctx context.Context, req requests.AddEventRequest) (
func (ec *eventClient) Add(ctx context.Context, serviceName string, req requests.AddEventRequest) (
dtoCommon.BaseWithIdResponse, errors.EdgeX) {
path := path.Join(common.ApiEventRoute, req.Event.ProfileName, req.Event.DeviceName, req.Event.SourceName)
path := path.Join(common.ApiEventRoute, serviceName, req.Event.ProfileName, req.Event.DeviceName, req.Event.SourceName)
var br dtoCommon.BaseWithIdResponse

bytes, encoding, err := req.Encode()
Expand Down
7 changes: 4 additions & 3 deletions clients/http/event_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021 IOTech Ltd
// Copyright (C) 2021-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -23,13 +23,14 @@ import (
)

func TestAddEvent(t *testing.T) {
serviceName := "serviceName"
event := dtos.Event{ProfileName: "profileName", DeviceName: "deviceName"}
apiRoute := path.Join(common.ApiEventRoute, event.ProfileName, event.DeviceName)
apiRoute := path.Join(common.ApiEventRoute, serviceName, event.ProfileName, event.DeviceName, event.SourceName)
ts := newTestServer(http.MethodPost, apiRoute, dtoCommon.BaseWithIdResponse{})
defer ts.Close()

client := NewEventClient(ts.URL)
res, err := client.Add(context.Background(), requests.AddEventRequest{Event: event})
res, err := client.Add(context.Background(), serviceName, requests.AddEventRequest{Event: event})
require.NoError(t, err)
assert.IsType(t, dtoCommon.BaseWithIdResponse{}, res)
}
Expand Down
4 changes: 2 additions & 2 deletions clients/interfaces/event.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021 IOTech Ltd
// Copyright (C) 2021-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -17,7 +17,7 @@ import (
// EventClient defines the interface for interactions with the Event endpoint on the EdgeX Foundry core-data service.
type EventClient interface {
// Add adds new event.
Add(ctx context.Context, req requests.AddEventRequest) (common.BaseWithIdResponse, errors.EdgeX)
Add(ctx context.Context, serviceName string, req requests.AddEventRequest) (common.BaseWithIdResponse, errors.EdgeX)
// AllEvents returns all events sorted in descending order of created time.
// The result can be limited in a certain range by specifying the offset and limit parameters.
// offset: The number of items to skip before starting to collect the result set. Default is 0.
Expand Down
20 changes: 10 additions & 10 deletions common/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2022 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -10,15 +10,15 @@ const (
ApiVersion = "v2"
ApiBase = "/api/v2"

ApiEventRoute = ApiBase + "/event"
ApiEventProfileNameDeviceNameSourceNameRoute = ApiEventRoute + "/{" + ProfileName + "}" + "/{" + DeviceName + "}" + "/{" + SourceName + "}"
ApiAllEventRoute = ApiEventRoute + "/" + All
ApiEventIdRoute = ApiEventRoute + "/" + Id + "/{" + Id + "}"
ApiEventCountRoute = ApiEventRoute + "/" + Count
ApiEventCountByDeviceNameRoute = ApiEventCountRoute + "/" + Device + "/" + Name + "/{" + Name + "}"
ApiEventByDeviceNameRoute = ApiEventRoute + "/" + Device + "/" + Name + "/{" + Name + "}"
ApiEventByTimeRangeRoute = ApiEventRoute + "/" + Start + "/{" + Start + "}/" + End + "/{" + End + "}"
ApiEventByAgeRoute = ApiEventRoute + "/" + Age + "/{" + Age + "}"
ApiEventRoute = ApiBase + "/event"
ApiEventServiceNameProfileNameDeviceNameSourceNameRoute = ApiEventRoute + "/{" + ServiceName + "}" + "/{" + ProfileName + "}" + "/{" + DeviceName + "}" + "/{" + SourceName + "}"
ApiAllEventRoute = ApiEventRoute + "/" + All
ApiEventIdRoute = ApiEventRoute + "/" + Id + "/{" + Id + "}"
ApiEventCountRoute = ApiEventRoute + "/" + Count
ApiEventCountByDeviceNameRoute = ApiEventCountRoute + "/" + Device + "/" + Name + "/{" + Name + "}"
ApiEventByDeviceNameRoute = ApiEventRoute + "/" + Device + "/" + Name + "/{" + Name + "}"
ApiEventByTimeRangeRoute = ApiEventRoute + "/" + Start + "/{" + Start + "}/" + End + "/{" + End + "}"
ApiEventByAgeRoute = ApiEventRoute + "/" + Age + "/{" + Age + "}"

ApiReadingRoute = ApiBase + "/reading"
ApiAllReadingRoute = ApiReadingRoute + "/" + All
Expand Down

0 comments on commit 61bd91a

Please sign in to comment.