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.go
2017-07-29 14:41:56 +02:00

41 lignes
984 o
Go

package models
import (
"errors"
"net/http"
"github.com/fatih/structs"
)
// Tag model for a torrent vote system
type Tag struct {
TorrentID uint `gorm:"column:torrent_id"`
UserID uint `gorm:"column:user_id"`
Tag string `gorm:"column:tag"`
Type string `gorm:"column:type"`
Weight float64 `gorm:"column:weight"`
Accepted bool `gorm:"column:accepted"`
Total float64 `gorm:"-"`
}
// Update a tag
func (ta *Tag) Update() (int, error) {
if ORM.Model(ta).UpdateColumn(ta.toMap()).Error != nil {
return http.StatusInternalServerError, errors.New("Tag was not updated")
}
return http.StatusOK, nil
}
// Delete : delete a tag based on id
func (ta *Tag) Delete() (int, error) {
if ORM.Delete(ta).Error != nil {
return http.StatusInternalServerError, errors.New("tag_not_deleted")
}
return http.StatusOK, nil
}
// toMap : convert the model to a map of interface
func (ta *Tag) toMap() map[string]interface{} {
return structs.Map(ta)
}