mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
- Core Go application with GraphQL API using gqlgen - Comprehensive data models for literary works, authors, translations - Repository pattern with caching layer - Authentication and authorization system - Linguistics analysis capabilities with multiple adapters - Vector search integration with Weaviate - Docker containerization support - Python data migration and analysis scripts - Clean architecture with proper separation of concerns - Production-ready configuration and middleware - Proper .gitignore excluding vendor/, database files, and build artifacts
217 lines
6.8 KiB
Go
217 lines
6.8 KiB
Go
package models
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
// WorkStatus represents the status of a work
|
|
type WorkStatus string
|
|
|
|
const (
|
|
WorkStatusDraft WorkStatus = "draft"
|
|
WorkStatusPublished WorkStatus = "published"
|
|
WorkStatusArchived WorkStatus = "archived"
|
|
WorkStatusDeleted WorkStatus = "deleted"
|
|
)
|
|
|
|
// WorkType represents the type of literary work
|
|
type WorkType string
|
|
|
|
const (
|
|
WorkTypePoetry WorkType = "poetry"
|
|
WorkTypeProse WorkType = "prose"
|
|
WorkTypeDrama WorkType = "drama"
|
|
WorkTypeEssay WorkType = "essay"
|
|
WorkTypeNovel WorkType = "novel"
|
|
WorkTypeShortStory WorkType = "short_story"
|
|
WorkTypeNovella WorkType = "novella"
|
|
WorkTypePlay WorkType = "play"
|
|
WorkTypeScript WorkType = "script"
|
|
WorkTypeOther WorkType = "other"
|
|
)
|
|
|
|
// Work represents a literary work in its original form
|
|
type Work struct {
|
|
TranslatableModel
|
|
Title string `gorm:"size:255;not null"`
|
|
Description string `gorm:"type:text"`
|
|
Type WorkType `gorm:"size:50;default:'other'"`
|
|
Status WorkStatus `gorm:"size:50;default:'draft'"`
|
|
PublishedAt *time.Time
|
|
Translations []Translation `gorm:"polymorphic:Translatable"`
|
|
Authors []*Author `gorm:"many2many:work_authors"`
|
|
Tags []*Tag `gorm:"many2many:work_tags"`
|
|
Categories []*Category `gorm:"many2many:work_categories"`
|
|
Copyrights []Copyright `gorm:"polymorphic:Copyrightable"`
|
|
Monetizations []Monetization `gorm:"polymorphic:Monetizable"`
|
|
}
|
|
|
|
// AuthorStatus represents the status of an author
|
|
type AuthorStatus string
|
|
|
|
const (
|
|
AuthorStatusActive AuthorStatus = "active"
|
|
AuthorStatusInactive AuthorStatus = "inactive"
|
|
AuthorStatusDeceased AuthorStatus = "deceased"
|
|
)
|
|
|
|
// Author represents a creator of literary works
|
|
type Author struct {
|
|
TranslatableModel
|
|
Name string `gorm:"size:255;not null"`
|
|
Status AuthorStatus `gorm:"size:50;default:'active'"`
|
|
BirthDate *time.Time
|
|
DeathDate *time.Time
|
|
Works []*Work `gorm:"many2many:work_authors"`
|
|
Books []*Book `gorm:"many2many:book_authors"`
|
|
CountryID *uint
|
|
Country *Country `gorm:"foreignKey:CountryID"`
|
|
CityID *uint
|
|
City *City `gorm:"foreignKey:CityID"`
|
|
PlaceID *uint
|
|
Place *Place `gorm:"foreignKey:PlaceID"`
|
|
AddressID *uint
|
|
Address *Address `gorm:"foreignKey:AddressID"`
|
|
Translations []Translation `gorm:"polymorphic:Translatable"`
|
|
Copyrights []Copyright `gorm:"polymorphic:Copyrightable"`
|
|
Monetizations []Monetization `gorm:"polymorphic:Monetizable"`
|
|
}
|
|
|
|
// BookStatus represents the status of a book
|
|
type BookStatus string
|
|
|
|
const (
|
|
BookStatusDraft BookStatus = "draft"
|
|
BookStatusPublished BookStatus = "published"
|
|
BookStatusOutOfPrint BookStatus = "out_of_print"
|
|
BookStatusArchived BookStatus = "archived"
|
|
)
|
|
|
|
// BookFormat represents the format of a book
|
|
type BookFormat string
|
|
|
|
const (
|
|
BookFormatHardcover BookFormat = "hardcover"
|
|
BookFormatPaperback BookFormat = "paperback"
|
|
BookFormatEbook BookFormat = "ebook"
|
|
BookFormatAudiobook BookFormat = "audiobook"
|
|
BookFormatDigital BookFormat = "digital"
|
|
)
|
|
|
|
// Book represents a physical or digital book that may contain multiple works
|
|
type Book struct {
|
|
TranslatableModel
|
|
Title string `gorm:"size:255;not null"`
|
|
Description string `gorm:"type:text"`
|
|
ISBN string `gorm:"size:20;index"`
|
|
Format BookFormat `gorm:"size:50;default:'paperback'"`
|
|
Status BookStatus `gorm:"size:50;default:'draft'"`
|
|
PublishedAt *time.Time
|
|
Works []*Work `gorm:"many2many:book_works"`
|
|
Authors []*Author `gorm:"many2many:book_authors"`
|
|
PublisherID *uint
|
|
Publisher *Publisher `gorm:"foreignKey:PublisherID"`
|
|
Translations []Translation `gorm:"polymorphic:Translatable"`
|
|
Copyrights []Copyright `gorm:"polymorphic:Copyrightable"`
|
|
Monetizations []Monetization `gorm:"polymorphic:Monetizable"`
|
|
}
|
|
|
|
// PublisherStatus represents the status of a publisher
|
|
type PublisherStatus string
|
|
|
|
const (
|
|
PublisherStatusActive PublisherStatus = "active"
|
|
PublisherStatusInactive PublisherStatus = "inactive"
|
|
PublisherStatusDefunct PublisherStatus = "defunct"
|
|
)
|
|
|
|
// Publisher represents a book publisher
|
|
type Publisher struct {
|
|
TranslatableModel
|
|
Name string `gorm:"size:255;not null"`
|
|
Description string `gorm:"type:text"`
|
|
Status PublisherStatus `gorm:"size:50;default:'active'"`
|
|
Books []*Book `gorm:"foreignKey:PublisherID"`
|
|
CountryID *uint
|
|
Country *Country `gorm:"foreignKey:CountryID"`
|
|
Translations []Translation `gorm:"polymorphic:Translatable"`
|
|
Copyrights []Copyright `gorm:"polymorphic:Copyrightable"`
|
|
Monetizations []Monetization `gorm:"polymorphic:Monetizable"`
|
|
}
|
|
|
|
// SourceStatus represents the status of a source
|
|
type SourceStatus string
|
|
|
|
const (
|
|
SourceStatusActive SourceStatus = "active"
|
|
SourceStatusInactive SourceStatus = "inactive"
|
|
SourceStatusArchived SourceStatus = "archived"
|
|
)
|
|
|
|
// Source represents an original source of literary content
|
|
type Source struct {
|
|
TranslatableModel
|
|
Name string `gorm:"size:255;not null"`
|
|
Description string `gorm:"type:text"`
|
|
URL string `gorm:"size:512"`
|
|
Status SourceStatus `gorm:"size:50;default:'active'"`
|
|
Works []*Work `gorm:"many2many:work_sources"`
|
|
Translations []Translation `gorm:"polymorphic:Translatable"`
|
|
Copyrights []Copyright `gorm:"polymorphic:Copyrightable"`
|
|
Monetizations []Monetization `gorm:"polymorphic:Monetizable"`
|
|
}
|
|
|
|
// EditionStatus represents the status of an edition
|
|
type EditionStatus string
|
|
|
|
const (
|
|
EditionStatusDraft EditionStatus = "draft"
|
|
EditionStatusPublished EditionStatus = "published"
|
|
EditionStatusOutOfPrint EditionStatus = "out_of_print"
|
|
EditionStatusArchived EditionStatus = "archived"
|
|
)
|
|
|
|
// Edition represents a specific edition of a book
|
|
type Edition struct {
|
|
BaseModel
|
|
Title string `gorm:"size:255;not null"`
|
|
Description string `gorm:"type:text"`
|
|
ISBN string `gorm:"size:20;index"`
|
|
Version string `gorm:"size:50"`
|
|
Format BookFormat `gorm:"size:50;default:'paperback'"`
|
|
Status EditionStatus `gorm:"size:50;default:'draft'"`
|
|
PublishedAt *time.Time
|
|
BookID uint
|
|
Book *Book `gorm:"foreignKey:BookID"`
|
|
}
|
|
|
|
// BeforeSave hooks for validation
|
|
func (w *Work) BeforeSave(tx *gorm.DB) error {
|
|
if w.Title == "" {
|
|
w.Title = "Untitled Work"
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (a *Author) BeforeSave(tx *gorm.DB) error {
|
|
if a.Name == "" {
|
|
a.Name = "Unknown Author"
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (b *Book) BeforeSave(tx *gorm.DB) error {
|
|
if b.Title == "" {
|
|
b.Title = "Untitled Book"
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Publisher) BeforeSave(tx *gorm.DB) error {
|
|
if p.Name == "" {
|
|
p.Name = "Unknown Publisher"
|
|
}
|
|
return nil
|
|
}
|