Skip to content

Commit

Permalink
added domonda.ObjectTenantOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Nov 6, 2024
1 parent 47cd23f commit d679015
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/domonda/go-types v0.0.0-20241104173616-e85c6dede426 h1:pWWcXqt8jvIGsqpo+o2RPe1Rx5lyFRj6lUKN2sTJ+rU=
github.com/domonda/go-types v0.0.0-20241104173616-e85c6dede426/go.mod h1:QfZG5NrNWDrwcqOp3ZlNh2XaLjZI1ncNpGPAa9MIUUE=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
Expand Down
4 changes: 2 additions & 2 deletions golang/domonda/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23

require (
github.com/domonda/go-types v0.0.0-20241104173616-e85c6dede426
github.com/ungerik/go-fs v0.0.0-20241029181032-3e0bba4739a8
github.com/ungerik/go-fs v0.0.0-20241106120305-a6e3fe880888
)

require (
Expand All @@ -29,4 +29,4 @@ require (
mvdan.cc/xurls/v2 v2.5.0 // indirect
)

replace github.com/domonda/go-types => ../../../go-types
// replace github.com/domonda/go-types => ../../../go-types
4 changes: 4 additions & 0 deletions golang/domonda/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/domonda/go-types v0.0.0-20241001090154-50384689aa30 h1:XHFdfkOBZZibBe
github.com/domonda/go-types v0.0.0-20241001090154-50384689aa30/go.mod h1:QfZG5NrNWDrwcqOp3ZlNh2XaLjZI1ncNpGPAa9MIUUE=
github.com/domonda/go-types v0.0.0-20241104142400-8d1c15e5203e h1:vJz55QzCqiyqWXjJmTAH4FXqqKTfKHifowcu0Q7vt9s=
github.com/domonda/go-types v0.0.0-20241104142400-8d1c15e5203e/go.mod h1:QfZG5NrNWDrwcqOp3ZlNh2XaLjZI1ncNpGPAa9MIUUE=
github.com/domonda/go-types v0.0.0-20241104173616-e85c6dede426 h1:pWWcXqt8jvIGsqpo+o2RPe1Rx5lyFRj6lUKN2sTJ+rU=
github.com/domonda/go-types v0.0.0-20241104173616-e85c6dede426/go.mod h1:QfZG5NrNWDrwcqOp3ZlNh2XaLjZI1ncNpGPAa9MIUUE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
Expand Down Expand Up @@ -50,6 +52,8 @@ github.com/ungerik/go-fs v0.0.0-20240919125757-1b6f933a416d h1:71JniF82NUc6v7nBx
github.com/ungerik/go-fs v0.0.0-20240919125757-1b6f933a416d/go.mod h1:nMIa35zyLzk4K3tTLL+AAsOZ9Q+0lgX/lxYubEwCZSY=
github.com/ungerik/go-fs v0.0.0-20241029181032-3e0bba4739a8 h1:XvNOz9F2B021JmJc2lzAYG2wxQGfmckK3gLHiKJIrfY=
github.com/ungerik/go-fs v0.0.0-20241029181032-3e0bba4739a8/go.mod h1:nMIa35zyLzk4K3tTLL+AAsOZ9Q+0lgX/lxYubEwCZSY=
github.com/ungerik/go-fs v0.0.0-20241106120305-a6e3fe880888 h1:6Ffh2W28jVony006U2lKV25Jvvi7gm6IiX84E7JB1u0=
github.com/ungerik/go-fs v0.0.0-20241106120305-a6e3fe880888/go.mod h1:5e5pAtKSTbP0JOwYsKcVZS081IkuqOxdt4/V1sUjPgk=
github.com/ungerik/go-reflection v0.0.0-20240905081803-708928fe0862 h1:rxp/NtuHYkx0HRYL/Y7xh/07ZwI/Pbk3VPkVoq3IUgQ=
github.com/ungerik/go-reflection v0.0.0-20240905081803-708928fe0862/go.mod h1:Ic/uip1MCECqTPItawo5lRHmyaOT6vCM0UuKrczg6LY=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
Expand Down
58 changes: 58 additions & 0 deletions golang/domonda/objecttenantowner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package domonda

import (
"context"
"errors"
"fmt"
"net/url"

"github.com/domonda/go-types/account"
"github.com/domonda/go-types/notnull"
)

type ObjectTenantOwner struct {
ObjectNo account.Number
TenantOwnerNo int64
UnitNo int64
OwnerLinkNo int64
Owner notnull.TrimmedString
}

func (o *ObjectTenantOwner) Validate() error {
var (
err error
errs []error
)
if err = o.ObjectNo.Validate(); err != nil {
errs = append(errs, fmt.Errorf("ObjectTenantOwner.ObjectNo: %w", err))
}
if o.Owner.IsEmpty() {
errs = append(errs, errors.New("empty ObjectTenantOwner.Owner"))
}
return errors.Join(errs...)
}

func PostObjectTenantOwners(ctx context.Context, apiKey string, tenantOwners []*ObjectTenantOwner, source string) error {
var err error
for i, obj := range tenantOwners {
if e := obj.Validate(); e != nil {
err = errors.Join(err, fmt.Errorf("ObjectTenantOwner at index %d has error: %w", i, e))
}
}
if err != nil {
return err
}

vals := make(url.Values)
if source != "" {
vals.Set("source", source)
}
response, err := postJSON(ctx, apiKey, "/masterdata/real-estate-object-tenant-owners", vals, tenantOwners)
if err != nil {
return err
}
if response.StatusCode != 200 {
return fmt.Errorf("unexpected status code: %d", response.StatusCode)
}
return nil
}

0 comments on commit d679015

Please sign in to comment.