verification/internal/client/customer.go

57 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-06-12 14:19:10 +00:00
package client
import (
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
2024-11-21 07:29:18 +00:00
"gitea.pena/PenaSide/verification/internal/models"
2023-06-12 14:19:10 +00:00
)
type Customer struct {
logger *zap.Logger
address string
}
func NewCustomer(logger *zap.Logger, address string) *Customer {
return &Customer{logger: logger, address: address}
}
2024-02-01 11:39:55 +00:00
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))
2023-06-12 14:19:10 +00:00
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
2023-06-12 14:19:10 +00:00
}
return &resp, nil
}