Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace for classification types #11

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions api/myDATA.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ paths:
- '{aade-user-id}'
type: string
default: '{aade-user-id}'
- name: nextPartitionKey
in: query
description: Παράμετρος για την τμηματική λήψη των αποτελεσμάτων
required: false
schema:
enum:
- '{nextPartitionKey}'
type: string
default: '{nextPartitionKey}'
- name: nextRowKey
in: query
description: Παράμετρος για την τμηματική λήψη των αποτελεσμάτων
required: false
schema:
enum:
- '{nextRowKey}'
type: string
default: '{nextRowKey}'
responses:
'200':
description:
Expand Down Expand Up @@ -98,6 +116,24 @@ paths:
enum:
- '{aade-user-id}'
type: string
- name: nextPartitionKey
in: query
description: Παράμετρος για την τμηματική λήψη των αποτελεσμάτων
required: false
schema:
enum:
- '{nextPartitionKey}'
type: string
default: '{nextPartitionKey}'
- name: nextRowKey
in: query
description: Παράμετρος για την τμηματική λήψη των αποτελεσμάτων
required: false
schema:
enum:
- '{nextRowKey}'
type: string
default: '{nextRowKey}'
responses:
'200':
description:
Expand Down
88 changes: 88 additions & 0 deletions internal/api/client.go

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

23 changes: 23 additions & 0 deletions pkg/models/expense_classification.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package models

import (
"encoding/xml"
"fmt"
)

type ExpensesClassificationsDoc struct {
ExpensesInvoiceClassification []ExpensesInvoiceClassification `xml:"ExpensesInvoiceClassification"`
}
Expand All @@ -16,3 +21,21 @@ type InvoicesExpensesClassificationDetails struct {
LineNumber uint `xml:"lineNumber"`
ExpensesClassificationDetailData []ExpensesClassificationType `xml:"ExpensesClassificationDetailData"`
}

// MarshalXML transforms an ExpensesClassificationType to expensesClassificationType and serializes it in order to
// include the `ecls` namespace for every field.
func (classification ExpensesClassificationType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
type expensesClassificationType struct {
ClassificationType string `xml:"ecls:classificationType"`
ClassificationCategory string `xml:"ecls:classificationCategory"`
Amount float64 `xml:"ecls:amount"`
ID *byte `xml:"ecls:id"`
}

err := enc.EncodeElement(expensesClassificationType(classification), start)
if err != nil {
return fmt.Errorf("xml marshal expense classification: %w", err)
}

return nil
}
28 changes: 28 additions & 0 deletions pkg/models/expense_classification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import (
"encoding/xml"
"testing"

"github.com/ppapapetrou76/go-testing/assert"
)

func TestExpensesClassificationType_MarshalXML(t *testing.T) {
t.Run("should have `ecls` namespace", func(t *testing.T) {
id := byte(1)
classification := ExpensesClassificationType{
ClassificationType: "type",
ClassificationCategory: "category",
Amount: 12,
ID: &id,
}

ft := assert.NewFluentT(t)

got, err := xml.Marshal(classification)
ft.AssertThat(err).IsNil()

want := []byte(`<ExpensesClassificationType><ecls:classificationType>type</ecls:classificationType><ecls:classificationCategory>category</ecls:classificationCategory><ecls:amount>12</ecls:amount><ecls:id>1</ecls:id></ExpensesClassificationType>`)
ft.AssertThat(got).IsEqualTo(want)
})
}
23 changes: 23 additions & 0 deletions pkg/models/income_classification.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package models

import (
"encoding/xml"
"fmt"
)

type IncomeClassificationsDoc struct {
IncomeInvoiceClassification []IncomeInvoiceClassification `xml:"incomeInvoiceClassification"`
}
Expand All @@ -16,3 +21,21 @@ type InvoicesIncomeClassificationDetails struct {
LineNumber uint `xml:"lineNumber"`
IncomeClassificationDetailData []IncomeClassificationType `xml:"incomeClassificationDetailData"`
}

// MarshalXML transforms an IncomeClassificationType to incomeClassificationType and serializes it in order to include
// the `icls` namespace for every field.
func (classification IncomeClassificationType) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
type incomeClassificationType struct {
ClassificationType string `xml:"icls:classificationType"`
ClassificationCategory string `xml:"icls:classificationCategory"`
Amount float64 `xml:"icls:amount"`
ID *byte `xml:"icls:id"`
}

err := enc.EncodeElement(incomeClassificationType(classification), start)
if err != nil {
return fmt.Errorf("xml marshal income classification: %w", err)
}

return nil
}
Comment on lines +27 to +41
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as ExpensesClassificationType reasoning

28 changes: 28 additions & 0 deletions pkg/models/income_classification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import (
"encoding/xml"
"testing"

"github.com/ppapapetrou76/go-testing/assert"
)

func TestIncomeClassificationType_MarshalXML(t *testing.T) {
t.Run("should have `icls` namespace", func(t *testing.T) {
id := byte(1)
classification := IncomeClassificationType{
ClassificationType: "type",
ClassificationCategory: "category",
Amount: 12,
ID: &id,
}

ft := assert.NewFluentT(t)

got, err := xml.Marshal(classification)
ft.AssertThat(err).IsNil()

want := []byte(`<IncomeClassificationType><icls:classificationType>type</icls:classificationType><icls:classificationCategory>category</icls:classificationCategory><icls:amount>12</icls:amount><icls:id>1</icls:id></IncomeClassificationType>`)
ft.AssertThat(got).IsEqualTo(want)
})
}
Loading