From bb88dfd7e9495e0865e8b7486487028d04954d84 Mon Sep 17 00:00:00 2001 From: Pascal Delange Date: Thu, 9 Jan 2025 14:23:51 +0100 Subject: [PATCH] fix: update feature access dto --- api/handle_organization.go | 8 ++------ dto/organization_feature_access_dto.go | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/api/handle_organization.go b/api/handle_organization.go index ae5e4694..b195415c 100644 --- a/api/handle_organization.go +++ b/api/handle_organization.go @@ -9,7 +9,6 @@ import ( "github.com/checkmarble/marble-backend/models" "github.com/checkmarble/marble-backend/pure_utils" "github.com/checkmarble/marble-backend/usecases" - "github.com/checkmarble/marble-backend/utils" ) func handleGetOrganizations(uc usecases.Usecases) func(c *gin.Context) { @@ -131,11 +130,8 @@ func handlePatchOrganizationFeatureAccess(uc usecases.Usecases) func(c *gin.Cont } usecase := usecasesWithCreds(ctx, uc).NewOrganizationUseCase() - err := usecase.UpdateOrganizationFeatureAccess(ctx, models.UpdateOrganizationFeatureAccessInput{ - OrganizationId: organizationID, - TestRun: utils.Ptr(models.FeatureAccessFrom(data.TestRun)), - Sanctions: utils.Ptr(models.FeatureAccessFrom(data.Sanctions)), - }) + err := usecase.UpdateOrganizationFeatureAccess(ctx, + dto.AdaptUpdateOrganizationFeatureAccessInput(data, organizationID)) if presentError(ctx, c, err) { return } diff --git a/dto/organization_feature_access_dto.go b/dto/organization_feature_access_dto.go index cecd9cf3..38b710c0 100644 --- a/dto/organization_feature_access_dto.go +++ b/dto/organization_feature_access_dto.go @@ -2,6 +2,7 @@ package dto import ( "github.com/checkmarble/marble-backend/models" + "github.com/checkmarble/marble-backend/utils" ) type APIOrganizationFeatureAccess struct { @@ -27,6 +28,21 @@ func AdaptOrganizationFeatureAccessDto(f models.OrganizationFeatureAccess) APIOr } type UpdateOrganizationFeatureAccessBodyDto struct { - TestRun string `json:"test_run"` - Sanctions string `json:"sanctions"` + TestRun *string `json:"test_run"` + Sanctions *string `json:"sanctions"` +} + +func AdaptUpdateOrganizationFeatureAccessInput(f UpdateOrganizationFeatureAccessBodyDto, orgId string) models.UpdateOrganizationFeatureAccessInput { + var testRun, sanctions *models.FeatureAccess + if f.TestRun != nil { + testRun = utils.Ptr(models.FeatureAccessFrom(*f.TestRun)) + } + if f.Sanctions != nil { + sanctions = utils.Ptr(models.FeatureAccessFrom(*f.Sanctions)) + } + return models.UpdateOrganizationFeatureAccessInput{ + OrganizationId: orgId, + TestRun: testRun, + Sanctions: sanctions, + } }