From 544c5348f12c67248a6a7501b1761570909eb1f1 Mon Sep 17 00:00:00 2001 From: nquidox Date: Thu, 2 Apr 2026 17:57:48 +0300 Subject: [PATCH] insert prices change --- internal/merch/provider.go | 12 ++++++------ internal/merch/repository_merch.go | 2 +- internal/merch/repository_prices.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/merch/provider.go b/internal/merch/provider.go index 8d7c8b5..50a308a 100644 --- a/internal/merch/provider.go +++ b/internal/merch/provider.go @@ -2,6 +2,7 @@ package merch import ( "context" + log "github.com/sirupsen/logrus" "merch-api/internal/common" "merch-api/pkg/utils" ) @@ -30,6 +31,7 @@ func (p *provider) GetTasks(ctx context.Context) ([]common.Task, error) { } func (p *provider) InsertPrices(ctx context.Context, rawPrices []common.Result) error { + log.WithField("payload", rawPrices).Debugf("%v Inserting prices", providerLogHeader) if rawPrices == nil || len(rawPrices) == 0 { logDebug(providerLogHeader, "no prices given") return nil @@ -56,15 +58,13 @@ func (p *provider) InsertPrices(ctx context.Context, rawPrices []common.Result) var insertPrices []Price for _, rawPrice := range rawPrices { insertPrices = append(insertPrices, Price{ - CreatedAt: now, - UpdatedAt: p.utils.NullTimeFromNow(now), - MerchId: uuidMap[rawPrice.MerchUuid], - OriginId: originIds[rawPrice.OriginName], - Price: int(rawPrice.Price), + MerchId: uuidMap[rawPrice.MerchUuid], + OriginId: originIds[rawPrice.OriginName], + Price: int(rawPrice.Price), }) } - if err = p.service.repo.insertPrices(ctx, insertPrices); err != nil { + if err = p.service.repo.insertPrices(ctx, now, p.utils.NullTimeFromNow(now), insertPrices); err != nil { logErr(serviceLogHeader, err) return err } diff --git a/internal/merch/repository_merch.go b/internal/merch/repository_merch.go index 4051f7a..af1868b 100644 --- a/internal/merch/repository_merch.go +++ b/internal/merch/repository_merch.go @@ -170,7 +170,7 @@ func (r *repo) getMerchUuidMap(ctx context.Context, merchUuids []string) (map[st return nil, err } - var merchUuidMap map[string]int64 + merchUuidMap := make(map[string]int64) for rows.Next() { var ( uuid string diff --git a/internal/merch/repository_prices.go b/internal/merch/repository_prices.go index 9c4454d..e5d1769 100644 --- a/internal/merch/repository_prices.go +++ b/internal/merch/repository_prices.go @@ -8,7 +8,7 @@ import ( ) type Prices interface { - insertPrices(ctx context.Context, prices []Price) error + insertPrices(ctx context.Context, now time.Time, updatedAt sql.NullTime, prices []Price) error getPricesWithDays(ctx context.Context, userId int64, days time.Time) ([]Price, error) getDistinctPrices(ctx context.Context, userId int64, merchUuid string, days time.Time) ([]Price, error) @@ -17,7 +17,7 @@ type Prices interface { deleteZeroPrices(ctx context.Context, userId int64, now sql.NullTime, list []int64) error } -func (r *repo) insertPrices(ctx context.Context, prices []Price) error { +func (r *repo) insertPrices(ctx context.Context, now time.Time, updatedAt sql.NullTime, prices []Price) error { q := ` INSERT INTO merch_prices (created_at, updated_at, merch_id, origin_id, price) SELECT $1, $2, src.merch_id, src.origin_id, src.price @@ -40,7 +40,7 @@ func (r *repo) insertPrices(ctx context.Context, prices []Price) error { priceValues = append(priceValues, price.Price) } - _, err := r.db.Exec(ctx, q, merchIds, originIds, priceValues) + _, err := r.db.Exec(ctx, q, now, updatedAt, merchIds, originIds, priceValues) if err != nil { return err }