42 lines
886 B
Go
42 lines
886 B
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rouggy.com/rouggy/RaceBot/helper"
|
|
"git.rouggy.com/rouggy/RaceBot/internal/database"
|
|
"git.rouggy.com/rouggy/RaceBot/models"
|
|
"github.com/gin-gonic/gin"
|
|
"time"
|
|
)
|
|
|
|
func CreatePreRace(c *gin.Context) {
|
|
start := time.Now()
|
|
r := models.NewRace()
|
|
rel := models.NewRelease()
|
|
|
|
if err := c.ShouldBind(&r); err != nil {
|
|
fmt.Println("Error: %v", err)
|
|
}
|
|
|
|
rel.ParseString(r.TorrentName)
|
|
|
|
searchRace, _ := r.GetRaceByName(r.TorrentName)
|
|
|
|
if searchRace.ID == 0 {
|
|
r.SaveRace()
|
|
helper.RespondJSON(c, 200, "New race saved", r)
|
|
fmt.Println("Elapsed: ", time.Since(start))
|
|
} else {
|
|
helper.RespondJSON(c, 200, "Race already existing", searchRace)
|
|
fmt.Println("Elapsed: ", time.Since(start))
|
|
}
|
|
}
|
|
|
|
func GetAllRaces(c *gin.Context) {
|
|
var r []models.Race
|
|
db := database.GetDB()
|
|
db.Find(&r)
|
|
|
|
helper.RespondJSON(c, 200, "Get all races", r)
|
|
}
|