Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Add modified torrent models + comments on Contains and HasAccepted function
Cette révision appartient à :
akuma06 2017-08-01 11:17:25 +02:00
Parent b21a09b9d4
révision 3bd6a0ab8f
2 fichiers modifiés avec 15 ajouts et 4 suppressions

Voir le fichier

@ -42,11 +42,22 @@ func (ta *Tag) toMap() map[string]interface{} {
type Tags []Tag
func (ts *Tags) Contains(tag Tag) bool {
for _, ta := range *ts {
// Contains check if the tag map has the same tag in it (tag value + tag type)
func (ts Tags) Contains(tag Tag) bool {
for _, ta := range ts {
if ta.Tag == tag.Tag && ta.Type == tag.Type {
return true
}
}
return false
}
// HasAccepted check if a tag has been accepted in the tags map
func (ts Tags) HasAccepted() bool {
for _, tag := range ts {
if tag.Accepted {
return true
}
}
return false
}

Voir le fichier

@ -63,7 +63,7 @@ type Torrent struct {
OldUploader string `gorm:"-"` // ???????
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
Comments []Comment `gorm:"ForeignKey:torrent_id"`
Tags []Tag `gorm:"-"`
Tags Tags `gorm:"-"`
Scrape *Scrape `gorm:"AssociationForeignKey:ID;ForeignKey:torrent_id"`
FileList []File `gorm:"ForeignKey:torrent_id"`
Languages []string `gorm:"-"` // This is parsed when retrieved from db
@ -98,7 +98,7 @@ type TorrentJSON struct {
Completed uint32 `json:"completed"`
LastScrape time.Time `json:"last_scrape"`
FileList []FileJSON `json:"file_list"`
Tags []Tag `json:"-"` // not needed in json to reduce db calls
Tags Tags `json:"-"` // not needed in json to reduce db calls
}
// Size : Returns the total size of memory recursively allocated for this struct