Skip to content

Commit

Permalink
Merge pull request #37 from blnkledger/jerry/34-date-not-being-return…
Browse files Browse the repository at this point in the history
…ed-correctly

Jerry/34 date not being returned correctly
  • Loading branch information
jerry-enebeli authored Jun 10, 2024
2 parents c3368fd + 3762ecb commit abfe723
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func serverCommands(b *blnkInstance) *cobra.Command {
Interval: 10 * time.Second,
Timeout: time.Minute,
}, newSearch)

go listener.Start()

if cfg.Server.SSL {
Expand Down
3 changes: 2 additions & 1 deletion cmd/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func (b *blnkInstance) processTransaction(cxt context.Context, t *asynq.Task) er
return err
}
_, err := b.blnk.RecordTransaction(cxt, &txn)

if err != nil {
return err
}
Expand All @@ -42,6 +41,8 @@ func (b *blnkInstance) processTransaction(cxt context.Context, t *asynq.Task) er
})
return err
}

log.Println(" [*] Transaction Processed", txn.ID)
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions database/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"database/sql"
"encoding/json"
"errors"
"time"

"go.opentelemetry.io/otel"

Expand All @@ -23,8 +22,6 @@ func (d Datasource) RecordTransaction(cxt context.Context, txn *model.Transactio
return txn, err
}

txn.CreatedAt = time.Now()
// insert into database
_, err = d.Conn.ExecContext(cxt,
`
INSERT INTO blnk.transactions(transaction_id,parent_transaction,source,reference,amount,precise_amount,precision,rate,currency,destination,description,status,created_at,meta_data,scheduled_for,hash) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/sdk v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
golang.org/x/net v0.22.0
golang.org/x/net v0.23.0
)

require (
Expand Down Expand Up @@ -72,6 +72,7 @@ require (
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/websocket v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.2 h1:qoW6V1GT3aZxybsbC6oLnailWnB+qTMVwMreOso9XUw=
github.com/gorilla/websocket v1.5.2/go.mod h1:0n9H61RBAcf5/38py2MCYbxzPIY9rOkpvvMT24Rqs30=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU=
github.com/hibiken/asynq v0.24.1 h1:+5iIEAyA9K/lcSPvx3qoPtsKJeKI5u9aOIvUmSsazEw=
Expand Down Expand Up @@ -365,6 +367,8 @@ golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
20 changes: 13 additions & 7 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,38 @@ func EnsureCollectionsExist(client *TypesenseClient, ctx context.Context) error
transaction := model.Transaction{}
_, err := client.CreateCollection(ctx, ledger.ToSchema())
if err != nil {
logrus.Error(err)
return err
}
_, err = client.CreateCollection(ctx, balance.ToSchema())
if err != nil {
logrus.Error(err)
return err
}
_, err = client.CreateCollection(ctx, transaction.ToSchema())
if err != nil {
logrus.Error(err)
return err
}
return nil
}

func (t *TypesenseClient) CreateCollection(ctx context.Context, schema *api.CollectionSchema) (*api.CollectionResponse, error) {
return t.Client.Collections().Create(ctx, schema)
api, err := t.Client.Collections().Create(ctx, schema)
if err != nil {
if strings.Contains(err.Error(), "already exists.") {
return nil, nil
}
return nil, err
}
return api, nil
}

func (t *TypesenseClient) Search(ctx context.Context, collection string, searchParams *api.SearchCollectionParams) (*api.SearchResult, error) {
return t.Client.Collection(collection).Documents().Search(ctx, searchParams)

}

func (t *TypesenseClient) HandleNotification(table string, data map[string]interface{}) error {
if err := EnsureCollectionsExist(t, context.Background()); err != nil {
if strings.Contains(err.Error(), "already exists.") {
logrus.Warningln(err)
}
logrus.Warningln(err)
}

metaData, ok := data["meta_data"]
Expand Down
1 change: 1 addition & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ func (l *Blnk) QueueTransaction(cxt context.Context, transaction *model.Transact

transaction.Status = StatusQueued
transaction.SkipBalanceUpdate = true
transaction.CreatedAt = time.Now()

if !transaction.ScheduledFor.IsZero() {
transaction.Status = StatusScheduled
Expand Down

0 comments on commit abfe723

Please sign in to comment.