package models import ( "git.rouggy.com/rouggy/RaceBot/internal/database" "github.com/jinzhu/gorm" ) type Race struct { gorm.Model Hash string `gorm:"column:hash;type:varchar(50)" form:"hash" json:"hash" binding:"max=50"` TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"` Category string `gorm:"column:category;varchar(50);not null" form:"category" json:"category" binding:"max=50"` Indexer string `gorm:"column:indexer;varchar(20);not null" form:"indexer" json:"indexer" binding:"max=20"` Type string `gorm:"column:type;varchar(20)" form:"type" json:"type" binding:"max=20"` Title string `gorm:"column:title;varchar(20)" form:"title" json:"title" binding:"max=20"` Season string `gorm:"column:season;varchar(2)" form:"season" json:"season" binding:"max=2"` Episode string `gorm:"column:episode;varchar(4)" form:"episode" json:"episode" binding:"max=4"` Year string `gorm:"column:year;varchar(4)" form:"year" json:"year" binding:"max=4"` Resolution string `gorm:"column:resolution;varchar(20)" form:"resolution" json:"resolution" binding:"max=20"` Source string `gorm:"column:source;varchar(20)" form:"source" json:"source" binding:"max=20"` HDR string `gorm:"column:hdr;varchar(20)" form:"hdr" json:"hdr" binding:"max=20"` TorrentURL string `gorm:"column:torrenturl;varchar(20);not null" form:"torrenturl" json:"torrenturl" binding:"max=20"` Won bool `gorm:"column:won;bool" form:"won" json:"won"` PreRace bool `gorm:"column:prerace;bool" form:"prerace" json:"prerace"` } func NewRace() *Race { r := &Race{} return r } func (r *Race) SaveRace() (*Race, error) { db := database.GetDB() err := db.Create(&r).Error if err != nil { return &Race{}, err } return r, nil } func (r *Race) GetRaceByName(title string) (*Race, error) { db := database.GetDB() err := db.Where(Race{TorrentName: title}).Find(&r).Error if err != nil { return &Race{}, err } return r, nil }