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

69 lines
2.0 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-18 21:16:52 +00:00
UUID uuid.UUID `gorm:"type:uuid;primarykey"`
2021-01-18 21:24:28 +00:00
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `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-16 22:00:17 +00:00
Name string `json:"name" gorm:"not null"`
Description string `json:"description" gorm:"not null"`
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-19 20:50:48 +00:00
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
2021-01-18 21:16:52 +00:00
RefreshKey string `json:"-"`
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-16 22:00:17 +00:00
Email string `json:"email" gorm:"unique"`
Username string `json:"username" gorm:"unique"`
2021-01-12 04:48:32 +00:00
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
2021-01-19 20:50:48 +00:00
Role string `json:"role"`
2021-01-16 22:00:17 +00:00
AuthType string `json:"auth_type" gorm:"default:Local;not null"`
Password string `json:"-"`
2021-01-12 04:48:32 +00:00
}
type MediaItem struct {
2021-01-18 04:56:56 +00:00
Base
User User `json:"user" gorm:"ForeignKey:UUID;not null"`
2021-01-12 04:48:32 +00:00
EXIFDate time.Time `json:"exif_date"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
2021-01-16 22:00:17 +00:00
MediaType string `json:"media_type" gorm:"default:Photo;not null"` // Photo, Video
RelPath string `json:"rel_path" gorm:"not null"`
2021-01-12 04:48:32 +00:00
Tags []Tag `json:"tags" gorm:"many2many:media_tags;"`
Albums []Album `json:"albums" gorm:"many2many:media_albums;"`
}
type Tag struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-16 22:00:17 +00:00
Name string `json:"name" gorm:"not null"`
2021-01-12 04:48:32 +00:00
}
type Album struct {
2021-01-18 04:56:56 +00:00
Base
2021-01-16 22:00:17 +00:00
Name string `json:"name" gorm:"not null"`
2021-01-12 04:48:32 +00:00
}