ADD logs
Some checks failed
dev test / test (push) Failing after 9s
dev test / vulnCheck (push) Has been skipped
dev test / Ci-Lint (push) Has been skipped
${{ github.actor }} executed Build Push Prod / deploy (push) Has been cancelled
${{ github.actor }} executed Build Push Prod / build (push) Has been cancelled
Some checks failed
dev test / test (push) Failing after 9s
dev test / vulnCheck (push) Has been skipped
dev test / Ci-Lint (push) Has been skipped
${{ github.actor }} executed Build Push Prod / deploy (push) Has been cancelled
${{ github.actor }} executed Build Push Prod / build (push) Has been cancelled
This commit is contained in:
parent
745a74de61
commit
2294f9efc1
@ -2,6 +2,8 @@ package dolar
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.maximotejeda.com/maximo/dolar/proto/golang/dolar"
|
||||
@ -12,19 +14,26 @@ import (
|
||||
type Adapter struct {
|
||||
dolar dolar.DollarClient
|
||||
conn *grpc.ClientConn
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewAdapter(conn *grpc.ClientConn) (*Adapter, error) {
|
||||
client := dolar.NewDollarClient(conn)
|
||||
return &Adapter{dolar: client, conn: conn}, nil
|
||||
log := slog.New(slog.NewJSONHandler(os.Stderr))
|
||||
log.With("dapter", "dolar-grpc")
|
||||
return &Adapter{dolar: client, conn: conn, log: log}, nil
|
||||
}
|
||||
func (a *Adapter) GetLatest(name string) (*domain.History, error) {
|
||||
hr, err := a.dolar.GetLatest(context.Background(), &dolar.GetLatestRequest{Name: name})
|
||||
if err != nil {
|
||||
a.log.Error("Get Lastest", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
date := time.Unix(hr.Actual.Parsed, 0)
|
||||
loc, _ := time.LoadLocation("America/Santo_Domingo")
|
||||
loc, err := time.LoadLocation("America/Santo_Domingo")
|
||||
if err != nil {
|
||||
a.log.Error("Get Lastest", "error", err)
|
||||
}
|
||||
history := &domain.History{
|
||||
ID: hr.Actual.Id,
|
||||
Institution: domain.Institution{
|
||||
@ -44,6 +53,7 @@ func (a Adapter) GetSince(name string, duration int64) (list []*domain.History,
|
||||
Duration: duration,
|
||||
})
|
||||
if err != nil {
|
||||
a.log.Error("get since", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -51,7 +61,10 @@ func (a Adapter) GetSince(name string, duration int64) (list []*domain.History,
|
||||
|
||||
for _, hr := range hrl.Histories {
|
||||
date := time.Unix(hr.Parsed, 0)
|
||||
loc, _ := time.LoadLocation("America/Santo_Domingo")
|
||||
loc, err := time.LoadLocation("America/Santo_Domingo")
|
||||
if err != nil {
|
||||
a.log.Error("get since", "error", err)
|
||||
}
|
||||
hist := &domain.History{
|
||||
ID: hr.Id,
|
||||
Institution: domain.Institution{
|
||||
@ -72,6 +85,7 @@ func (a Adapter) GetInstByType(name string) (list []string, err error) {
|
||||
Name: name,
|
||||
})
|
||||
if err != nil {
|
||||
a.log.Error("get inst by type", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -85,6 +99,7 @@ func (a Adapter) Subscribe(tgbid int64, instName string) (bool, error) {
|
||||
ctx := context.Background()
|
||||
_, err := a.dolar.TGBSubscribe(ctx, &dolar.TGBSubscribeRequest{TgbId: tgbid, InstName: instName})
|
||||
if err != nil {
|
||||
a.log.Error("subscribe", "error", err)
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
@ -94,6 +109,7 @@ func (a Adapter) Unsubscribe(tgbid int64, instName string) (bool, error) {
|
||||
ctx := context.Background()
|
||||
_, err := a.dolar.TGBUnsubscribe(ctx, &dolar.TGBUnsubscribeRequest{TgbId: tgbid, InstName: instName})
|
||||
if err != nil {
|
||||
a.log.Error("unsubscribe", "error", err)
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
@ -103,6 +119,7 @@ func (a Adapter) GetSubscribedUsers(instName string) ([]int64, error) {
|
||||
ctx := context.Background()
|
||||
users, err := a.dolar.TGBGetSubscribedUsers(ctx, &dolar.TGBGetSubscribedUsersRequest{InstName: instName})
|
||||
if err != nil {
|
||||
a.log.Error("get subscribed users", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
list := []int64{}
|
||||
@ -115,6 +132,7 @@ func (a Adapter) GetSubscribedInsts(tgbid int64) ([]string, error) {
|
||||
ctx := context.Background()
|
||||
insts, err := a.dolar.TGBGetSubscribedInsts(ctx, &dolar.TGBGetSubscribedInstRequest{TgbId: tgbid})
|
||||
if err != nil {
|
||||
a.log.Error("get subscribed inst", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
list := []string{}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user