/
remates.go
67 lines (55 loc) · 1.9 KB
/
remates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package models
import (
"time"
u "github.com/gonzalezlrjesus/API-Betting-Sports/utils"
"github.com/jinzhu/gorm"
)
// Cuando el proyecto este mas avanzado deberia llevar un control de la tabla que se esta jugando
// Todo eso para repartir el dinero mas eficazmente cuando existan varias tablas para la misma carrera
// Necesito tener un control a cual tabla pertenece el remate para repartir el dineros
// Remates struct
type Remates struct {
gorm.Model
Idracing uint `json:"idracing"`
Idhorse int `json:"idhorse"`
Numberhorse int `json:"numberhorse"`
Seudonimo string `json:"seudonimo"`
Amount int64 `json:"amount"`
Horsename string `json:"horsename"`
}
// CreateRemates .
func CreateRemates(idracing uint, idhorse int, numberhorse int, seudonimo string, amount int64, horsename string) map[string]interface{} {
remateGanador := &Remates{
Idracing: idracing,
Idhorse: idhorse,
Numberhorse: numberhorse,
Seudonimo: seudonimo,
Amount: amount,
Horsename: horsename}
GetDB().Create(remateGanador)
response := u.Message(true, "Remate added")
response["remate"] = remateGanador
return response
}
// GetRemates .
func GetRemates(idracing uint) map[string]interface{} {
remates, err := searchRematesByRacingID(idracing)
if err != nil {
return nil
}
response := u.Message(true, "Remates")
response["remates"] = remates
response["time"] = time.Now()
return response
}
// SearchRemateByRaceIDAndHorseID .
func SearchRemateByRaceIDAndHorseID(idRacing uint, idHorse int) (*Remates, error) {
temp := &Remates{}
err := GetDB().Table("remates").Where("idracing = ? AND idhorse = ?", idRacing, idHorse).Order("id").Find(temp).Error
return temp, err
}
func searchRematesByRacingID(idracing uint) ([]*Remates, error) {
remates := make([]*Remates, 0)
err := GetDB().Table("remates").Where("idracing = ?", idracing).Order("id").Find(&remates).Error
return remates, err
}