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
2021-01-19 21:18:08 -05:00

69 lines
2.0 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 `gorm:"type:uuid;primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `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"`
Name string `json:"name" gorm:"not null"`
Type string `json:"type" gorm:"not null"` // Android, iOS, Chrome, FireFox, Edge, etc
RefreshKey string `json:"-"`
}
type User struct {
Base
Email string `json:"email" gorm:"unique"`
Username string `json:"username" gorm:"unique"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Role string `json:"role"`
AuthType string `json:"auth_type" gorm:"default:Local;not null"`
Password string `json:"-"`
}
type MediaItem struct {
Base
User User `json:"user" gorm:"ForeignKey:UUID;not null"`
EXIFDate time.Time `json:"exif_date"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
MediaType string `json:"media_type" gorm:"default:Image;not null"` // Image, Video
RelPath string `json:"rel_path" gorm:"not null"`
Tags []Tag `json:"tags" gorm:"many2many:media_tags;"`
Albums []Album `json:"albums" gorm:"many2many:media_albums;"`
}
type Tag struct {
Base
Name string `json:"name" gorm:"not null"`
}
type Album struct {
Base
Name string `json:"name" gorm:"not null"`
}