diff --git a/cmd/root.go b/cmd/root.go index fa56e4d..824bc2e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -19,6 +19,7 @@ var ( PATH_STATIC string = getEnv("PATH_STATIC") PATH_IMAGE string = getEnv("PATH_IMAGE") ) + var ( rootCmd = &cobra.Command{ Use: "cobra-cli", diff --git a/internal/domain/model/football.go b/internal/domain/model/football.go new file mode 100644 index 0000000..16402bc --- /dev/null +++ b/internal/domain/model/football.go @@ -0,0 +1,39 @@ +package model + +type LeagueResponse struct { + ID string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Logo string `json:"logo"` +} + +type CountryResponse struct { + Name string `json:"name"` + Code string `json:"code"` + Flag string `json:"flag"` +} + +type SeassonResponse struct { + Year int `json:"year"` + Start string `json:"start"` + End string `json:"end"` + Current bool `json:"current"` +} + +type CoverageResponse struct { + Standings bool `json:"standings"` + Players bool `json:"players"` + TopScorers bool `json:"top_scorers"` + TopAssists bool `json:"top_assists"` + TopCards bool `json:"top_cards"` + Injuries bool `json:"injuries"` + Predictions bool `json:"predictions"` + Odds bool `json:"odds"` +} + +type FixturesResponse struct { + Events bool `json:"events"` + Lineups bool `json:"lineups"` + StatisticsFixtures bool `json:"statistics_fixtures"` + StatisticsPlayers bool `json:"statistics_players"` +} diff --git a/internal/handler/ussd_handler.go b/internal/handler/ussd_handler.go index 33b3e0f..36709bd 100644 --- a/internal/handler/ussd_handler.go +++ b/internal/handler/ussd_handler.go @@ -4,7 +4,6 @@ import ( "log" "github.com/gofiber/fiber/v2" - "github.com/idprm/go-football-alert/internal/domain/model" "github.com/idprm/go-football-alert/internal/services" ) @@ -19,7 +18,7 @@ func NewUssdHandler(ussdService services.IUssdService) *UssdHandler { } func (h *UssdHandler) Callback(c *fiber.Ctx) error { - req := new(model.AfricasTalkingRequest) + req := c.FormValue("text") layer1 := `Credit Goal Gagnez des lots a chaque but de votre equipe \n 1. Foot International \n @@ -37,15 +36,19 @@ func (h *UssdHandler) Callback(c *fiber.Ctx) error { 5. France - Etats Unis \n 0. Suiv` - if req.IsFirst() { - return c.Status(fiber.StatusOK).SendString(layer1) - } - if req.IsOne() { + layer3 := `Foot international Credit Goal Mercedi 24 Juil. \n + 1. Japon - Paraguay \n + 0. Suiv` + + if req == "1" { return c.Status(fiber.StatusOK).SendString(layer2) } - if req.IsTwo() { + if req == "2" { return c.Status(fiber.StatusOK).SendString(layer2) } + if req == "3" { + return c.Status(fiber.StatusOK).SendString(layer3) + } return c.Status(fiber.StatusOK).SendString(layer1) } diff --git a/internal/providers/apifb/apifb.go b/internal/providers/apifb/apifb.go index 47ba4b2..6ea96d0 100644 --- a/internal/providers/apifb/apifb.go +++ b/internal/providers/apifb/apifb.go @@ -1,5 +1,11 @@ package apifb +import "github.com/idprm/go-football-alert/internal/utils" + +var ( + URL_FOOTBALL string = utils.GetEnv("URL_FOOTBALL") +) + type ApiFb struct { } diff --git a/internal/providers/telco/telco.go b/internal/providers/telco/telco.go new file mode 100644 index 0000000..d28ecd8 --- /dev/null +++ b/internal/providers/telco/telco.go @@ -0,0 +1,66 @@ +package telco + +import ( + "bytes" + "encoding/json" + "errors" + "io" + "net/http" + "strconv" + "time" +) + +type Telco struct { +} + +func NewTelco() *Telco { + return &Telco{} +} + +type ITelco interface { +} + +func (p *Telco) Token() ([]byte, error) { + dataJson, err := json.Marshal(p) + if err != nil { + return nil, errors.New(err.Error()) + } + + req, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(dataJson)) + if err != nil { + return nil, err + } + + now := time.Now() + timeStamp := strconv.Itoa(int(now.Unix())) + + req.Header.Add("Accept-Charset", "utf-8") + req.Header.Add("X-Api-Key", "") + req.Header.Add("X-Signature", "") + req.Header.Add("X-Trxtime", timeStamp) + + tr := &http.Transport{ + MaxIdleConns: 40, + IdleConnTimeout: 60 * time.Second, + DisableCompression: true, + } + + client := &http.Client{ + Timeout: 60 * time.Second, + Transport: tr, + } + + resp, err := client.Do(req) + if err != nil { + return nil, errors.New(err.Error()) + } + + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, errors.New(err.Error()) + } + + return body, nil +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go new file mode 100644 index 0000000..5b2287b --- /dev/null +++ b/internal/utils/utils.go @@ -0,0 +1,14 @@ +package utils + +import ( + "log" + "os" +) + +func GetEnv(key string) string { + value := os.Getenv(key) + if len(value) == 0 { + log.Panicf("Error %v", key) + } + return value +}