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
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"git.maximotejeda.com/maximo/dolar/internal/application/core/domain"
|
|
"git.maximotejeda.com/maximo/dolar/internal/ports"
|
|
)
|
|
|
|
type Application struct {
|
|
db ports.DBPort
|
|
log *slog.Logger
|
|
}
|
|
|
|
func NewApplication(db ports.DBPort) *Application {
|
|
log := slog.Default()
|
|
log = log.With("adapter", "application")
|
|
return &Application{
|
|
db: db,
|
|
log: log,
|
|
}
|
|
}
|
|
|
|
func (a Application) NewHistory(history *domain.History) (*domain.History, error) {
|
|
err := a.db.Save(history)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return history, nil
|
|
}
|
|
func (a Application) GetInstByType(name string) ([]string, error) {
|
|
list, err := a.db.GetInstByType(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return list, nil
|
|
}
|
|
func (a Application) GetLatest(name string) (*domain.History, error) {
|
|
return a.db.GetLatest(name)
|
|
}
|
|
|
|
func (a Application) GetSince(name string, duration int64) ([]*domain.History, error) {
|
|
hs, err := a.db.GetSince(name, duration)
|
|
a.log.Info("get since", "name", name, "duration", duration)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return hs, nil
|
|
}
|
|
|
|
func (a Application) GetInstByName(name string) (*domain.Institution, error) {
|
|
return a.db.GetInstByName(name)
|
|
}
|
|
|
|
func (a Application) TGBSubscribe(tgb_id int64, inst_name string) (bool, error) {
|
|
return a.db.TGBSubscribe(tgb_id, inst_name)
|
|
}
|
|
func (a Application) TGBUnsubscribe(tgb_id int64, inst_name string) (bool, error) {
|
|
return a.db.TGBUnsubscribe(tgb_id, inst_name)
|
|
}
|
|
|
|
func (a Application) TGBGetSubscribedUsers(inst_name string) ([]int64, error) {
|
|
return a.db.TGBGetSubscribedUsers(inst_name)
|
|
}
|
|
|
|
func (a Application) TGBGetSubscribedInst(tgb_id int64) ([]string, error) {
|
|
return a.db.TGBGetSubscribedInst(tgb_id)
|
|
}
|