Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

package Database
import (
"github.com/gofrs/uuid"
"gorm.io/gorm"
)
type FriendRequestDeviceToken struct {
Base
DeviceTokenID uuid.UUID `gorm:"type:uuid;column:device_token_id;not null;" json:"device_token_id"`
DeviceToken DeviceToken `gorm:"not null;" json:"device_token"`
FriendRequestID uuid.UUID `gorm:"type:uuid;column:friend_request_id;not null;" json:"friend_request_id"`
FriendRequest FriendRequest `gorm:"not null;" json:"friend_device_tokens"`
}
type DeviceToken struct {
Base
Token string `gorm:"not null" json:"token"` // Stored encrypted
DeviceType string `gorm:"not null" json:"device_type"` // Stored encrypted
}
func GetUserDeviceTokenById(id string) (DeviceToken, error) {
var (
deviceToken DeviceToken
err error
)
err = DB.First(&deviceToken, "id = ?", id).
Error
return deviceToken, err
}
func (deviceToken *DeviceToken) CreateUserDeviceToken() error {
var err error
err = DB.Session(&gorm.Session{FullSaveAssociations: true}).
Create(deviceToken).
Error
return err
}
func (deviceToken *DeviceToken) DeleteUserDeviceToken() error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Delete(deviceToken).
Error
}