mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +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
64 lines
1.4 KiB
Go
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"
|
|
)
|