2025-06-21 12:42:09 +03:00

169 lines
4.2 KiB
Go

package schemas
import "time"
type Language struct {
ID uint `gorm:",unique;autoIncrement:true"`
Code string `gorm:"primaryKey;index:,unique"`
ISO *string
}
type Genre struct {
ID uint `gorm:",unique;autoIncrement:true"`
RawTag string `gorm:"index:,unique"`
Tag *string
Name *string
}
type Author struct {
ID uint `gorm:"primaryKey;index:,unique;autoIncrement:true"`
Key string `gorm:",unique"`
FirstName string
MiddleName *string
LastName *string
IsBanned *bool
BanReason *string
Books []Book `gorm:"many2many:BookAuthor"`
}
type User struct {
ID uint `gorm:"primaryKey"`
Username string `gorm:"autoIncrement:false;index:,unique"`
Avatar *string
Name *string
Admin bool
Lang *string
Language *Language `gorm:"foreignKey:Lang"`
LastSeen time.Time
Created time.Time
Password string
OTPToken *string
//Favorites []Book `gorm:"many2many:FavoriteBook;ForeignKey:username"`
BookShelf []ReaderBook
}
type Translator struct {
ID uint `gorm:"primaryKey;index:,unique;autoIncrement:true"`
Key string `gorm:",unique"`
FirstName string
MiddleName *string
LastName *string
}
type Sequence struct {
ID uint `gorm:",unique;autoIncrement:true"`
Name string `gorm:"primaryKey;index:,unique"`
}
type Publisher struct {
ID uint `gorm:",unique;autoIncrement:true"`
Name string `gorm:"primaryKey;index:,unique"`
}
type Book struct {
ID uint64 `gorm:"primaryKey"`
Title string
Authors []Author `gorm:"many2many:BookAuthor;References:ID"`
Lang *string
Language Language `gorm:"foreignKey:Lang"`
Genre *[]Genre `gorm:"many2many:BookGenre;References:RawTag"`
Description *string `gorm:"type:text"`
HasCover bool
IsTranslated bool
Translators *[]Translator `gorm:"many2many:BookTranslator;References:ID"`
SrcLang *string
SrcLanguage Language `gorm:"foreignKey:SrcLang"`
Sequence *string
SequenceID *Sequence `gorm:"foreignKey:Sequence"`
SequenceBook *int
Year *int
Publisher *string
PublisherID *Publisher `gorm:"foreignKey:Publisher"`
Isbn *string
Downloads int `gorm:"default:0"`
Views int `gorm:"default:0"`
SymbolsCount *int
PagesCount *int // pdf
Size int
Hash *string
Bookcase *string
Filename string
// FiletypeID uint
Filetype string
UploadedByID *uint
UploadedBy *User
UploadedAt *time.Time
Collections []Collection `gorm:"many2many:CollectionBook;"`
ExternalCover *string
}
// type Filetype struct {
// ID uint `gorm:"primaryKey"`
// Filetype string `gorm:"uniqueIndex"`
// Name string
// }
type ReaderBook struct {
ID uint `gorm:"primaryKey"`
UserID uint
BookID uint
Book Book `gorm:"foreignKey:BookID"`
Progress float64
LastRead time.Time
}
type Collection struct {
ID uint `gorm:"primaryKey"`
Link string `gorm:"uniqueIndex"`
Name string
UserID uint
Creator User `gorm:"foreignKey:UserID"`
Books []Book `gorm:"many2many:CollectionBook;"`
Created time.Time
Modified time.Time
}
type Share struct {
ID uint `gorm:"primaryKey"`
Token string `gorm:"uniqueIndex"`
CreatedAt time.Time
ExpiredAt *time.Time
BookID *uint
Book *Book
UserID uint
User User
}
type Permission struct {
ID uint `gorm:"primaryKey"`
User User `gorm:"foreignKey:ID"`
EditBooks []Book `gorm:"many2many:EditableBook;"`
BooksWhitelist *[]Book `gorm:"many2many:WhitelistedBook;"`
EditCollections []Collection `gorm:"many2many:EditCollection;"`
ViewCollections []Collection `gorm:"many2many:ViewCollection;"`
CanShare bool
CanSearch bool
CanUpload bool
CanCreateCollections bool
}
type Settings struct {
LibPath string
ReadOnly bool
MultiUsers bool
}
// таблицы индексы FTS5
type BooksIndex struct {
RowId uint64 `gorm:"column:rowid"`
Title string
}
type AuthorsIndex struct {
RowId uint64 `gorm:"column:rowid"`
Key string
}
type TagsIndex struct {
RowId uint64 `gorm:"column:rowid"`
Name string
}
type SequencesIndex struct {
RowId uint64 `gorm:"column:rowid"`
Name string
}