(WIP) Refresh & Access

This commit is contained in:
2021-01-17 23:56:56 -05:00
parent cd97b6262f
commit 377903f7a1
14 changed files with 366 additions and 136 deletions

View File

@@ -1,40 +1,53 @@
package models
import (
"github.com/google/uuid"
"gorm.io/gorm"
"time"
)
// Might not even need this
// Base contains common columns for all tables.
type Base struct {
UUID uuid.UUID `gorm:"type:uuid;default:default:uuid_generate_v4();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 {
gorm.Model
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 {
gorm.Model
User User `json:"user" gorm:"ForeignKey:ID"`
DeviceName string `json:"name"`
Type string `json:"type"` // Android, iOS, Chrome, FireFox, Edge, etc
Base
User User `json:"user" gorm:"ForeignKey:UUID"`
Name string `json:"name"`
Type string `json:"type"` // Android, iOS, Chrome, FireFox, Edge, etc
RefreshExp string `json:"refresh_exp"`
RefreshToken string `json:"-"`
}
// TODO: ID -> UUID?
type User struct {
gorm.Model
Base
Email string `json:"email" gorm:"unique"`
Username string `json:"username" gorm:"unique"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
AuthType string `json:"auth_type" gorm:"default:Local;not null"`
Password string `json:"-"`
JWTSecret string `json:"-" gorm:"unique;not null"` // TODO: Auto Generate UUID
}
type MediaItem struct {
gorm.Model
User User `json:"user" gorm:"ForeignKey:ID;not null"`
Base
User User `json:"user" gorm:"ForeignKey:UUID;not null"`
EXIFDate time.Time `json:"exif_date"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
@@ -45,11 +58,11 @@ type MediaItem struct {
}
type Tag struct {
gorm.Model
Base
Name string `json:"name" gorm:"not null"`
}
type Album struct {
gorm.Model
Base
Name string `json:"name" gorm:"not null"`
}