generated from PenaSide/GolangTemplate
--
This commit is contained in:
parent
cd561b2c3d
commit
eb8ad44a11
@ -31,7 +31,7 @@ services:
|
|||||||
- PAYMENT_MICROSERVICE_GRPC_HOST=10.6.0.11:9085
|
- PAYMENT_MICROSERVICE_GRPC_HOST=10.6.0.11:9085
|
||||||
- VERIFICATION_MICROSERVICE_USER_URL=http://10.6.0.11:7035/verification
|
- VERIFICATION_MICROSERVICE_USER_URL=http://10.6.0.11:7035/verification
|
||||||
- TEMPLATEGEN_MICROSERVICE_URL=10.6.0.17
|
- TEMPLATEGEN_MICROSERVICE_URL=10.6.0.17
|
||||||
- API_URL=connect.mailclient.bz
|
- API_URL=https://api.smtp.bz/v1/smtp/send
|
||||||
- MAIL_SENDER=noreply@mailing.pena.digital
|
- MAIL_SENDER=noreply@mailing.pena.digital
|
||||||
- MAIL_API_KEY=P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev
|
- MAIL_API_KEY=P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev
|
||||||
- MAIL_AUTH_USERNAME=kotilion.95@gmail.com
|
- MAIL_AUTH_USERNAME=kotilion.95@gmail.com
|
||||||
|
@ -63,6 +63,7 @@ func (receiver *MailClient) SendMessage(userEmail string, verification *models.V
|
|||||||
return handleError(receiver.deps.Logger, "Error closing form writer", err)
|
return handleError(receiver.deps.Logger, "Error closing form writer", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("SEEEEEND", receiver.deps.ApiUrl)
|
||||||
req := receiver.deps.FiberClient.Post(receiver.deps.ApiUrl).Body(form.Bytes()).ContentType(writer.FormDataContentType())
|
req := receiver.deps.FiberClient.Post(receiver.deps.ApiUrl).Body(form.Bytes()).ContentType(writer.FormDataContentType())
|
||||||
if receiver.deps.ApiKey != "" {
|
if receiver.deps.ApiKey != "" {
|
||||||
req.Set("Authorization", receiver.deps.ApiKey)
|
req.Set("Authorization", receiver.deps.ApiKey)
|
||||||
|
@ -23,7 +23,6 @@ type VerificationClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewVerificationClient(deps VerificationClientDeps) *VerificationClient {
|
func NewVerificationClient(deps VerificationClientDeps) *VerificationClient {
|
||||||
fmt.Println("AAAAAABAAAAa", deps)
|
|
||||||
if deps.Logger == nil {
|
if deps.Logger == nil {
|
||||||
log.Panicln("logger is nil on <NewVerificationClient>")
|
log.Panicln("logger is nil on <NewVerificationClient>")
|
||||||
}
|
}
|
||||||
@ -38,8 +37,7 @@ func NewVerificationClient(deps VerificationClientDeps) *VerificationClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *VerificationClient) GetVerification(ctx context.Context, userID string) (*models.Verification, errors.Error) {
|
func (receiver *VerificationClient) GetVerification(ctx context.Context, token, userID string) (*models.Verification, errors.Error) {
|
||||||
fmt.Println("AAAAAAAAAAAa", receiver)
|
|
||||||
verifURL, err := url.JoinPath(receiver.urls.Verification, userID)
|
verifURL, err := url.JoinPath(receiver.urls.Verification, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(
|
return nil, errors.New(
|
||||||
@ -50,9 +48,13 @@ func (receiver *VerificationClient) GetVerification(ctx context.Context, userID
|
|||||||
|
|
||||||
response, err := client.Get[models.Verification, models.FastifyError](ctx, &client.RequestSettings{
|
response, err := client.Get[models.Verification, models.FastifyError](ctx, &client.RequestSettings{
|
||||||
URL: verifURL,
|
URL: verifURL,
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": token,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("AAAAAAAAAAAa", err, verifURL, response)
|
||||||
if response.StatusCode == 404 {
|
if response.StatusCode == 404 {
|
||||||
return nil, errors.New(err, errors.ErrNotFound)
|
return nil, errors.New(err, errors.ErrNotFound)
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,10 @@ func (receiver *Controller) PostWalletRspay(ctx echo.Context) error {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := receiver.walletService.PostWalletRspay(ctx.Request().Context(), userID, req); err != nil {
|
token := ctx.Request().Header.Get("Authorization")
|
||||||
|
fmt.Println("HEADERS", ctx.Request().Header)
|
||||||
|
|
||||||
|
if err := receiver.walletService.PostWalletRspay(ctx.Request().Context(), token, userID, req); err != nil {
|
||||||
if err == errors.ErrNoAccess {
|
if err == errors.ErrNoAccess {
|
||||||
return errors.HTTP(ctx, err)
|
return errors.HTTP(ctx, err)
|
||||||
}
|
}
|
||||||
|
@ -705,8 +705,10 @@ func (api *API2) SendReport(ctx echo.Context) error {
|
|||||||
)
|
)
|
||||||
return api.errorOld(ctx, err)
|
return api.errorOld(ctx, err)
|
||||||
}
|
}
|
||||||
|
token := ctx.Request().Header.Get("Authorization")
|
||||||
|
fmt.Println("HEADERS", ctx.Request().Header)
|
||||||
|
|
||||||
verifuser, err := api.clients.verify.GetVerification(ctx.Request().Context(), tariffs.UserID)
|
verifuser, err := api.clients.verify.GetVerification(ctx.Request().Context(),token, tariffs.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.logger.Error("failed to get user verification on <GetHistoryById> of <HistoryService>",
|
api.logger.Error("failed to get user verification on <GetHistoryById> of <HistoryService>",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
@ -785,8 +787,10 @@ func (api *API2) PostWalletRspay(ctx echo.Context) error {
|
|||||||
if user.Status != models.AccountStatusNko && user.Status != models.AccountStatusOrg {
|
if user.Status != models.AccountStatusNko && user.Status != models.AccountStatusOrg {
|
||||||
return api.error(ctx, http.StatusForbidden, "not allowed for non organizations")
|
return api.error(ctx, http.StatusForbidden, "not allowed for non organizations")
|
||||||
}
|
}
|
||||||
|
token := ctx.Request().Header.Get("Authorization")
|
||||||
|
fmt.Println("HEADERS", ctx.Request().Header)
|
||||||
|
|
||||||
verification, err := api.clients.verify.GetVerification(ctx.Request().Context(), userID)
|
verification, err := api.clients.verify.GetVerification(ctx.Request().Context(),token, userID)
|
||||||
if err == errors.ErrNotFound {
|
if err == errors.ErrNotFound {
|
||||||
return api.error(ctx, http.StatusForbidden, "no verification data found")
|
return api.error(ctx, http.StatusForbidden, "no verification data found")
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ type currencyClient interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type verificationClient interface {
|
type verificationClient interface {
|
||||||
GetVerification(ctx context.Context, userID string) (*models.Verification, errors.Error)
|
GetVerification(ctx context.Context, token, userID string) (*models.Verification, errors.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type authClient interface {
|
type authClient interface {
|
||||||
@ -55,7 +55,6 @@ type Service struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(deps Deps) *Service {
|
func New(deps Deps) *Service {
|
||||||
fmt.Println("AAAAABBAAAAa", deps)
|
|
||||||
if deps.Logger == nil {
|
if deps.Logger == nil {
|
||||||
log.Panicln("logger is nil on <New (wallet service)>")
|
log.Panicln("logger is nil on <New (wallet service)>")
|
||||||
}
|
}
|
||||||
@ -286,7 +285,7 @@ func (receiver *Service) ChangeCurrency(ctx context.Context, userID string, curr
|
|||||||
return updatedAccount, nil
|
return updatedAccount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *Service) PostWalletRspay(ctx context.Context, userID string, req swagger.PostWalletRspayJSONBody) errors.Error {
|
func (receiver *Service) PostWalletRspay(ctx context.Context, token, userID string, req swagger.PostWalletRspayJSONBody) errors.Error {
|
||||||
user, err := receiver.repository.FindByUserID(ctx, userID)
|
user, err := receiver.repository.FindByUserID(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -298,8 +297,7 @@ func (receiver *Service) PostWalletRspay(ctx context.Context, userID string, req
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("AAAAABBBAAAa", receiver.verificationClient)
|
verification, err := receiver.verificationClient.GetVerification(ctx, token, userID)
|
||||||
verification, err := receiver.verificationClient.GetVerification(ctx, userID)
|
|
||||||
if err == errors.ErrNotFound {
|
if err == errors.ErrNotFound {
|
||||||
return errors.New(
|
return errors.New(
|
||||||
fmt.Errorf("no verification data found"),
|
fmt.Errorf("no verification data found"),
|
||||||
|
@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
@ -43,6 +44,7 @@ func makeRequest[T any, R any](url string, requestMethod func(url string) (*rest
|
|||||||
Error: responseBody,
|
Error: responseBody,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
fmt.Println("OOOOO", responseInstance.RawResponse)
|
||||||
|
|
||||||
responseBody, parseErr := parseResponse[T](responseInstance.Body(), responseInstance.RawResponse)
|
responseBody, parseErr := parseResponse[T](responseInstance.Body(), responseInstance.RawResponse)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
|
@ -3,12 +3,14 @@ package client
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/json"
|
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseResponse[T any](body []byte, response *http.Response) (*T, error) {
|
func parseResponse[T any](body []byte, response *http.Response) (*T, error) {
|
||||||
isJSONResponse := response.Header.Get("Content-Type") == "application/json"
|
isJSONResponse := response.Header.Get("Content-Type") == "application/json"
|
||||||
|
fmt.Println("1OOOO", response.Header.Get("Content-Type"), string(body))
|
||||||
|
|
||||||
if !isJSONResponse {
|
if !isJSONResponse {
|
||||||
responseBody, unmarshalErr := json.Unmarshal[T](body)
|
responseBody, unmarshalErr := json.Unmarshal[T](body)
|
||||||
|
Loading…
Reference in New Issue
Block a user