2023-11-26 13:02:01 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/url"
|
2023-12-01 11:59:27 +00:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
2023-11-26 13:02:01 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/errors"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
|
|
|
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VerificationClientDeps struct {
|
|
|
|
Logger *zap.Logger
|
|
|
|
URLs *models.VerificationMicroserviceURL
|
|
|
|
}
|
|
|
|
|
|
|
|
type VerificationClient struct {
|
|
|
|
logger *zap.Logger
|
|
|
|
urls *models.VerificationMicroserviceURL
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewVerificationClient(deps VerificationClientDeps) *VerificationClient {
|
|
|
|
if deps.Logger == nil {
|
|
|
|
log.Panicln("logger is nil on <NewVerificationClient>")
|
|
|
|
}
|
|
|
|
|
|
|
|
if deps.URLs == nil {
|
|
|
|
log.Panicln("urls is nil on <NewVerificationClient>")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &VerificationClient{
|
|
|
|
logger: deps.Logger,
|
|
|
|
urls: deps.URLs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (receiver *VerificationClient) GetVerification(ctx context.Context, userID string) (*models.Verification, errors.Error) {
|
|
|
|
verifURL, err := url.JoinPath(receiver.urls.Verification, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New(
|
|
|
|
fmt.Errorf("failed to join path on <GetVerification> of <VerificationClient>: %w", err),
|
|
|
|
errors.ErrInternalError,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err := client.Get[models.Verification, models.FastifyError](ctx, &client.RequestSettings{
|
|
|
|
URL: verifURL,
|
|
|
|
Headers: map[string]string{"Content-Type": "application/json"},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New(err, errors.ErrInternalError)
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Body, nil
|
|
|
|
}
|