Add notification data
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Melody Becker 2025-04-04 11:26:03 +02:00
parent 500bf48295
commit f3a139b809
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
6 changed files with 103 additions and 34 deletions

View file

@ -0,0 +1,41 @@
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)
}