From c961a5e6e02e42ae5ca8c3dcaaf95f04ebf97f14 Mon Sep 17 00:00:00 2001 From: Chris Hung Date: Fri, 17 Feb 2023 14:03:54 +0800 Subject: [PATCH] feat(data)!: update Add Event REST endpoint BREAKING CHANGE: POST Event RSET endpoint will become /event/{serviceName}/{profileName}/{deviceName}/{sourceName} Signed-off-by: Chris Hung --- go.mod | 2 +- go.sum | 4 ++-- .../core/data/controller/http/event_test.go | 17 +++++++++-------- internal/core/data/router.go | 4 ++-- openapi/v3/core-data.yaml | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 070c479115..f1ebf922b2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25 github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 - github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15 + github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.17 github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.7 github.com/fxamacker/cbor/v2 v2.4.0 diff --git a/go.sum b/go.sum index b1762bf7f0..557f9c8ed9 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25 h1:PkmFk6qTwc4WHxAwRBY github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15 h1:0fPmT+Jm2scrs9iQLX9dNTAaCPXn6fiTCwiYhcTc0fc= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.15/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.17 h1:29zJpgNGSxEZlGh+1Bgh4if3EU1P0osGnGiRhWYv1SA= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.17/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c= github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk= github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ= github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg= diff --git a/internal/core/data/controller/http/event_test.go b/internal/core/data/controller/http/event_test.go index 4b5cb0e3f3..5f8bf1c6af 100644 --- a/internal/core/data/controller/http/event_test.go +++ b/internal/core/data/controller/http/event_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2022 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -19,11 +19,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/edgexfoundry/edgex-go/internal/core/data/application" - "github.com/edgexfoundry/edgex-go/internal/core/data/config" - "github.com/edgexfoundry/edgex-go/internal/core/data/container" - dbMock "github.com/edgexfoundry/edgex-go/internal/core/data/infrastructure/interfaces/mocks" - "github.com/edgexfoundry/edgex-go/internal/core/data/mocks" "github.com/edgexfoundry/go-mod-bootstrap/v3/di" "github.com/edgexfoundry/go-mod-core-contracts/v3/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos" @@ -32,6 +27,12 @@ import ( responseDTO "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos/responses" "github.com/edgexfoundry/go-mod-core-contracts/v3/errors" "github.com/edgexfoundry/go-mod-core-contracts/v3/models" + + "github.com/edgexfoundry/edgex-go/internal/core/data/application" + "github.com/edgexfoundry/edgex-go/internal/core/data/config" + "github.com/edgexfoundry/edgex-go/internal/core/data/container" + dbMock "github.com/edgexfoundry/edgex-go/internal/core/data/infrastructure/interfaces/mocks" + "github.com/edgexfoundry/edgex-go/internal/core/data/mocks" ) var expectedEventId = uuid.New().String() @@ -243,7 +244,7 @@ func TestAddEvent(t *testing.T) { require.NoError(t, err) reader := strings.NewReader(string(byteData)) - req, err := http.NewRequest(http.MethodPost, common.ApiEventProfileNameDeviceNameSourceNameRoute, reader) + req, err := http.NewRequest(http.MethodPost, common.ApiEventServiceNameProfileNameDeviceNameSourceNameRoute, reader) req.Header.Set(common.ContentType, testCase.RequestContentType) req = mux.SetURLVars(req, map[string]string{common.ServiceName: TestServiceName, common.ProfileName: testCase.ProfileName, common.DeviceName: testCase.DeviceName, common.SourceName: testCase.Request.Event.SourceName}) require.NoError(t, err) @@ -330,7 +331,7 @@ func TestAddEventSize(t *testing.T) { require.NoError(t, err) reader := strings.NewReader(string(byteData)) - req, err := http.NewRequest(http.MethodPost, common.ApiEventProfileNameDeviceNameSourceNameRoute, reader) + req, err := http.NewRequest(http.MethodPost, common.ApiEventServiceNameProfileNameDeviceNameSourceNameRoute, reader) req.Header.Set(common.ContentType, testCase.RequestContentType) req = mux.SetURLVars(req, map[string]string{common.ServiceName: TestServiceName, common.ProfileName: validRequest.Event.ProfileName, common.DeviceName: validRequest.Event.DeviceName, common.SourceName: validRequest.Event.SourceName}) require.NoError(t, err) diff --git a/internal/core/data/router.go b/internal/core/data/router.go index 073cc33f60..2c0f6c10b4 100644 --- a/internal/core/data/router.go +++ b/internal/core/data/router.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2021 IOTech Ltd +// Copyright (C) 2021-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -28,7 +28,7 @@ func LoadRestRoutes(r *mux.Router, dic *di.Container, serviceName string) { // Events ec := dataController.NewEventController(dic) - r.HandleFunc(common.ApiEventProfileNameDeviceNameSourceNameRoute, ec.AddEvent).Methods(http.MethodPost) + r.HandleFunc(common.ApiEventServiceNameProfileNameDeviceNameSourceNameRoute, ec.AddEvent).Methods(http.MethodPost) r.HandleFunc(common.ApiEventIdRoute, ec.EventById).Methods(http.MethodGet) r.HandleFunc(common.ApiEventIdRoute, ec.DeleteEventById).Methods(http.MethodDelete) r.HandleFunc(common.ApiEventCountRoute, ec.EventTotalCount).Methods(http.MethodGet) diff --git a/openapi/v3/core-data.yaml b/openapi/v3/core-data.yaml index a7ece79bde..b99f799c45 100644 --- a/openapi/v3/core-data.yaml +++ b/openapi/v3/core-data.yaml @@ -557,7 +557,7 @@ components: statusCode: 200 count: 3 paths: - /event/{serviceName}{profileName}/{deviceName}/{sourceName}: + /event/{serviceName}/{profileName}/{deviceName}/{sourceName}: parameters: - $ref: '#/components/parameters/correlatedRequestHeader' - name: serviceName