70 lines
2.9 KiB
Go
70 lines
2.9 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
"gorm.io/gorm"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Base contains common columns for all tables.
|
|
type Base struct {
|
|
UUID uuid.UUID `json:"uuid" gorm:"type:uuid;primarykey"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
}
|
|
|
|
func (base *Base) BeforeCreate(tx *gorm.DB) (err error) {
|
|
base.UUID = uuid.New()
|
|
return
|
|
}
|
|
|
|
type ServerSetting struct {
|
|
Base
|
|
Name string `json:"name" gorm:"not null"`
|
|
Description string `json:"description" gorm:"not null"`
|
|
Value string `json:"value" gorm:"not null"`
|
|
}
|
|
|
|
type Device struct {
|
|
Base
|
|
User User `json:"user" gorm:"ForeignKey:UUID;not null"` // User UUID
|
|
Name string `json:"name" gorm:"not null"` // Name of Device
|
|
Type string `json:"type" gorm:"not null"` // Android, iOS, Chrome, FireFox, Edge
|
|
RefreshKey string `json:"-"` // Device Specific Refresh Key
|
|
}
|
|
|
|
type User struct {
|
|
Base
|
|
Email string `json:"email" gorm:"unique"` // Email
|
|
Username string `json:"username" gorm:"unique"` // Username
|
|
FirstName string `json:"first_name"` // First Name
|
|
LastName string `json:"last_name"` // Last Name
|
|
Role string `json:"role"` // Role
|
|
AuthType string `json:"auth_type" gorm:"default:Local;not null"` // Auth Type (E.g. Local, LDAP)
|
|
Password string `json:"-"` // Hased & Salted Password
|
|
}
|
|
|
|
type MediaItem struct {
|
|
Base
|
|
User User `json:"user" gorm:"ForeignKey:UUID;not null"` // User UUID
|
|
EXIFDate time.Time `json:"exif_date"` // EXIF Date
|
|
Latitude float32 `json:"latitude" gorm:"type:decimal(10,2)"` // Decimal Latitude
|
|
Longitude float32 `json:"longitude" gorm:"type:decimal(10,2)"` // Decimal Longitude
|
|
MediaType string `json:"media_type" gorm:"default:Image;not null"` // Image, Video
|
|
OrigName string `json:"orig_name" gorm:"not null"` // Original Name
|
|
FileName string `json:"file_name" gorm:"not null"` // File Name
|
|
Tags []Tag `json:"tags" gorm:"many2many:media_tags;"` // Associated Tag UUIDs
|
|
Albums []Album `json:"albums" gorm:"many2many:media_albums;"` // Associated Album UUIDs
|
|
}
|
|
|
|
type Tag struct {
|
|
Base
|
|
Name string `json:"name" gorm:"not null"` // Tag Name
|
|
}
|
|
|
|
type Album struct {
|
|
Base
|
|
Name string `json:"name" gorm:"not null"` // Album Name
|
|
}
|