All checks were successful
dev test / test (push) Successful in 17s
dev test / vulnCheck (push) Successful in 30s
dev test / Ci-Lint (push) Successful in 19s
${{ github.actor }} executed Build Push Prod / build (push) Successful in 4m24s
${{ github.actor }} executed Build Push Prod / deploy (push) Successful in 18s
111 lines
3.4 KiB
Go
111 lines
3.4 KiB
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.maximotejeda.com/maximo/dolar/internal/application/core/domain"
|
|
"git.maximotejeda.com/maximo/dolar/proto/golang/dolar"
|
|
)
|
|
|
|
func (a Adapter) NewHistory(ctx context.Context, request *dolar.AddDolarRequest) (*dolar.AddDolarResponse, error) {
|
|
newHistory := domain.NewHistory(
|
|
request.Institution.Name,
|
|
request.Institution.Parser,
|
|
request.Institution.Parser,
|
|
float64(request.Institution.Compra),
|
|
float64(request.Institution.Venta))
|
|
result, err := a.api.NewHistory(&newHistory)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &dolar.AddDolarResponse{Id: result.ID}, nil
|
|
}
|
|
|
|
func (a Adapter) GetLatest(ctx context.Context, name *dolar.GetLatestRequest) (*dolar.GetLatestResponse, error) {
|
|
lastHistory, err := a.api.GetLatest(name.Name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dH := dolar.History{
|
|
Id: lastHistory.ID,
|
|
Name: lastHistory.Institution.Name,
|
|
Compra: float32(lastHistory.Compra),
|
|
Venta: float32(lastHistory.Venta),
|
|
Parser: lastHistory.Parser,
|
|
Parsed: lastHistory.Parsed,
|
|
}
|
|
return &dolar.GetLatestResponse{Actual: &dH}, nil
|
|
}
|
|
func (a Adapter) GetSince(ctx context.Context, req *dolar.GetSinceRequest) (*dolar.GetMultipleResponse, error) {
|
|
ch, err := a.api.GetSince(req.Name, req.Duration)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
historiesList := []*dolar.History{}
|
|
for _, his := range ch {
|
|
h := dolar.History{
|
|
Id: his.ID,
|
|
Name: his.Institution.Name,
|
|
Compra: float32(his.Compra),
|
|
Venta: float32(his.Venta),
|
|
Parser: his.Parser,
|
|
Parsed: his.Parsed,
|
|
}
|
|
historiesList = append(historiesList, &h)
|
|
}
|
|
return &dolar.GetMultipleResponse{Histories: historiesList}, nil
|
|
}
|
|
|
|
func (a Adapter) GetInstByType(ctx context.Context, req *dolar.GetInstByTypeRequest) (*dolar.GetInstByTypeResponse, error) {
|
|
il, err := a.api.GetInstByType(req.Name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dolar.GetInstByTypeResponse{InstList: il}, nil
|
|
}
|
|
|
|
func (a Adapter) GetInstByName(ctx context.Context, req *dolar.GetInstByNameRequest) (*dolar.GetInstByNameResponse, error) {
|
|
inst, err := a.api.GetInstByName(req.InstName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
in := &dolar.Institution{
|
|
Id: inst.ID,
|
|
Name: inst.Name,
|
|
ShortName: inst.ShortName,
|
|
Created: inst.Created,
|
|
}
|
|
return &dolar.GetInstByNameResponse{Institution: in}, nil
|
|
}
|
|
|
|
func (a Adapter) TGBSubscribe(ctx context.Context, req *dolar.TGBSubscribeRequest) (*dolar.TGBSubsResponse, error) {
|
|
ok, err := a.api.TGBSubscribe(req.TgbId, req.InstName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dolar.TGBSubsResponse{Response: ok}, nil
|
|
}
|
|
|
|
func (a Adapter) TGBUnsubscribe(ctx context.Context, req *dolar.TGBUnsubscribeRequest) (*dolar.TGBSubsResponse, error) {
|
|
ok, err := a.api.TGBUnsubscribe(req.TgbId, req.InstName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dolar.TGBSubsResponse{Response: ok}, nil
|
|
}
|
|
func (a Adapter) TGBGetSubscribedUsers(ctx context.Context, req *dolar.TGBGetSubscribedUsersRequest) (*dolar.TGBGetSubscribedUsersResponse, error) {
|
|
userList, err := a.api.TGBGetSubscribedUsers(req.InstName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dolar.TGBGetSubscribedUsersResponse{TgbIds: userList}, nil
|
|
}
|
|
func (a Adapter) TGBGetSubscribedInsts(ctx context.Context, req *dolar.TGBGetSubscribedInstRequest) (*dolar.TGBGetSubscribedInstResponse, error) {
|
|
userList, err := a.api.TGBGetSubscribedInst(req.TgbId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &dolar.TGBGetSubscribedInstResponse{InstName: userList}, nil
|
|
}
|