verification/internal/client/customer.go
Danil Solovyov 7d677a2d83 Version 0.1
2023-06-12 19:19:10 +05:00

53 lines
1.3 KiB
Go

package client
import (
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
"verification/internal/models"
)
type Customer struct {
logger *zap.Logger
address string
}
func NewCustomer(logger *zap.Logger, address string) *Customer {
return &Customer{logger: logger, address: address}
}
func (c *Customer) UpdateAccountVerification(userId, status string) (*models.RespUpdateVerificationStatus, error) {
agent := fiber.Patch(fmt.Sprintf("%s/account/%s", c.address, userId))
agent.JSON(&models.ReqCreateVerification{Status: status})
err := agent.Parse()
if err != nil {
c.logger.Error("CustomerUpdateAccountVerification", zap.Error(err))
return nil, err
}
var resp models.RespUpdateVerificationStatus
statusCode, body, errs := agent.Struct(&resp)
if errs != nil || len(errs) > 0 {
for _, err := range errs {
c.logger.Error("CustomerUpdateAccountVerification", zap.Error(err))
}
return nil, errs[0]
}
if statusCode != 200 {
var respErr models.RespUpdateVerificationStatusError
err = json.Unmarshal(body, &respErr)
if err != nil {
c.logger.Error("CustomerUpdateAccountVerification", zap.Error(err))
return nil, err
}
return nil, fmt.Errorf("got bad status: %v | %v", respErr.StatusCode, respErr.Message)
}
return &resp, nil
}