package models import ( "database/sql" "gorm.io/gen" "gorm.io/gorm" ) // Notifications inform users of inbound events // happening to their content type Notification struct { gorm.Model ForUser User // The user the notification is for ForUserId string SourceNote *Note // The note where the notification originates from SourceNoteId sql.NullString SourceUser *User // The user causing the notification SourceUserId sql.NullString Cause NotificationCauseType // What the cause of the notification is ViewedState NotificationViewedState // What the last known state of the notification is } type INotification interface { // Update a given set of notifications to a given viewed state. // State should be a [NotificationViewedStateType] // // UPDATE @@table SET viewed_state = @state WHERE id IN @ids SetState(state uint8, ids ...uint) error // Get the lastest count amount of notifications with a given offset for a user // // SELECT * FROM @@table WHERE for_user_id = @userId // ORDER BY id DESC // {{if count > 0 }} // LIMIT @count // {{else}} // LIMIT 20 // {{end}} // OFFSET @offset GetLatestWithOffset(userId string, count uint, offset uint) ([]gen.T, error) }