2024-08-12 13:54:36 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
2024-08-13 13:41:36 +00:00
|
|
|
"time"
|
2024-08-12 13:54:36 +00:00
|
|
|
|
2024-08-29 13:02:39 +00:00
|
|
|
"git.anthrove.art/Anthrove/otter-space-sdk/v4/pkg/models"
|
2024-08-12 13:54:36 +00:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
gonanoid "github.com/matoous/go-nanoid/v2"
|
2024-08-13 13:41:36 +00:00
|
|
|
"gorm.io/gorm"
|
2024-08-12 13:54:36 +00:00
|
|
|
)
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
func GenerateRandomTags(num int) []models.Tag {
|
2024-08-12 13:54:36 +00:00
|
|
|
var tags []models.Tag
|
|
|
|
tagTypes := []models.TagType{"general", "species", "character", "artist", "lore", "meta", "invalid", "copyright"}
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
for i := 0; i < num; i++ {
|
2024-08-12 13:54:36 +00:00
|
|
|
id, _ := gonanoid.New(10)
|
|
|
|
tagName := spew.Sprintf("tag_name_%s", id)
|
|
|
|
|
|
|
|
tagType := tagTypes[rand.Intn(len(tagTypes))]
|
|
|
|
|
|
|
|
tag := models.Tag{
|
|
|
|
Name: models.TagName(tagName),
|
|
|
|
Type: tagType,
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = append(tags, tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
func GenerateRandomTagGroups(tags []models.Tag, num int) []models.TagGroup {
|
2024-08-12 13:54:36 +00:00
|
|
|
var tagGroups []models.TagGroup
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
for i := 0; i < num; i++ {
|
2024-08-12 13:54:36 +00:00
|
|
|
id, _ := gonanoid.New(10)
|
|
|
|
groupName := fmt.Sprintf("tag_group_%s", id)
|
|
|
|
randomTag := tags[rand.Intn(len(tags))]
|
|
|
|
|
|
|
|
tagGroup := models.TagGroup{
|
|
|
|
Name: models.TagGroupName(groupName),
|
|
|
|
TagID: randomTag.Name,
|
|
|
|
}
|
|
|
|
|
|
|
|
tagGroups = append(tagGroups, tagGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tagGroups
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
func GenerateRandomTagAlias(tags []models.Tag, num int) []models.TagAlias {
|
2024-08-12 13:54:36 +00:00
|
|
|
var tagAliases []models.TagAlias
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
for i := 0; i < num; i++ {
|
2024-08-12 13:54:36 +00:00
|
|
|
id, _ := gonanoid.New(10)
|
|
|
|
groupName := fmt.Sprintf("tag_alias_%s", id)
|
|
|
|
randomTag := tags[rand.Intn(len(tags))]
|
|
|
|
|
|
|
|
tagAlias := models.TagAlias{
|
|
|
|
Name: models.TagAliasName(groupName),
|
|
|
|
TagID: randomTag.Name,
|
|
|
|
}
|
|
|
|
|
|
|
|
tagAliases = append(tagAliases, tagAlias)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tagAliases
|
|
|
|
}
|
2024-08-13 13:41:36 +00:00
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
func GenerateRandomSources(num int) []models.Source {
|
2024-08-13 13:41:36 +00:00
|
|
|
var sources []models.Source
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
for i := 0; i < num; i++ {
|
2024-08-13 13:41:36 +00:00
|
|
|
id, _ := gonanoid.New(10)
|
|
|
|
displayName, _ := gonanoid.New(10)
|
|
|
|
domain, _ := gonanoid.New(10)
|
|
|
|
icon, _ := gonanoid.New(10)
|
|
|
|
id = spew.Sprintf("source_name_%s", id)
|
|
|
|
|
|
|
|
source := models.Source{
|
|
|
|
BaseModel: models.BaseModel[models.SourceID]{
|
|
|
|
ID: models.SourceID(id),
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
DeletedAt: gorm.DeletedAt{},
|
|
|
|
},
|
|
|
|
DisplayName: displayName,
|
|
|
|
Domain: models.SourceDomain(domain),
|
|
|
|
Icon: icon,
|
|
|
|
UserSources: nil,
|
|
|
|
References: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
sources = append(sources, source)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sources
|
|
|
|
}
|
2024-08-13 19:17:17 +00:00
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
func GenerateRandomPosts(num int) []models.Post {
|
2024-08-13 19:17:17 +00:00
|
|
|
var sources []models.Post
|
|
|
|
ratings := []models.Rating{"safe", "explicit", "questionable", "unknown"}
|
|
|
|
|
2024-08-14 11:43:11 +00:00
|
|
|
for i := 0; i < num; i++ {
|
2024-08-13 19:17:17 +00:00
|
|
|
id, _ := gonanoid.New(10)
|
|
|
|
id = spew.Sprintf("source_name_%s", id)
|
|
|
|
rating := ratings[rand.Intn(len(ratings))]
|
|
|
|
|
|
|
|
source := models.Post{
|
|
|
|
BaseModel: models.BaseModel[models.PostID]{
|
|
|
|
ID: models.PostID(id),
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
DeletedAt: gorm.DeletedAt{},
|
|
|
|
},
|
|
|
|
Rating: rating,
|
|
|
|
}
|
|
|
|
|
|
|
|
sources = append(sources, source)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sources
|
|
|
|
}
|
2024-08-14 11:43:11 +00:00
|
|
|
|
|
|
|
func GenerateRandomUserFavorites(userID models.UserID, postID models.PostID, userSourceID models.UserSourceID, num int) []models.UserFavorite {
|
|
|
|
var userFavorites []models.UserFavorite
|
|
|
|
|
|
|
|
for i := 0; i < num; i++ {
|
|
|
|
id, _ := gonanoid.New(6)
|
|
|
|
id = spew.Sprintf("user_favorite_name_%s", id)
|
|
|
|
|
|
|
|
source := models.UserFavorite{
|
|
|
|
BaseModel: models.BaseModel[models.UserFavoriteID]{
|
|
|
|
ID: models.UserFavoriteID(id),
|
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
DeletedAt: gorm.DeletedAt{},
|
|
|
|
},
|
|
|
|
UserID: userID,
|
|
|
|
PostID: postID,
|
|
|
|
UserSourceID: userSourceID,
|
|
|
|
}
|
|
|
|
|
|
|
|
userFavorites = append(userFavorites, source)
|
|
|
|
}
|
|
|
|
|
|
|
|
return userFavorites
|
|
|
|
}
|