Skip to content

Commit

Permalink
feat: use dto in getversion
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavilosetty-intel authored and rjbrache committed Sep 11, 2024
1 parent deef94b commit b95e1c6
Show file tree
Hide file tree
Showing 110 changed files with 1,234 additions and 1,059 deletions.
10 changes: 5 additions & 5 deletions internal/controller/http/v1/amtexplorer_mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions internal/controller/http/v1/ciraconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/open-amt-cloud-toolkit/console/internal/entity/dto"
dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1"
"github.com/open-amt-cloud-toolkit/console/internal/usecase/ciraconfigs"
"github.com/open-amt-cloud-toolkit/console/pkg/logger"
)
Expand All @@ -29,8 +29,8 @@ func NewCIRAConfigRoutes(handler *gin.RouterGroup, t ciraconfigs.Feature, l logg
}

type CIRAConfigCountResponse struct {
Count int `json:"totalCount"`
Data []dto.CIRAConfig `json:"data"`
Count int `json:"totalCount"`
Data []dtov1.CIRAConfig `json:"data"`
}

func (r *ciraConfigRoutes) get(c *gin.Context) {
Expand Down Expand Up @@ -85,7 +85,7 @@ func (r *ciraConfigRoutes) getByName(c *gin.Context) {
}

func (r *ciraConfigRoutes) insert(c *gin.Context) {
var config dto.CIRAConfig
var config dtov1.CIRAConfig
if err := c.ShouldBindJSON(&config); err != nil {
r.l.Error(err, "http - CIRA configs - v1 - insert")
ErrorResponse(c, err)
Expand All @@ -105,7 +105,7 @@ func (r *ciraConfigRoutes) insert(c *gin.Context) {
}

func (r *ciraConfigRoutes) update(c *gin.Context) {
var config dto.CIRAConfig
var config dtov1.CIRAConfig
if err := c.ShouldBindJSON(&config); err != nil {
r.l.Error(err, "http - CIRA configs - v1 - update")
ErrorResponse(c, err)
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/http/v1/ciraconfigs_mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions internal/controller/http/v1/ciraconfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"github.com/open-amt-cloud-toolkit/console/internal/entity/dto"
dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1"
"github.com/open-amt-cloud-toolkit/console/internal/usecase/ciraconfigs"
"github.com/open-amt-cloud-toolkit/console/pkg/logger"
)
Expand Down Expand Up @@ -40,13 +40,13 @@ type ciraconfigTest struct {
url string
mock func(repo *MockCIRAConfigsFeature)
response interface{}
requestBody dto.CIRAConfig
requestBody dtov1.CIRAConfig
expectedCode int
}

var (
requestCIRAConfig = dto.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}
responseCIRAConfig = dto.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}
requestCIRAConfig = dtov1.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}
responseCIRAConfig = dtov1.CIRAConfig{ConfigName: "ciraconfig", MPSAddress: "https://example.com", MPSPort: 4433, Username: "username", Password: "password", CommonName: "example.com", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"}
)

func TestCIRAConfigRoutes(t *testing.T) {
Expand All @@ -58,24 +58,24 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodGet,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dto.CIRAConfig{{
ciraconfig.EXPECT().Get(context.Background(), 25, 0, "").Return([]dtov1.CIRAConfig{{
ConfigName: "config",
}}, nil)
},
response: []dto.CIRAConfig{{ConfigName: "config"}},
response: []dtov1.CIRAConfig{{ConfigName: "config"}},
expectedCode: http.StatusOK,
},
{
name: "get all ciraconfigs - with count",
method: http.MethodGet,
url: "/api/v1/admin/ciraconfigs?$top=10&$skip=1&$count=true",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dto.CIRAConfig{{
ciraconfig.EXPECT().Get(context.Background(), 10, 1, "").Return([]dtov1.CIRAConfig{{
ConfigName: "config",
}}, nil)
ciraconfig.EXPECT().GetCount(context.Background(), "").Return(1, nil)
},
response: CIRAConfigCountResponse{Count: 1, Data: []dto.CIRAConfig{{ConfigName: "config"}}},
response: CIRAConfigCountResponse{Count: 1, Data: []dtov1.CIRAConfig{{ConfigName: "config"}}},
expectedCode: http.StatusOK,
},
{
Expand All @@ -93,11 +93,11 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodGet,
url: "/api/v1/admin/ciraconfigs/profile",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dto.CIRAConfig{
ciraconfig.EXPECT().GetByName(context.Background(), "profile", "").Return(&dtov1.CIRAConfig{
ConfigName: "config",
}, nil)
},
response: dto.CIRAConfig{ConfigName: "config"},
response: dtov1.CIRAConfig{ConfigName: "config"},
expectedCode: http.StatusOK,
},
{
Expand All @@ -115,7 +115,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodPost,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfigTest := &dto.CIRAConfig{
ciraconfigTest := &dtov1.CIRAConfig{
ConfigName: "ciraconfig",
MPSAddress: "https://example.com",
MPSPort: 4433,
Expand All @@ -141,7 +141,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodPost,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfigTest := &dto.CIRAConfig{
ciraconfigTest := &dtov1.CIRAConfig{
ConfigName: "ciraconfig",
MPSAddress: "https://example.com",
MPSPort: 4433,
Expand All @@ -167,7 +167,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodPost,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfig400Test := &dto.CIRAConfig{
ciraconfig400Test := &dtov1.CIRAConfig{
ConfigName: "ciraconfig",
ServerAddressFormat: 201,
AuthMethod: 2,
Expand All @@ -180,7 +180,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
ciraconfig.EXPECT().Insert(context.Background(), ciraconfig400Test).Return(nil, ciraconfigs.ErrDatabase)
},
response: ciraconfigs.ErrDatabase,
requestBody: dto.CIRAConfig{ConfigName: "ciraconfig", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"},
requestBody: dtov1.CIRAConfig{ConfigName: "ciraconfig", ServerAddressFormat: 201, AuthMethod: 2, MPSRootCertificate: "-----BEGIN CERTIFICATE-----\n...", ProxyDetails: "http://example.com", TenantID: "abc123", RegeneratePassword: true, Version: "1.0.0"},
expectedCode: http.StatusBadRequest,
},
{
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodPatch,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfigTest := &dto.CIRAConfig{
ciraconfigTest := &dtov1.CIRAConfig{
ConfigName: "ciraconfig",
MPSAddress: "https://example.com",
MPSPort: 4433,
Expand All @@ -234,7 +234,7 @@ func TestCIRAConfigRoutes(t *testing.T) {
method: http.MethodPatch,
url: "/api/v1/admin/ciraconfigs",
mock: func(ciraconfig *MockCIRAConfigsFeature) {
ciraconfigTest := &dto.CIRAConfig{
ciraconfigTest := &dtov1.CIRAConfig{
ConfigName: "ciraconfig",
MPSAddress: "https://example.com",
MPSPort: 4433,
Expand Down
18 changes: 9 additions & 9 deletions internal/controller/http/v1/devicemanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/open-amt-cloud-toolkit/console/internal/entity/dto"
dtov1 "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1"
"github.com/open-amt-cloud-toolkit/console/internal/usecase/amtexplorer"
"github.com/open-amt-cloud-toolkit/console/internal/usecase/devices"
"github.com/open-amt-cloud-toolkit/console/pkg/logger"
Expand Down Expand Up @@ -60,15 +60,15 @@ func NewAmtRoutes(handler *gin.RouterGroup, d devices.Feature, amt amtexplorer.F
func (r *deviceManagementRoutes) getVersion(c *gin.Context) {
guid := c.Param("guid")

version, err := r.d.GetVersion(c.Request.Context(), guid)
versionv1, _, err := r.d.GetVersion(c.Request.Context(), guid)
if err != nil {
r.l.Error(err, "http - v1 - GetVersion")
ErrorResponse(c, err)

return
}

c.JSON(http.StatusOK, version)
c.JSON(http.StatusOK, versionv1)
}

func (r *deviceManagementRoutes) getFeatures(c *gin.Context) {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (r *deviceManagementRoutes) getFeatures(c *gin.Context) {
func (r *deviceManagementRoutes) setFeatures(c *gin.Context) {
guid := c.Param("guid")

var features dto.Features
var features dtov1.Features

if err := c.ShouldBindJSON(&features); err != nil {
ErrorResponse(c, err)
Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *deviceManagementRoutes) getAlarmOccurrences(c *gin.Context) {
func (r *deviceManagementRoutes) createAlarmOccurrences(c *gin.Context) {
guid := c.Param("guid")

alarm := &dto.AlarmClockOccurrence{}
alarm := &dtov1.AlarmClockOccurrence{}
if err := c.ShouldBindJSON(alarm); err != nil {
ErrorResponse(c, err)

Expand All @@ -154,7 +154,7 @@ func (r *deviceManagementRoutes) createAlarmOccurrences(c *gin.Context) {
func (r *deviceManagementRoutes) deleteAlarmOccurrences(c *gin.Context) {
guid := c.Param("guid")

alarm := dto.DeleteAlarmOccurrenceRequest{}
alarm := dtov1.DeleteAlarmOccurrenceRequest{}
if err := c.ShouldBindJSON(&alarm); err != nil {
ErrorResponse(c, err)

Expand Down Expand Up @@ -277,7 +277,7 @@ func (r *deviceManagementRoutes) getUserConsentCode(c *gin.Context) {
func (r *deviceManagementRoutes) sendConsentCode(c *gin.Context) {
guid := c.Param("guid")

var userConsent dto.UserConsent
var userConsent dtov1.UserConsent
if err := c.ShouldBindJSON(&userConsent); err != nil {
ErrorResponse(c, err)

Expand All @@ -298,7 +298,7 @@ func (r *deviceManagementRoutes) sendConsentCode(c *gin.Context) {
func (r *deviceManagementRoutes) powerAction(c *gin.Context) {
guid := c.Param("guid")

var powerAction dto.PowerAction
var powerAction dtov1.PowerAction
if err := c.ShouldBindJSON(&powerAction); err != nil {
ErrorResponse(c, err)

Expand Down Expand Up @@ -357,7 +357,7 @@ func (r *deviceManagementRoutes) getEventLog(c *gin.Context) {
func (r *deviceManagementRoutes) setBootOptions(c *gin.Context) {
guid := c.Param("guid")

var bootSetting dto.BootSetting
var bootSetting dtov1.BootSetting
if err := c.ShouldBindJSON(&bootSetting); err != nil {
ErrorResponse(c, err)

Expand Down
Loading

0 comments on commit b95e1c6

Please sign in to comment.