linstrom/storage-new/models/Notification.go
mstar f3a139b809
Some checks are pending
/ test (push) Waiting to run
Add notification data
2025-04-04 11:26:03 +02:00

41 lines
1.2 KiB
Go

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
//
// UPDATE @@table SET viewed_state = @state WHERE id IN @id
SetState(state NotificationViewedState, ids ...uint) error
// Get the lastest count amount of notifications with a given offset for a user
//
// SELECT * FROM @@table WHERE for_user_id = @id
// 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)
}