feat: history details

This commit is contained in:
Kirill 2023-09-10 14:54:41 +00:00 committed by Mikhail
parent 19f3fcbe69
commit f31b22c97d
5 changed files with 58 additions and 34 deletions

@ -7,7 +7,7 @@ type History struct {
UserID string `json:"userId" bson:"userId"`
Comment string `json:"comment" bson:"comment"`
Key string `json:"key" bson:"key"`
RawDetails string `json:"rawDetails" bson:"rawDetails"`
RawDetails any `json:"rawDetails" bson:"rawDetails"`
Deleted bool `json:"isDeleted" bson:"isDeleted"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`

@ -2,6 +2,7 @@ package callback
import (
"context"
"fmt"
"log"
"go.uber.org/zap"
@ -82,13 +83,16 @@ func (receiver *PaymentCallbackService) SuccessEvent(ctx context.Context, event
return err
}
go func() {
if _, err := receiver.historyService.CreateHistory(ctx, &models.History{
UserID: account.UserID,
Comment: event.Message,
Key: event.Key,
RawDetails: fmt.Sprintf("%d%s", event.Amount, event.Currency),
}); err != nil {
receiver.logger.Error("failed to create history on <SuccessEvent> of <PaymentCallbackService>", zap.Error(err))
}
}()
return nil
}
@ -98,6 +102,7 @@ func (receiver *PaymentCallbackService) FailureEvent(ctx context.Context, event
UserID: event.UserID,
Comment: event.Message,
Key: event.Key,
RawDetails: fmt.Sprintf("%d%s", event.Amount, event.Currency),
}); err != nil {
receiver.logger.Error("failed to create history on <FailureEvent> of <PaymentCallbackService>", zap.Error(err))
return err

@ -186,13 +186,16 @@ func (receiver *Service) Pay(ctx context.Context, accessToken string, userID str
return nil, err
}
go func(tariffs []models.Tariff) {
if _, historyErr := receiver.historyService.CreateHistory(ctx, &models.History{
Key: models.CustomerHistoryKeyPayCart,
UserID: account.UserID,
Comment: "Успешная оплата корзины",
RawDetails: utils.TranslateTariffsArrayToMapPair(tariffs),
}); historyErr != nil {
receiver.logger.Error("failed to insert history on <Pay> of <CartService>", zap.Error(historyErr))
}
}(tariffs)
// TODO: обработать ошибки при отправке сообщений

@ -2,6 +2,7 @@ package wallet
import (
"context"
"fmt"
"log"
"go.uber.org/zap"
@ -97,19 +98,21 @@ func (receiver *Service) ReplenishAccountWallet(ctx context.Context, request *mo
zap.String("Currency", request.Account.Wallet.Currency),
zap.Int64("Money", request.Account.Wallet.Money+request.Cash),
zap.Int64("Cash", request.Account.Wallet.Cash+cash),
zap.Bool("Is currensy equal internal", request.Currency == models.InternalCurrencyKey),
)
return nil, changeErr
}
go func() {
if _, historyErr := receiver.historyService.CreateHistory(ctx, &models.History{
Key: models.CustomerHistoryKeyReplenish,
UserID: request.Account.UserID,
Comment: "Успешное пополнение средств (Без конвертации валюты)",
RawDetails: fmt.Sprintf("%d%s", cash, models.InternalCurrencyKey),
}); historyErr != nil {
receiver.logger.Error("failed to insert history on <ReplenishAccountWallet> of <WalletService>", zap.Error(historyErr))
}
}()
return updatedAccount, nil
}
@ -136,7 +139,7 @@ func (receiver *Service) ReplenishAccountWallet(ctx context.Context, request *mo
receiver.logger.Error("failed to replenish wallet on <ReplenishAccountWallet> of <WalletService>",
zap.Error(err),
zap.String("Currency", request.Account.Wallet.Currency),
zap.Int64("Money", request.Account.Wallet.Money+request.Cash),
zap.Int64("Money", request.Account.Wallet.Money+money),
zap.Int64("Cash", request.Account.Wallet.Cash+cash),
zap.Bool("Is currensy equal internal", request.Currency == models.InternalCurrencyKey),
)
@ -144,13 +147,16 @@ func (receiver *Service) ReplenishAccountWallet(ctx context.Context, request *mo
return nil, err
}
go func() {
if _, historyErr := receiver.historyService.CreateHistory(ctx, &models.History{
Key: models.CustomerHistoryKeyReplenish,
UserID: request.Account.UserID,
Comment: "Успешное пополнение средств (C конвертацией валюты)",
RawDetails: fmt.Sprintf("%d%s", cash, request.Currency),
}); historyErr != nil {
receiver.logger.Error("failed to insert history on <ReplenishAccountWallet> of <WalletService>", zap.Error(historyErr))
}
}()
return updatedAccount, nil
}

@ -23,3 +23,13 @@ func CalculateCartPurchasesAmount(tariffs []models.Tariff) uint64 {
return sum
}
func TranslateTariffsArrayToMapPair(tariffs []models.Tariff) map[string]string {
pair := make(map[string]string, len(tariffs))
for _, tariff := range tariffs {
pair[tariff.Name] = tariff.ID
}
return pair
}