From b2d0cfc28cb4ecf6e7e06c6862fa7b8ed3c2cfeb Mon Sep 17 00:00:00 2001 From: Parya Rastegar Date: Mon, 24 Jun 2024 05:02:11 +0330 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(linter):=20fix=20errors=20>>?= =?UTF-8?q?>=20=E2=8F=B0=2010m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/model/dataframe.go | 7 ++++++- internal/model/proof.go | 8 +++++++- internal/model/signer.go | 2 ++ internal/repository/mongo/assetprice.go | 8 ++++---- internal/repository/mongo/correctness.go | 4 ++-- internal/repository/mongo/eventlog.go | 4 ++-- internal/repository/mongo/signer.go | 4 ++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/internal/model/dataframe.go b/internal/model/dataframe.go index d49d3c26..99f1c75e 100644 --- a/internal/model/dataframe.go +++ b/internal/model/dataframe.go @@ -1,8 +1,13 @@ package model -import "time" +import ( + "time" + + "gorm.io/gorm" +) type DataFrame struct { + gorm.Model Hash []byte `bson:"hash" json:"hash"` Timestamp time.Time `bson:"timestamp" json:"timestamp"` Data interface{} `bson:"data" gorm:"embedded" json:"data"` diff --git a/internal/model/proof.go b/internal/model/proof.go index d69cd8e7..0735b7bf 100644 --- a/internal/model/proof.go +++ b/internal/model/proof.go @@ -1,8 +1,14 @@ package model -import "time" +import ( + "time" + + "gorm.io/gorm" +) type Proof struct { + gorm.Model + Hash []byte `bson:"hash" json:"hash"` Timestamp time.Time `bson:"timestamp" json:"timestamp"` Signature [48]byte `bson:"signature" json:"signature"` diff --git a/internal/model/signer.go b/internal/model/signer.go index bd7d0606..b2aa1496 100644 --- a/internal/model/signer.go +++ b/internal/model/signer.go @@ -2,9 +2,11 @@ package model import ( sia "github.com/pouya-eghbali/go-sia/v2/pkg" + "gorm.io/gorm" ) type Signer struct { + gorm.Model Name string EvmAddress string PublicKey [96]byte diff --git a/internal/repository/mongo/assetprice.go b/internal/repository/mongo/assetprice.go index 61421d5d..1d962abc 100644 --- a/internal/repository/mongo/assetprice.go +++ b/internal/repository/mongo/assetprice.go @@ -58,8 +58,8 @@ func (a AssetPriceRepo) Upsert(ctx context.Context, data model.AssetPrice) error return nil } -func (a AssetPriceRepo) Find(ctx context.Context, block uint64, chain string, name string, pair string) ([]*ent.AssetPrice, error) { - currentRecords := []*ent.AssetPrice{} +func (a AssetPriceRepo) Find(ctx context.Context, block uint64, chain string, name string, pair string) ([]model.AssetPrice, error) { + currentRecords := []model.AssetPrice{} cursor, err := a.client. GetConnection(). Database(config.App.Mongo.Database). @@ -83,14 +83,14 @@ func (a AssetPriceRepo) Find(ctx context.Context, block uint64, chain string, na } }(cursor, ctx) for cursor.Next(ctx) { - var result ent.AssetPrice + var result model.AssetPrice err := cursor.Decode(&result) if err != nil { utils.Logger.With("err", err).Error("Cant decode signer record") return nil, err } - currentRecords = append(currentRecords, &result) + currentRecords = append(currentRecords, result) } if err := cursor.Err(); err != nil { utils.Logger.With("err", err).Error("Cant fetch asset price records from database") diff --git a/internal/repository/mongo/correctness.go b/internal/repository/mongo/correctness.go index 688429c0..efc4be1b 100644 --- a/internal/repository/mongo/correctness.go +++ b/internal/repository/mongo/correctness.go @@ -18,7 +18,7 @@ type CorrectnessRepo struct { client database.MongoDatabase } -func (c CorrectnessRepo) Find(ctx context.Context, hash []byte, topic []byte, timestamp uint64) ([]*ent.CorrectnessReport, error) { +func (c CorrectnessRepo) Find(ctx context.Context, hash []byte, topic []byte, timestamp uint64) ([]model.Correctness, error) { cursor, err := c.client. GetConnection(). Database(config.App.Mongo.Database). @@ -34,7 +34,7 @@ func (c CorrectnessRepo) Find(ctx context.Context, hash []byte, topic []byte, ti return nil, consts.ErrInternalError } - currentRecords, err := CursorToList[*ent.CorrectnessReport](ctx, cursor) + currentRecords, err := CursorToList[model.Correctness](ctx, cursor) if err != nil { utils.Logger.With("err", err).Error("Cant fetch correctness reports from database") return nil, consts.ErrInternalError diff --git a/internal/repository/mongo/eventlog.go b/internal/repository/mongo/eventlog.go index 3177e790..7b1f2ca0 100644 --- a/internal/repository/mongo/eventlog.go +++ b/internal/repository/mongo/eventlog.go @@ -18,7 +18,7 @@ type EventLogRepo struct { client database.MongoDatabase } -func (r EventLogRepo) Find(ctx context.Context, block uint64, hash []byte, index uint64) ([]*ent.EventLog, error) { +func (r EventLogRepo) Find(ctx context.Context, block uint64, hash []byte, index uint64) ([]model.EventLog, error) { cursor, err := r.client. GetConnection(). Database(config.App.Mongo.Database). @@ -34,7 +34,7 @@ func (r EventLogRepo) Find(ctx context.Context, block uint64, hash []byte, index return nil, consts.ErrInternalError } - currentRecords, err := CursorToList[*ent.EventLog](ctx, cursor) + currentRecords, err := CursorToList[model.EventLog](ctx, cursor) if err != nil { utils.Logger.With("err", err).Error("Cant fetch event log records from database") return nil, consts.ErrInternalError diff --git a/internal/repository/mongo/signer.go b/internal/repository/mongo/signer.go index 2f95791b..c707206a 100644 --- a/internal/repository/mongo/signer.go +++ b/internal/repository/mongo/signer.go @@ -74,14 +74,14 @@ func (s signerRepo) GetSingerIDsByKeys(ctx context.Context, keys [][]byte) ([]in } }(cursor, ctx) for cursor.Next(ctx) { - var result ent.Signer + var result model.Signer err := cursor.Decode(&result) if err != nil { utils.Logger.With("err", err).Error("Cant decode signer record") return nil, err } - ids = append(ids, result.ID) + ids = append(ids, int(result.ID)) } if err := cursor.Err(); err != nil { utils.Logger.With("err", err).Error("Cant fetch asset price records from database")