-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |