Skip to content

Commit

Permalink
add new
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Jul 30, 2024
1 parent fd7bfb7 commit 1b641d6
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
PATH_STATIC string = getEnv("PATH_STATIC")
PATH_IMAGE string = getEnv("PATH_IMAGE")
)

var (
rootCmd = &cobra.Command{
Use: "cobra-cli",
Expand Down
39 changes: 39 additions & 0 deletions internal/domain/model/football.go
Original file line number Diff line number Diff line change
@@ -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"`
}
17 changes: 10 additions & 7 deletions internal/handler/ussd_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand All @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/providers/apifb/apifb.go
Original file line number Diff line number Diff line change
@@ -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 {
}

Expand Down
66 changes: 66 additions & 0 deletions internal/providers/telco/telco.go
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1b641d6

Please sign in to comment.