From d679015df43d25a2c35092eecf133f815ed4e3b1 Mon Sep 17 00:00:00 2001 From: Erik Unger Date: Wed, 6 Nov 2024 14:14:34 +0100 Subject: [PATCH] added domonda.ObjectTenantOwner --- go.work.sum | 2 + golang/domonda/go.mod | 4 +- golang/domonda/go.sum | 4 ++ golang/domonda/objecttenantowner.go | 58 +++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 golang/domonda/objecttenantowner.go diff --git a/go.work.sum b/go.work.sum index 635452e..d6583a0 100644 --- a/go.work.sum +++ b/go.work.sum @@ -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= diff --git a/golang/domonda/go.mod b/golang/domonda/go.mod index 17ce539..b2e8823 100644 --- a/golang/domonda/go.mod +++ b/golang/domonda/go.mod @@ -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 ( @@ -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 diff --git a/golang/domonda/go.sum b/golang/domonda/go.sum index 5f81564..c598b47 100644 --- a/golang/domonda/go.sum +++ b/golang/domonda/go.sum @@ -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= @@ -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= diff --git a/golang/domonda/objecttenantowner.go b/golang/domonda/objecttenantowner.go new file mode 100644 index 0000000..286177a --- /dev/null +++ b/golang/domonda/objecttenantowner.go @@ -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 +}