Skip to content

Commit

Permalink
fix: update feature access dto
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Delange authored and carere committed Jan 13, 2025
1 parent ff269fb commit 9f2e035
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 2 additions & 6 deletions api/handle_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
20 changes: 18 additions & 2 deletions dto/organization_feature_access_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dto

import (
"github.com/checkmarble/marble-backend/models"
"github.com/checkmarble/marble-backend/utils"
)

type APIOrganizationFeatureAccess struct {
Expand All @@ -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,
}
}

0 comments on commit 9f2e035

Please sign in to comment.