53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"html/template"
|
|
"log/slog"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/maximotejeda/us_dop_api/domain"
|
|
"github.com/maximotejeda/us_dop_api/ports"
|
|
"github.com/maximotejeda/us_dop_db/db"
|
|
)
|
|
|
|
type API struct {
|
|
http.ServeMux
|
|
db *db.DB
|
|
dolar ports.DolarService
|
|
log *slog.Logger
|
|
templ template.Template
|
|
}
|
|
|
|
type SearchResult struct {
|
|
InstRequested string `json:"institution_requested"`
|
|
Date time.Time `json:"date"`
|
|
TimeAmount string `json:"time_amount"`
|
|
TimeFrame string `json:"time_frame"`
|
|
Results []*domain.History `josn:"results"`
|
|
}
|
|
|
|
func NewApiHandler(db *db.DB, dolar ports.DolarService, log *slog.Logger, templ template.Template) *API {
|
|
log = log.With("api", "insti")
|
|
api := &API{
|
|
db: db,
|
|
log: log,
|
|
dolar: dolar,
|
|
templ: templ,
|
|
}
|
|
api.HandleFunc("POST /api/instituciones/history", api.GetInstitutionHistory) // general handler to get banks, agents and others histories
|
|
// api.HandleFunc("GET /api/instituciones/{inst}", nil) // return the card of just one institution with details
|
|
api.HandleFunc("GET /api/{inst}/", api.GetInstNames)
|
|
api.HandleFunc("GET /api/latest/all", api.GetAllLatestPrice)
|
|
api.HandleFunc("GET /api/control/select", api.GetHistoryPage)
|
|
api.HandleFunc("GET /api/control/compare", api.GetComparisonPage)
|
|
return api
|
|
}
|
|
|
|
// instParseHTML
|
|
//
|
|
// Can be much tipe of html part of a list, a form, a card etc...
|
|
func instParseHTML(SearchResult) string {
|
|
return "html"
|
|
}
|