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

33 lignes
829 o
Go
Brut Vue normale Historique

2017-07-29 15:20:57 +02:00
package tags
2017-07-30 03:29:09 +02:00
import (
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/cache"
2017-07-30 03:29:09 +02:00
"github.com/pkg/errors"
)
2017-07-29 15:20:57 +02:00
// Create a new tag based on string inputs
2017-07-29 15:20:57 +02:00
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,
}
return New(newTag, torrent)
}
2017-07-29 15:20:57 +02:00
// New is the low level functions that actually create a tag in db
func New(tag *models.Tag, torrent *models.Torrent) (*models.Tag, error) {
2017-07-30 03:29:09 +02:00
if torrent.ID == 0 {
return tag, errors.New("Can't add a tag to no torrents")
2017-07-30 03:29:09 +02:00
}
if err := models.ORM.Create(tag).Error; err != nil {
return tag, err
2017-07-29 15:20:57 +02:00
}
cache.C.Delete(torrent.Identifier())
return tag, nil
2017-07-29 15:20:57 +02:00
}