tercul-backend/models/base.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- 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
2025-08-13 07:42:32 +02:00

64 lines
1.4 KiB
Go

package models
import (
"database/sql/driver"
"encoding/json"
"fmt"
"time"
)
// JSONB is a custom type for JSONB columns.
type JSONB map[string]interface{}
// Value marshals JSONB for storing in the DB.
func (j JSONB) Value() (driver.Value, error) {
if j == nil {
return "{}", nil
}
return json.Marshal(j)
}
// Scan unmarshals a JSONB value.
func (j *JSONB) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return fmt.Errorf("failed to unmarshal JSONB value: %v", value)
}
return json.Unmarshal(bytes, j)
}
// BaseModel contains common fields for all models
type BaseModel struct {
ID uint `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
}
// TranslatableModel extends BaseModel with language support
type TranslatableModel struct {
BaseModel
Language string `gorm:"size:50;default:'multi'"`
Slug string `gorm:"size:255;index"`
}
// Translation status enum
type TranslationStatus string
const (
TranslationStatusDraft TranslationStatus = "draft"
TranslationStatusPublished TranslationStatus = "published"
TranslationStatusReviewing TranslationStatus = "reviewing"
TranslationStatusRejected TranslationStatus = "rejected"
)
// UserRole enum
type UserRole string
const (
UserRoleReader UserRole = "reader"
UserRoleContributor UserRole = "contributor"
UserRoleReviewer UserRole = "reviewer"
UserRoleEditor UserRole = "editor"
UserRoleAdmin UserRole = "admin"
)