diff --git a/common/constants.go b/common/constants.go index 90a3ed5a..0a368157 100644 --- a/common/constants.go +++ b/common/constants.go @@ -35,6 +35,7 @@ const ( ApiDeviceProfileRoute = ApiBase + "/deviceprofile" ApiDeviceProfileBasicInfoRoute = ApiDeviceProfileRoute + "/basicinfo" + ApiAllDeviceProfileBasicInfoRoute = ApiDeviceProfileBasicInfoRoute + "/" + All ApiDeviceProfileDeviceCommandRoute = ApiDeviceProfileRoute + "/" + DeviceCommand ApiDeviceProfileResourceRoute = ApiDeviceProfileRoute + "/" + Resource ApiDeviceProfileUploadFileRoute = ApiDeviceProfileRoute + "/uploadfile" diff --git a/dtos/deviceprofile.go b/dtos/deviceprofile.go index 0a1a0fe2..94ad886f 100644 --- a/dtos/deviceprofile.go +++ b/dtos/deviceprofile.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2024 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -94,6 +94,18 @@ func FromDeviceProfileModelToDTO(deviceProfile models.DeviceProfile) DeviceProfi } } +// FromDeviceProfileModelToBasicInfoDTO transforms the DeviceProfile Model to the DeviceProfileBasicInfo DTO +func FromDeviceProfileModelToBasicInfoDTO(deviceProfile models.DeviceProfile) DeviceProfileBasicInfo { + return DeviceProfileBasicInfo{ + Id: deviceProfile.Id, + Name: deviceProfile.Name, + Description: deviceProfile.Description, + Manufacturer: deviceProfile.Manufacturer, + Model: deviceProfile.Model, + Labels: deviceProfile.Labels, + } +} + func ValidateDeviceProfileDTO(profile DeviceProfile) error { // deviceResources validation dupCheck := make(map[string]bool) diff --git a/dtos/deviceprofile_test.go b/dtos/deviceprofile_test.go index e9e29bac..609e800d 100644 --- a/dtos/deviceprofile_test.go +++ b/dtos/deviceprofile_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2021-2023 IOTech Ltd +// Copyright (C) 2021-2024 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -90,6 +90,11 @@ func TestFromDeviceProfileModelToDTO(t *testing.T) { assert.Equal(t, profileData(), result, "FromDeviceProfileModelToDTO did not result in expected device profile DTO.") } +func TestFromDeviceProfileModelToBasicInfoDTO(t *testing.T) { + result := FromDeviceProfileModelToBasicInfoDTO(testDeviceProfile) + assert.Equal(t, profileData().DeviceProfileBasicInfo, result, "FromDeviceProfileModelToBasicInfoDTO did not result in expected device profile basic info DTO.") +} + func TestDeviceProfileDTOValidation(t *testing.T) { valid := profileData() duplicatedDeviceResource := profileData() diff --git a/dtos/responses/deviceprofile.go b/dtos/responses/deviceprofile.go index 00a125ba..979d9d14 100644 --- a/dtos/responses/deviceprofile.go +++ b/dtos/responses/deviceprofile.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020 IOTech Ltd +// Copyright (C) 2020-2024 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -35,3 +35,16 @@ func NewMultiDeviceProfilesResponse(requestId string, message string, statusCode Profiles: deviceProfiles, } } + +// MultiDeviceProfileBasicInfoResponse defines the Response Content for GET multiple DeviceProfileBasicInfo DTOs. +type MultiDeviceProfileBasicInfoResponse struct { + common.BaseWithTotalCountResponse `json:",inline"` + Profiles []dtos.DeviceProfileBasicInfo `json:"profiles"` +} + +func NewMultiDeviceProfileBasicInfosResponse(requestId string, message string, statusCode int, totalCount uint32, deviceProfileBasicInfos []dtos.DeviceProfileBasicInfo) MultiDeviceProfileBasicInfoResponse { + return MultiDeviceProfileBasicInfoResponse{ + BaseWithTotalCountResponse: common.NewBaseWithTotalCountResponse(requestId, message, statusCode, totalCount), + Profiles: deviceProfileBasicInfos, + } +} diff --git a/dtos/responses/deviceprofile_test.go b/dtos/responses/deviceprofile_test.go index cb3ccd1c..5ea2a5f5 100644 --- a/dtos/responses/deviceprofile_test.go +++ b/dtos/responses/deviceprofile_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020 IOTech Ltd +// Copyright (C) 2020-2024 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -43,3 +43,21 @@ func TestNewMultiDeviceProfilesResponse(t *testing.T) { assert.Equal(t, expectedTotalCount, actual.TotalCount) assert.Equal(t, expectedDeviceProfiles, actual.Profiles) } + +func TestNewMultiDeviceProfileBasicInfosResponse(t *testing.T) { + expectedRequestId := "123456" + expectedStatusCode := 200 + expectedMessage := "unit test message" + expectedDeviceProfileBasicInfos := []dtos.DeviceProfileBasicInfo{ + {Name: "test device profile1"}, + {Name: "test device profile2"}, + } + expectedTotalCount := uint32(2) + actual := NewMultiDeviceProfileBasicInfosResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedTotalCount, expectedDeviceProfileBasicInfos) + + assert.Equal(t, expectedRequestId, actual.RequestId) + assert.Equal(t, expectedStatusCode, actual.StatusCode) + assert.Equal(t, expectedMessage, actual.Message) + assert.Equal(t, expectedTotalCount, actual.TotalCount) + assert.Equal(t, expectedDeviceProfileBasicInfos, actual.Profiles) +}