summaryrefslogtreecommitdiffstats
path: root/internal/client/email.go
blob: a7000fe63c3614ea3035c8547970b2e846ac8aca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package client

import (
	"encoding/json"
	"fmt"
	"git.db.org.ai/dborg/internal/models"
	"strings"
)

func (c *Client) VerifyEmail(email string) (*models.EmailVerifyResponse, error) {
	email = strings.TrimSpace(email)
	if email == "" {
		return nil, fmt.Errorf("email address cannot be empty")
	}

	path := fmt.Sprintf("/email/verify/%s", email)
	data, err := c.Get(path, nil)
	if err != nil {
		return nil, err
	}

	var response models.EmailVerifyResponse
	if err := json.Unmarshal(data, &response); err != nil {
		return nil, fmt.Errorf("failed to parse email verification response: %w", err)
	}

	return &response, nil
}