This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/internal/utils/modelConvert.go

61 lines
1.8 KiB
Go

package utils
import (
"git.dragse.it/anthrove/otter-space-sdk/pkg/models"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/graphModels"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models/pgModels"
)
// GraphConvertSource converts a graphModels.AnthroveSource to a pgModels.Source
func GraphConvertSource(graphSource *graphModels.AnthroveSource) *pgModels.Source {
pgSource := &pgModels.Source{
DisplayName: graphSource.DisplayName,
Domain: graphSource.Domain,
Icon: graphSource.Icon,
}
return pgSource
}
// PostgresConvertToAnthroveSource converts a pgModels.Source to a graphModels.AnthroveSource
func PostgresConvertToAnthroveSource(pgSource *pgModels.Source) *graphModels.AnthroveSource {
graphSource := &graphModels.AnthroveSource{
DisplayName: pgSource.DisplayName,
Domain: pgSource.Domain,
Icon: pgSource.Icon,
}
return graphSource
}
// GraphConvertTag converts a graphModels.AnthroveTag to a pgModels.Tag
func GraphConvertTag(graphTag *graphModels.AnthroveTag) *pgModels.Tag {
pgTag := &pgModels.Tag{
Name: graphTag.Name,
Type: models.TagType(graphTag.Type),
}
return pgTag
}
// PostgresConvertToAnthroveTag converts a pgModels.Tag to a graphModels.AnthroveTag
func PostgresConvertToAnthroveTag(pgTag *pgModels.Tag) *graphModels.AnthroveTag {
graphTag := &graphModels.AnthroveTag{
Name: pgTag.Name,
Type: string(pgTag.Type),
}
return graphTag
}
func ConvertToTagsWithFrequency(tags []pgModels.Tag) []graphModels.TagsWithFrequency {
var tagsWithFrequency []graphModels.TagsWithFrequency
for _, tag := range tags {
graphTag := PostgresConvertToAnthroveTag(&tag)
tagsWithFrequency = append(tagsWithFrequency, graphModels.TagsWithFrequency{
Frequency: 0,
Tags: *graphTag,
})
}
return tagsWithFrequency
}