This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/models/db.go

70 lines
2.9 KiB
Go
Raw Normal View History

2021-01-12 04:48:32 +00:00
package models
import (
"time"
2021-01-18 21:24:28 +00:00
"gorm.io/gorm"
"github.com/google/uuid"
2021-01-12 04:48:32 +00:00
)
2021-01-18 04:56:56 +00:00
// Base contains common columns for all tables.
type Base struct {
2021-01-22 05:00:55 +00:00
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"`
2021-01-18 04:56:56 +00:00
}
func (base *Base) BeforeCreate(tx *gorm.DB) (err error) {
base.UUID = uuid.New()
return
}
2021-01-12 04:48:32 +00:00
type ServerSetting struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
Name string `json:"name" gorm:"not null"`
2021-01-16 22:00:17 +00:00
Description string `json:"description" gorm:"not null"`
2021-01-22 05:00:55 +00:00
Value string `json:"value" gorm:"not null"`
2021-01-12 04:48:32 +00:00
}
2021-01-16 22:00:17 +00:00
type Device struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
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
2021-01-16 22:00:17 +00:00
}
2021-01-12 04:48:32 +00:00
type User struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
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
2021-01-12 04:48:32 +00:00
}
type MediaItem struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
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
2021-01-12 04:48:32 +00:00
}
type Tag struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
Name string `json:"name" gorm:"not null"` // Tag Name
2021-01-12 04:48:32 +00:00
}
type Album struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-22 05:00:55 +00:00
Name string `json:"name" gorm:"not null"` // Album Name
2021-01-12 04:48:32 +00:00
}