Skip to content

Commit

Permalink
Merge pull request #904 from weichou1229/issue-4814-2
Browse files Browse the repository at this point in the history
feat: Add profile basic info http client
  • Loading branch information
cloudxxx8 authored Jul 5, 2024
2 parents 28ac3a9 + 3d51ed7 commit 2eb7a4d
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 26 deletions.
17 changes: 16 additions & 1 deletion clients/http/deviceprofile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2023 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
// Copyright (C) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -120,6 +120,21 @@ func (client *DeviceProfileClient) AllDeviceProfiles(ctx context.Context, labels
return res, nil
}

// AllDeviceProfileBasicInfos queries the device profile basic infos with offset, and limit
func (client *DeviceProfileClient) AllDeviceProfileBasicInfos(ctx context.Context, labels []string, offset int, limit int) (res responses.MultiDeviceProfileBasicInfoResponse, edgexError errors.EdgeX) {
requestParams := url.Values{}
if len(labels) > 0 {
requestParams.Set(common.Labels, strings.Join(labels, common.CommaSeparator))
}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
err := utils.GetRequest(ctx, &res, client.baseUrl, common.ApiAllDeviceProfileBasicInfoRoute, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
}
return res, nil
}

// DeviceProfilesByModel queries the device profiles with offset, limit and model
func (client *DeviceProfileClient) DeviceProfilesByModel(ctx context.Context, model string, offset int, limit int) (res responses.MultiDeviceProfilesResponse, edgexError errors.EdgeX) {
requestPath := path.Join(common.ApiDeviceProfileRoute, common.Model, model)
Expand Down
9 changes: 9 additions & 0 deletions clients/http/deviceprofile_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//
// Copyright (C) 2020-2021 Unknown author
// Copyright (C) 2023 Intel Corporation
// Copyright (C) 2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -203,6 +204,14 @@ func TestQueryAllDeviceProfiles(t *testing.T) {
require.NoError(t, err)
}

func TestQueryAllDeviceProfileBasicInfos(t *testing.T) {
ts := newTestServer(http.MethodGet, common.ApiAllDeviceProfileBasicInfoRoute, responses.MultiDeviceProfilesResponse{})
defer ts.Close()
client := NewDeviceProfileClient(ts.URL, NewNullAuthenticationInjector(), false)
_, err := client.AllDeviceProfileBasicInfos(context.Background(), []string{"testLabel1", "testLabel2"}, 1, 10)
require.NoError(t, err)
}

func TestQueryDeviceProfilesByModel(t *testing.T) {
testModel := "testModel"
urlPath := path.Join(common.ApiDeviceProfileRoute, common.Model, testModel)
Expand Down
4 changes: 3 additions & 1 deletion clients/interfaces/deviceprofile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2022 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -30,6 +30,8 @@ type DeviceProfileClient interface {
DeviceProfileByName(ctx context.Context, name string) (responses.DeviceProfileResponse, errors.EdgeX)
// AllDeviceProfiles queries all profiles
AllDeviceProfiles(ctx context.Context, labels []string, offset int, limit int) (responses.MultiDeviceProfilesResponse, errors.EdgeX)
// AllDeviceProfileBasicInfos queries all profile basic infos
AllDeviceProfileBasicInfos(ctx context.Context, labels []string, offset int, limit int) (responses.MultiDeviceProfileBasicInfoResponse, errors.EdgeX)
// DeviceProfilesByModel queries profiles by model
DeviceProfilesByModel(ctx context.Context, model string, offset int, limit int) (responses.MultiDeviceProfilesResponse, errors.EdgeX)
// DeviceProfilesByManufacturer queries profiles by manufacturer
Expand Down
Loading

0 comments on commit 2eb7a4d

Please sign in to comment.