Skip to content

Commit

Permalink
Merge pull request #903 from weichou1229/issue-4814
Browse files Browse the repository at this point in the history
feat: Add multiple profile basic info DTO
  • Loading branch information
cloudxxx8 authored Jul 4, 2024
2 parents efd5619 + 2133f19 commit 28ac3a9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (

ApiDeviceProfileRoute = ApiBase + "/deviceprofile"
ApiDeviceProfileBasicInfoRoute = ApiDeviceProfileRoute + "/basicinfo"
ApiAllDeviceProfileBasicInfoRoute = ApiDeviceProfileBasicInfoRoute + "/" + All
ApiDeviceProfileDeviceCommandRoute = ApiDeviceProfileRoute + "/" + DeviceCommand
ApiDeviceProfileResourceRoute = ApiDeviceProfileRoute + "/" + Resource
ApiDeviceProfileUploadFileRoute = ApiDeviceProfileRoute + "/uploadfile"
Expand Down
14 changes: 13 additions & 1 deletion dtos/deviceprofile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion dtos/deviceprofile_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021-2023 IOTech Ltd
// Copyright (C) 2021-2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion dtos/responses/deviceprofile.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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,
}
}
20 changes: 19 additions & 1 deletion dtos/responses/deviceprofile_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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)
}

0 comments on commit 28ac3a9

Please sign in to comment.