forked from TylerSowers/TheSweetBabyGang
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite episode to use new structure #2
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
type PlatformReference struct {
Code string `gorm:"primaryKey"`
Name string
Priority int
}
type PlatformLink struct {
Episode string `gorm:"primaryKey"`
Platform string `gorm:"primaryKey"` // PlatformReference::Code
Link string
Title string // for similarity
}
func (e Episode) GetPlatforms() []PlatformLink {
ret := []PlatformLink{}
db, err := Connect()
if err != nil {
fmt.Println("\x1b[91;1mEpisode.GetPlatforms; Connect():\x1b[m " + err.Error())
return ret
}
db.Debug().Model(&PlatformLink{
Episode: e.Code,
})
.Joins("LEFT JOIN platform_reference ON platform_reference.code = platform_link.platform")
.Order("priority ASC")
.Scan(&ret)
return ret
}
func (l PlatformLink) GetEpisode() Episode {
return GetParent(Episode{ Code: l.Episode })
} |
type RecordGuest struct {
Code string `gorm:"primaryKey"` // ID, no spaces, eg `knowles` or `kirk_cameron`
Name string // Full name, eg `Michael Knowles` or `Kirk Cameron`
Image string // Just the face
}
type EpisodeRecord struct {
Episode string `gorm:"primaryKey"`
Format string // yes-or-no, face-off, etc
Host string // RecordGuest::Code
Players string // []RecordGuest::Code separated by space; includes host
}
type RecordEntry struct {
Episode string `gorm:"primaryKey"`
Placement string `gorm:"primaryKey;autoIncrement=false"`
Question string
Winners string // []RecordGuest::Code separated by space; includes host
}
type RecordScore struct {
Player RecordGuest
Score int
}
func (e Episode) GetRecord() EpisodeRecord {
return GetParent(EpisodeRecord{ Episode: e.Code })
}
func (r EpisodeRecord) GetEpisode() Episode {
return GetParent(Episode{ Code: r.Episode })
}
func (r EpisodeRecord) GetQuestions() []RecordEntry {
return GetChildren(RecordEntry{ Episode: r.Episode })
}
func (r EpisodeRecord) GetScores() []RecordScore {
db, err := Connect()
if err != nil {
fmt.Println("\x1b[91;1mEpisodeRecord.GetScores; Connect():\x1b[0m " + err.Error())
return nil
}
scores := []RecordScore{}
for _, player := range r.GetPlayers()
count := 0
db.Model(&RecordEntry)
.Where("winners LIKE ?", "%" + name + "%")
.Count(&count)
record := RecordScore{ player, count }
scores = append(scores, record)
}
slices.SortFunc(scores, func(a, b RecordScore) int {
return a.Score - b.Score
})
return scores
}
func (r EpisodeRecord) GetPlayers() []RecordGuest {
return (RecordGuest{ Code: r.Players }).Split()
}
func (r RecordEntry) GetWinners() []RecordGuest {
return (RecordGuest{ Code: r.Winners }).Split()
}
func (g RecordGuest) Split() []RecordGuest {
guests := []RecordGuest{}
db, err := Connect()
if err != nil {
fmt.Println("\x1b[91;1mRecordGuest.Split; Connect():\x1b[0m " + err.Error())
return guests
}
names := strings.Split(g.Code, " ")
db.Where("code IN ?", names).Find(&guests)
return guests
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/users/VoxelPrismatic/projects/4/views/1?pane=issue&itemId=86806178
The text was updated successfully, but these errors were encountered: