51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package entities
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type DeviceType string
|
|
type DevicePlatform string
|
|
|
|
const (
|
|
DeviceTypeMobile DeviceType = "mobile"
|
|
DeviceTypeTablet DeviceType = "tablet"
|
|
DeviceTypeDesktop DeviceType = "desktop"
|
|
|
|
DevicePlatformAndroid DevicePlatform = "android"
|
|
DevicePlatformIOS DevicePlatform = "ios"
|
|
DevicePlatformWeb DevicePlatform = "web"
|
|
)
|
|
|
|
type UserDevice struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
|
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
|
|
DeviceID string `gorm:"not null;size:255;index" json:"device_id"`
|
|
DeviceName string `gorm:"size:255" json:"device_name"`
|
|
DeviceType DeviceType `gorm:"size:50" json:"device_type"`
|
|
Platform DevicePlatform `gorm:"size:50" json:"platform"`
|
|
FCMToken string `gorm:"size:512" json:"fcm_token"`
|
|
AppVersion string `gorm:"size:50" json:"app_version"`
|
|
OsVersion string `gorm:"size:50" json:"os_version"`
|
|
IPAddress string `gorm:"size:45" json:"ip_address"`
|
|
LastActiveAt *time.Time `gorm:"type:timestamptz" json:"last_active_at"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
|
}
|
|
|
|
func (u *UserDevice) BeforeCreate(tx *gorm.DB) error {
|
|
if u.ID == uuid.Nil {
|
|
u.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (UserDevice) TableName() string {
|
|
return "user_devices"
|
|
}
|