first commit

This commit is contained in:
2023-04-15 16:23:34 +07:00
commit bbed7f94f4
20 changed files with 533 additions and 0 deletions

41
controllers/race.go Normal file
View 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
View File

@ -0,0 +1 @@
package controllers