Skip to content

Commit

Permalink
Merge pull request #187 from LerianStudio/fix/MZ-623
Browse files Browse the repository at this point in the history
Fix/MZ-623
  • Loading branch information
maxwelbm authored Nov 4, 2024
2 parents dc0c342 + 93a995e commit 8e6076c
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 493 deletions.
Binary file modified components/mdz/bin/mdz
Binary file not shown.
6 changes: 3 additions & 3 deletions components/mdz/internal/model/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ type Organization struct {
ParentOrganizationID *string `json:"parentOrganizationId,omitempty"`
DoingBusinessAs string `json:"doingBusinessAs"`
LegalDocument string `json:"legalDocument"`
Status Status `json:"status"`
Status *Status `json:"status"`
Address Address `json:"address"`
Metadata *Metadata `json:"metadata,omitempty"`
}

type Status struct {
Code *string `json:"code,omitempty"`
Description string `json:"description"`
Description *string `json:"description"`
}

type Address struct {
Expand Down Expand Up @@ -61,7 +61,7 @@ type OrganizationItem struct {
DoingBusinessAs string `json:"doingBusinessAs"`
LegalDocument string `json:"legalDocument"`
Address Address `json:"address"`
Status Status `json:"status"`
Status *Status `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
Expand Down
10 changes: 5 additions & 5 deletions components/mdz/internal/rest/organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func TestCreateOrganization(t *testing.T) {
LegalName: "Corwin LLC",
DoingBusinessAs: "The ledger.io",
LegalDocument: "48784548000104",
Status: model.Status{
Status: &model.Status{
Code: ptr.StringPtr("ACTIVE"),
Description: "Teste Ledger",
Description: ptr.StringPtr("Teste Ledger"),
},
Address: model.Address{
Line1: ptr.StringPtr("Avenida Paulista, 1234"),
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestCreateOrganization(t *testing.T) {
},
Status: model.Status{
Code: ptr.StringPtr("ACTIVE"),
Description: "Teste Ledger",
Description: ptr.StringPtr("Teste Ledger"),
},
Metadata: model.Metadata{
Chave: ptr.StringPtr("metadata_chave"),
Expand Down Expand Up @@ -249,9 +249,9 @@ func TestOrganizationUpdate(t *testing.T) {
State: ptr.StringPtr("MU"),
Country: "LV",
},
Status: model.Status{
Status: &model.Status{
Code: ptr.StringPtr("ACTIVE"),
Description: "Teste Ledger",
Description: ptr.StringPtr("Teste Ledger"),
},
}

Expand Down
79 changes: 50 additions & 29 deletions components/mdz/pkg/cmd/organization/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ func (f *factoryOrganizationCreate) runE(cmd *cobra.Command, _ []string) error {
}

func (f *factoryOrganizationCreate) createRequestFromFlags(org *model.Organization) error {
org.Status = model.Status{}
org.Address = model.Address{}

if org.Metadata == nil {
org.Metadata = &model.Metadata{}
}

var err error
org.LegalName, err = utils.AssignStringField(f.LegalName, "legal-name", f.tuiInput)

Expand All @@ -102,17 +97,19 @@ func (f *factoryOrganizationCreate) createRequestFromFlags(org *model.Organizati
return err
}

if len(f.Code) < 1 {
org.Status.Code = nil
} else {
org.Status.Code = &f.Code
}
var status *model.Status

org.Status.Description, err = utils.AssignStringField(f.Description, "description", f.tuiInput)
if err != nil {
return err
if len(f.Code) > 0 || len(f.Description) > 0 {
tempStatus := model.Status{}

tempStatus.Code = utils.AssignOptionalStringPtr(f.Code)
tempStatus.Description = utils.AssignOptionalStringPtr(f.Description)

status = &tempStatus
}

org.Status = status

org.Address.Line1 = utils.AssignOptionalStringPtr(f.Line1)
org.Address.Line2 = utils.AssignOptionalStringPtr(f.Line2)
org.Address.ZipCode = utils.AssignOptionalStringPtr(f.ZipCode)
Expand All @@ -124,32 +121,56 @@ func (f *factoryOrganizationCreate) createRequestFromFlags(org *model.Organizati
return err
}

if len(f.Chave) > 0 {
org.Metadata.Chave = &f.Chave
metadata, err := buildMetadataCreate(f)
if err != nil {
return err
}

if len(f.Bitcoin) > 0 {
org.Metadata.Bitcoin = &f.Bitcoin
org.Metadata = metadata

return nil
}

func buildMetadataCreate(f *factoryOrganizationCreate) (*model.Metadata, error) {
if len(f.Chave) == 0 && len(f.Bitcoin) == 0 && len(f.Boolean) == 0 && len(f.Double) == 0 && len(f.Int) == 0 {
return nil, nil
}

org.Metadata.Boolean, err = utils.ParseAndAssign(f.Boolean, strconv.ParseBool)
if err != nil {
return fmt.Errorf("invalid boolean field: %v", err)
tempMetadata := model.Metadata{}

tempMetadata.Chave = utils.AssignOptionalStringPtr(f.Chave)
tempMetadata.Bitcoin = utils.AssignOptionalStringPtr(f.Bitcoin)

if len(f.Boolean) > 0 {
var err error

tempMetadata.Boolean, err = utils.ParseAndAssign(f.Boolean, strconv.ParseBool)
if err != nil {
return nil, fmt.Errorf("invalid boolean field: %v", err)
}
}

org.Metadata.Double, err = utils.ParseAndAssign(f.Double, func(s string) (float64, error) {
return strconv.ParseFloat(s, 64)
})
if err != nil {
return fmt.Errorf("invalid double field: %v", err)
if len(f.Double) > 0 {
var err error
tempMetadata.Double, err = utils.ParseAndAssign(f.Double, func(s string) (float64, error) {
return strconv.ParseFloat(s, 64)
})

if err != nil {
return nil, fmt.Errorf("invalid double field: %v", err)
}
}

org.Metadata.Int, err = utils.ParseAndAssign(f.Int, strconv.Atoi)
if err != nil {
return fmt.Errorf("invalid int field: %v", err)
if len(f.Int) > 0 {
var err error

tempMetadata.Int, err = utils.ParseAndAssign(f.Int, strconv.Atoi)
if err != nil {
return nil, fmt.Errorf("invalid int field: %v", err)
}
}

return nil
return &tempMetadata, nil
}

func (f *factoryOrganizationCreate) setFlags(cmd *cobra.Command) {
Expand Down
Loading

0 comments on commit 8e6076c

Please sign in to comment.