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/notification.go

41 lignes
958 o
Go
Brut Vue normale Historique

package models
2017-05-20 20:53:05 +02:00
import (
2017-08-03 03:38:07 +02:00
"errors"
2017-08-02 22:15:59 +02:00
"time"
2017-05-20 20:53:05 +02:00
"github.com/NyaaPantsu/nyaa/config"
)
// Notification model
2017-05-20 20:53:05 +02:00
type Notification struct {
2017-05-24 09:11:13 +02:00
ID uint
Content string
Read bool
2017-05-20 20:53:05 +02:00
Identifier string
URL string
2017-08-02 22:15:59 +02:00
Expire time.Time
2017-10-29 00:17:31 +02:00
Date time.Time
2017-05-24 09:11:13 +02:00
UserID uint
// User *User `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"` // Don't think that we need it here
2017-05-20 20:53:05 +02:00
}
// NewNotification : Create a new notification
2017-05-21 00:02:57 +02:00
func NewNotification(identifier string, c string, url string) Notification {
2017-10-29 00:17:31 +02:00
return Notification{Identifier: identifier, Content: c, URL: url, Date: time.Now()}
2017-05-20 20:53:05 +02:00
}
// TableName : Return the name of notification table
2017-05-20 20:53:05 +02:00
func (n *Notification) TableName() string {
return config.Get().Models.NotificationsTableName
2017-05-20 20:53:05 +02:00
}
2017-08-03 03:38:07 +02:00
// Delete a notification
func (n *Notification) Delete() error {
if n.ID == 0 {
return errors.New("Can't delete a non existent notification")
}
ORM.Where("id = ?", n.ID).Delete(n)
return nil
}