Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/models/tag/create.go

27 lignes
626 o
Go

package tags
import (
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/cache"
"github.com/pkg/errors"
)
func Create(tag string, tagType string, torrent *models.Torrent, user *models.User) (*models.Tag, error) {
newTag := &models.Tag{
Tag: tag,
Type: tagType,
TorrentID: torrent.ID,
UserID: user.ID,
Weight: user.Pantsu,
Accepted: false,
}
if torrent.ID == 0 {
return newTag, errors.New("Can't add a tag to no torrents")
}
if err := models.ORM.Create(newTag).Error; err != nil {
return newTag, err
}
cache.C.Delete(torrent.Identifier())
return newTag, nil
}