From e3e2da89f783a55556a27478db4547bf7693e3ac Mon Sep 17 00:00:00 2001 From: sinchubhat Date: Tue, 25 Nov 2025 10:10:16 +0530 Subject: [PATCH] refactor: correct dto mapping for GetFeatures and PowerState --- .../http/v1/devicemanagement_test.go | 26 ++++++++--------- internal/controller/http/v1/features.go | 28 +++++++++---------- internal/entity/dto/v1/getfeatures.go | 16 +++++++++++ internal/entity/dto/v1/powerstate.go | 4 +-- 4 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 internal/entity/dto/v1/getfeatures.go diff --git a/internal/controller/http/v1/devicemanagement_test.go b/internal/controller/http/v1/devicemanagement_test.go index 71c2db81..ee0741e8 100644 --- a/internal/controller/http/v1/devicemanagement_test.go +++ b/internal/controller/http/v1/devicemanagement_test.go @@ -123,19 +123,19 @@ func TestDeviceManagement(t *testing.T) { Return(dto.Features{}, dtov2.Features{}, nil) }, expectedCode: http.StatusOK, - response: map[string]interface{}{ - "IDER": false, - "KVM": false, - "SOL": false, - "httpsBootSupported": false, - "kvmAvailable": false, - "localPBABootSupported": false, - "ocr": false, - "optInState": 0, - "redirection": false, - "remoteErase": false, - "userConsent": "", - "winREBootSupported": false, + response: dto.GetFeaturesResponse{ + IDER: false, + KVM: false, + SOL: false, + HTTPSBootSupported: false, + KVMAvailable: false, + LocalPBABootSupported: false, + OCR: false, + OptInState: 0, + Redirection: false, + RemoteErase: false, + UserConsent: "", + WinREBootSupported: false, }, }, { diff --git a/internal/controller/http/v1/features.go b/internal/controller/http/v1/features.go index a1dd870c..5c95394a 100644 --- a/internal/controller/http/v1/features.go +++ b/internal/controller/http/v1/features.go @@ -5,7 +5,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/device-management-toolkit/console/internal/entity/dto/v1" + dto "github.com/device-management-toolkit/console/internal/entity/dto/v1" ) func (r *deviceManagementRoutes) getVersion(c *gin.Context) { @@ -33,19 +33,19 @@ func (r *deviceManagementRoutes) getFeatures(c *gin.Context) { return } - v1Features := map[string]interface{}{ - "redirection": features.Redirection, - "KVM": features.EnableKVM, - "SOL": features.EnableSOL, - "IDER": features.EnableIDER, - "optInState": features.OptInState, - "userConsent": features.UserConsent, - "kvmAvailable": features.KVMAvailable, - "ocr": features.OCR, - "httpsBootSupported": features.HTTPSBootSupported, - "winREBootSupported": features.WinREBootSupported, - "localPBABootSupported": features.LocalPBABootSupported, - "remoteErase": features.RemoteErase, + v1Features := dto.GetFeaturesResponse{ + Redirection: features.Redirection, + KVM: features.EnableKVM, + SOL: features.EnableSOL, + IDER: features.EnableIDER, + OptInState: features.OptInState, + UserConsent: features.UserConsent, + KVMAvailable: features.KVMAvailable, + OCR: features.OCR, + HTTPSBootSupported: features.HTTPSBootSupported, + WinREBootSupported: features.WinREBootSupported, + LocalPBABootSupported: features.LocalPBABootSupported, + RemoteErase: features.RemoteErase, } c.JSON(http.StatusOK, v1Features) diff --git a/internal/entity/dto/v1/getfeatures.go b/internal/entity/dto/v1/getfeatures.go new file mode 100644 index 00000000..d62dd569 --- /dev/null +++ b/internal/entity/dto/v1/getfeatures.go @@ -0,0 +1,16 @@ +package dto + +type GetFeaturesResponse struct { + Redirection bool `json:"redirection" binding:"required" example:"true"` + KVM bool `json:"KVM" binding:"required" example:"true"` + SOL bool `json:"SOL" binding:"required" example:"true"` + IDER bool `json:"IDER" binding:"required" example:"true"` + OptInState int `json:"optInState" binding:"required" example:"0"` + UserConsent string `json:"userConsent" binding:"required" example:"none"` + KVMAvailable bool `json:"kvmAvailable" binding:"required" example:"true"` + OCR bool `json:"ocr" binding:"required" example:"false"` + HTTPSBootSupported bool `json:"httpsBootSupported" binding:"required" example:"false"` + WinREBootSupported bool `json:"winREBootSupported" binding:"required" example:"false"` + LocalPBABootSupported bool `json:"localPBABootSupported" binding:"required" example:"false"` + RemoteErase bool `json:"remoteErase" binding:"required" example:"false"` +} diff --git a/internal/entity/dto/v1/powerstate.go b/internal/entity/dto/v1/powerstate.go index 233f08aa..0f360e6d 100644 --- a/internal/entity/dto/v1/powerstate.go +++ b/internal/entity/dto/v1/powerstate.go @@ -1,6 +1,6 @@ package dto type PowerState struct { - PowerState int `json:"powerstate" binding:"required" example:"0"` - OSPowerSavingState int `json:"osPowerSavingState" binding:"required" example:"0"` + PowerState int `json:"powerstate" example:"0"` + OSPowerSavingState int `json:"osPowerSavingState" example:"0"` }