Skip to content

Commit

Permalink
Make various times optional/pointers: Zeitraum, Rechnung, Reklamati…
Browse files Browse the repository at this point in the history
…on, Vertragskonditionen (always Start/End) (#206)
  • Loading branch information
qndaa authored Apr 12, 2023
1 parent 86a2948 commit 49cb527
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
13 changes: 7 additions & 6 deletions bo/preisblatt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hochfrequenz/go-bo4e/enum/rollencodetyp"
"github.com/hochfrequenz/go-bo4e/enum/sparte"
"github.com/hochfrequenz/go-bo4e/enum/waehrungseinheit"
"github.com/hochfrequenz/go-bo4e/internal"
"github.com/shopspring/decimal"
"reflect"
"strings"
Expand Down Expand Up @@ -47,8 +48,8 @@ func (s *Suite) Test_Preisblatt_Deserialization() {
Makoadresse: "[email protected]",
},
Gueltigkeit: com.Zeitraum{
Startzeitpunkt: time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC),
Startdatum: time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC)),
Startdatum: internal.Ptr(time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC)),
},
Preispositionen: []com.Preisposition{
{
Expand Down Expand Up @@ -155,10 +156,10 @@ func (s *Suite) Test_Successful_Preisblatt_Validation() {
Makoadresse: "[email protected]",
},
Gueltigkeit: com.Zeitraum{
Startzeitpunkt: time.Date(2021, 12, 31, 22, 00, 00, 00, time.UTC),
Startdatum: time.Date(2021, 12, 31, 22, 00, 00, 00, time.UTC),
Enddatum: time.Date(9999, 12, 31, 23, 59, 59, 00, time.UTC),
Endzeitpunkt: time.Date(9999, 12, 31, 23, 59, 59, 00, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 12, 31, 22, 00, 00, 00, time.UTC)),
Startdatum: internal.Ptr(time.Date(2021, 12, 31, 22, 00, 00, 00, time.UTC)),
Enddatum: internal.Ptr(time.Date(9999, 12, 31, 23, 59, 59, 00, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(9999, 12, 31, 23, 59, 59, 00, time.UTC)),
},
Preispositionen: []com.Preisposition{},
},
Expand Down
8 changes: 4 additions & 4 deletions bo/rechnung_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ var serializableRechnung = bo.Rechnung{
Rechnungsperiode: com.Zeitraum{
Einheit: zeiteinheit.MINUTE,
Dauer: decimal.NullDecimal{},
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
Buchungsdatum: time.Date(2022, 9, 22, 0, 0, 0, 0, time.UTC),
Rechnungsersteller: bo.Geschaeftspartner{
Expand Down Expand Up @@ -290,8 +290,8 @@ var completeValidRechnung = bo.Rechnung{
Rechnungsperiode: com.Zeitraum{
Einheit: zeiteinheit.MINUTE,
Dauer: decimal.NewNullDecimal(decimal.NewFromFloat(15)),
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
Rechnungsersteller: bo.Geschaeftspartner{
Geschaeftsobjekt: bo.Geschaeftsobjekt{
Expand Down
11 changes: 6 additions & 5 deletions bo/reklamation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hochfrequenz/go-bo4e/enum/botyp"
"github.com/hochfrequenz/go-bo4e/enum/lokationstyp"
"github.com/hochfrequenz/go-bo4e/enum/reklamationsgrund"
"github.com/hochfrequenz/go-bo4e/internal"

"reflect"
"time"
Expand All @@ -28,7 +29,7 @@ func (s *Suite) Test_Reklamation_Deserialization() {
LokationsTyp: lokationstyp.MALO,
ObisKennzahl: obis("1-0:1.8.0"),
ZeitraumMesswertanfrage: com.Zeitraum{
Startzeitpunkt: time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC)),
}.AsPointer(),
Reklamationsgrund: reklamationsgrund.WERTE_FEHLEN,
}
Expand Down Expand Up @@ -79,10 +80,10 @@ func (s *Suite) Test_Successful_Reklamation_Validation() {
LokationsTyp: lokationstyp.MALO,
ObisKennzahl: obis("1-0:1.8.0"),
ZeitraumMesswertanfrage: com.Zeitraum{
Startzeitpunkt: time.Date(2021, 11, 30, 22, 0, 0, 0, time.UTC),
Startdatum: time.Date(2021, 11, 30, 22, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC),
Enddatum: time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 11, 30, 22, 0, 0, 0, time.UTC)),
Startdatum: internal.Ptr(time.Date(2021, 11, 30, 22, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2021, 12, 31, 22, 0, 0, 0, time.UTC)),
}.AsPointer(),
Reklamationsgrund: reklamationsgrund.WERTE_FEHLEN,
},
Expand Down
19 changes: 10 additions & 9 deletions com/vertragskonditionen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-playground/validator/v10"
"github.com/hochfrequenz/go-bo4e/com"
"github.com/hochfrequenz/go-bo4e/enum/zeiteinheit"
"github.com/hochfrequenz/go-bo4e/internal"
"github.com/shopspring/decimal"
"strings"
"time"
Expand All @@ -20,16 +21,16 @@ var validVertragskonditionen = com.Vertragskonditionen{
Dauer: decimal.NewNullDecimal(decimal.NewFromFloat(15)),
},
Kuendigungsfrist: &com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startdatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Enddatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
Startdatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
Vertragsverlaengerung: &com.Zeitraum{
Startzeitpunkt: time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startdatum: time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC),
Enddatum: time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
Startdatum: internal.Ptr(time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2022, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
Abschlagszyklus: &com.Zeitraum{
Einheit: zeiteinheit.JAHR,
Expand Down Expand Up @@ -58,7 +59,7 @@ func (s *Suite) Test_Vertragskonditionen_Failed_Validation() {
com.Vertragskonditionen{
// is only invalid if a zeitraum is invalid
Vertragslaufzeit: &com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions com/zeitraum.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
type Zeitraum struct {
Einheit zeiteinheit.Zeiteinheit `json:"zeiteinheit,omitempty" validate:"omitempty,required_with=Dauer"` // Einheit is the unit of measurement
Dauer decimal.NullDecimal `json:"dauer,omitempty" validate:"omitempty,required_with=Einheit"` // Dauer ist eh duration
Startdatum time.Time `json:"startdatum,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Startdatum is the day and time of begin
Enddatum time.Time `json:"enddatum,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Enddatum is the day and time of end
Startzeitpunkt time.Time `json:"startzeitpunkt,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Startzeitpunkt is the inclusive begin
Endzeitpunkt time.Time `json:"endzeitpunkt,omitempty" validate:"required_with=Startzeitpunkt,omitempty,gtfield=Startzeitpunkt" example:"2018-01-28T10:30:00+01"` // Endzeitpunkt is the exclusive end
Startdatum *time.Time `json:"startdatum,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Startdatum is the day and time of begin
Enddatum *time.Time `json:"enddatum,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Enddatum is the day and time of end
Startzeitpunkt *time.Time `json:"startzeitpunkt,omitempty" validate:"required_without_all=Einheit Dauer" example:"2018-01-28T10:15:00+01"` // Startzeitpunkt is the inclusive begin
Endzeitpunkt *time.Time `json:"endzeitpunkt,omitempty" validate:"required_with=Startzeitpunkt,omitempty,gtfield=Startzeitpunkt" example:"2018-01-28T10:30:00+01"` // Endzeitpunkt is the exclusive end
}

func (zeitraum Zeitraum) AsPointer() *Zeitraum {
Expand Down
35 changes: 18 additions & 17 deletions com/zeitraum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-playground/validator/v10"
"github.com/hochfrequenz/go-bo4e/com"
"github.com/hochfrequenz/go-bo4e/enum/zeiteinheit"
"github.com/hochfrequenz/go-bo4e/internal"
"github.com/shopspring/decimal"
"strings"
"time"
Expand All @@ -17,10 +18,10 @@ func (s *Suite) Test_Zeitraum_Deserialization() {
var zeitraum = com.Zeitraum{
Einheit: zeiteinheit.MINUTE,
Dauer: decimal.NewNullDecimal(decimal.NewFromFloat(15)),
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Startdatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Enddatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Startdatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
}
serializedZeitraum, err := json.Marshal(zeitraum)
jsonString := string(serializedZeitraum)
Expand All @@ -36,8 +37,8 @@ func (s *Suite) Test_Zeitraum_Deserialization() {
// TestZeitraumDeserializationWithoutEinheit
func (s *Suite) Test_Zeitraum_DeserializationWithoutEinheit() {
var zeitraum = com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
}
serializedZeitraum, err := json.Marshal(zeitraum)
jsonString := string(serializedZeitraum)
Expand All @@ -56,13 +57,13 @@ func (s *Suite) Test_Zeitraum_Failed_Validation() {
invalidZeitraums := map[string][]interface{}{
"required_with": {
com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
},
},
"gtfield": {
com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2020, 8, 1, 0, 0, 0, 0, time.UTC),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2020, 8, 1, 0, 0, 0, 0, time.UTC)),
},
},
}
Expand All @@ -76,20 +77,20 @@ func (s *Suite) Test_Successful_Zeitraum_Validation() {
com.Zeitraum{
Einheit: zeiteinheit.Zeiteinheit(0),
Dauer: decimal.NewNullDecimal(decimal.NewFromFloat(15)),
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Startdatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Enddatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Startdatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
com.Zeitraum{
Einheit: zeiteinheit.MINUTE,
Dauer: decimal.NewNullDecimal(decimal.NewFromFloat(15)),
},
com.Zeitraum{
Startzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Endzeitpunkt: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startdatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC),
Enddatum: time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15),
Startzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Endzeitpunkt: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
Startdatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC)),
Enddatum: internal.Ptr(time.Date(2021, 8, 1, 0, 0, 0, 0, time.UTC).Add(time.Minute * 15)),
},
}
VerfiySuccessfulValidations(s, validate, validZeitraums)
Expand Down

0 comments on commit 49cb527

Please sign in to comment.