From a79499348ee63b5847187eb10b947453fd6f546a Mon Sep 17 00:00:00 2001 From: Carl Allen Date: Thu, 30 Jan 2025 09:42:31 -0600 Subject: [PATCH] Fix GetDNSRecord --- unifi/dns_record.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/unifi/dns_record.go b/unifi/dns_record.go index 0185e66..056b343 100644 --- a/unifi/dns_record.go +++ b/unifi/dns_record.go @@ -63,19 +63,22 @@ func (c *Client) ListDNSRecord(ctx context.Context, site string) ([]DNSRecord, e } func (c *Client) GetDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) { - var respBody DNSRecord - - err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, id), nil, &respBody) + respBody, err := c.ListDNSRecord(ctx, site) if err != nil { return nil, err } - // if len(respBody.Data) != 1 { - // return nil, &NotFoundError{} - // } + if len(respBody) == 0 { + return nil, &NotFoundError{} + } - // d := respBody.Data[0] - return &respBody, nil + for _, dns := range respBody { + if dns.ID == id { + return &dns, nil + } + } + + return nil, &NotFoundError{} } func (c *Client) DeleteDNSRecord(ctx context.Context, site, id string) error {