mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
package fixtures
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Work fixtures for testing
|
|
var (
|
|
// ClassicNovel is a fixture for a classic novel
|
|
ClassicNovel = domain.Work{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: 1,
|
|
CreatedAt: time.Now().Add(-365 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-30 * 24 * time.Hour),
|
|
},
|
|
Language: "ru",
|
|
},
|
|
Title: "War and Peace",
|
|
Description: "Epic historical novel by Leo Tolstoy",
|
|
Type: "novel",
|
|
Status: "published",
|
|
}
|
|
|
|
// ModernPoetry is a fixture for modern poetry
|
|
ModernPoetry = domain.Work{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: 2,
|
|
CreatedAt: time.Now().Add(-180 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-10 * 24 * time.Hour),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Title: "The Waste Land",
|
|
Description: "Modernist poem by T.S. Eliot",
|
|
Type: "poetry",
|
|
Status: "published",
|
|
}
|
|
|
|
// ShortStory is a fixture for a short story
|
|
ShortStory = domain.Work{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: 3,
|
|
CreatedAt: time.Now().Add(-90 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-5 * 24 * time.Hour),
|
|
},
|
|
Language: "de",
|
|
},
|
|
Title: "The Metamorphosis",
|
|
Description: "Novella by Franz Kafka",
|
|
Type: "novella",
|
|
Status: "published",
|
|
}
|
|
|
|
// DraftWork is a fixture for a work in draft status
|
|
DraftWork = domain.Work{
|
|
TranslatableModel: domain.TranslatableModel{
|
|
BaseModel: domain.BaseModel{
|
|
ID: 4,
|
|
CreatedAt: time.Now().Add(-7 * 24 * time.Hour),
|
|
UpdatedAt: time.Now().Add(-1 * time.Hour),
|
|
},
|
|
Language: "en",
|
|
},
|
|
Title: "Untitled Work",
|
|
Description: "Work in progress",
|
|
Type: "novel",
|
|
Status: "draft",
|
|
}
|
|
)
|
|
|
|
// AllWorks returns all work fixtures
|
|
func AllWorks() []domain.Work {
|
|
return []domain.Work{
|
|
ClassicNovel,
|
|
ModernPoetry,
|
|
ShortStory,
|
|
DraftWork,
|
|
}
|
|
}
|
|
|
|
// LoadWorks loads work fixtures into the database
|
|
func LoadWorks(ctx context.Context, db *gorm.DB) error {
|
|
for _, work := range AllWorks() {
|
|
if err := db.Create(&work).Error; err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|