first commit
This commit is contained in:
41
controllers/race.go
Normal file
41
controllers/race.go
Normal file
@ -0,0 +1,41 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rouggy.com/rouggy/RaceBot/database"
|
||||
"git.rouggy.com/rouggy/RaceBot/helper"
|
||||
"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)
|
||||
}
|
1
controllers/release.go
Normal file
1
controllers/release.go
Normal file
@ -0,0 +1 @@
|
||||
package controllers
|
Reference in New Issue
Block a user