57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/gofiber/fiber/v2"
|
|
"go.uber.org/zap"
|
|
"gitea.pena/PenaSide/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, token string) (*models.RespUpdateVerificationStatus, error) {
|
|
agent := fiber.Patch(fmt.Sprintf("%s/account/%s", c.address, userId)).Set("Authorization", token)
|
|
fmt.Println("PATCHED", 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
|
|
}
|
|
|
|
err = fmt.Errorf("got bad status: %v | %v", respErr.StatusCode, respErr.Message)
|
|
c.logger.Error("CustomerUpdateAccountVerification", zap.Error(err))
|
|
|
|
return nil, err
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|