From 95f69039ffe7ffd3bacc62779f7a464f02ded132 Mon Sep 17 00:00:00 2001 From: bruce Date: Wed, 6 Dec 2023 22:17:30 +0800 Subject: [PATCH] PS-579 Add device update func with query parameter Add device update func with query parameter Signed-off-by: bruce --- clients/http/device.go | 12 ++++++++++++ clients/interfaces/device.go | 2 ++ common/constants.go | 1 + 3 files changed, 15 insertions(+) diff --git a/clients/http/device.go b/clients/http/device.go index 6b47bde8..82d6d3bc 100644 --- a/clients/http/device.go +++ b/clients/http/device.go @@ -42,6 +42,18 @@ func (dc DeviceClient) Update(ctx context.Context, reqs []requests.UpdateDeviceR return res, nil } +func (dc DeviceClient) UpdateWithQueryParams(ctx context.Context, reqs []requests.UpdateDeviceRequest, queryParams map[string]string) (res []dtoCommon.BaseResponse, err errors.EdgeX) { + requestParams := url.Values{} + for k, v := range queryParams { + requestParams.Set(k, v) + } + err = utils.PatchRequest(ctx, &res, dc.baseUrl, common.ApiDeviceRoute, requestParams, reqs) + if err != nil { + return res, errors.NewCommonEdgeXWrapper(err) + } + return res, nil +} + func (dc DeviceClient) AllDevices(ctx context.Context, labels []string, offset int, limit int) (res responses.MultiDevicesResponse, err errors.EdgeX) { requestParams := url.Values{} if len(labels) > 0 { diff --git a/clients/interfaces/device.go b/clients/interfaces/device.go index 2916849d..0bac9315 100644 --- a/clients/interfaces/device.go +++ b/clients/interfaces/device.go @@ -20,6 +20,8 @@ type DeviceClient interface { Add(ctx context.Context, reqs []requests.AddDeviceRequest) ([]common.BaseWithIdResponse, errors.EdgeX) // Update updates devices. Update(ctx context.Context, reqs []requests.UpdateDeviceRequest) ([]common.BaseResponse, errors.EdgeX) + // UpdateWithQueryParams updates devices with query parameters. + UpdateWithQueryParams(ctx context.Context, reqs []requests.UpdateDeviceRequest, queryParams map[string]string) ([]common.BaseResponse, errors.EdgeX) // AllDevices returns all devices. Devices can also be filtered by labels. // 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. diff --git a/common/constants.go b/common/constants.go index 353d8dd6..003913a2 100644 --- a/common/constants.go +++ b/common/constants.go @@ -209,6 +209,7 @@ const ( KeyOnly = "keyOnly" //query string to specify if the response will only return the keys of the specified query key prefix, without values and metadata Plaintext = "plaintext" //query string to specify if the response will return the stored plain text value of the key(s) without any encoding Deregistered = "deregistered" //query string to specify if the response will return the registries of deregistered services + NoCallback = "nocallback" //query string to specify if the response will return the registries of deregistered services ) // Constants related to the default value of query strings in the v2 service APIs