diff --git a/go.mod b/go.mod index 9dcb619..4b598af 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,9 @@ module git.dragse.it/anthrove/otter-space-sdk go 1.22.0 require ( + github.com/brianvoe/gofakeit/v7 v7.0.3 github.com/lib/pq v1.10.7 + github.com/matoous/go-nanoid/v2 v2.1.0 github.com/neo4j/neo4j-go-driver/v5 v5.17.0 github.com/rubenv/sql-migrate v1.6.1 github.com/sirupsen/logrus v1.9.3 @@ -19,7 +21,6 @@ require ( github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect - github.com/matoous/go-nanoid/v2 v2.1.0 // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.18.0 // indirect diff --git a/go.sum b/go.sum index f00d304..9cd0cd1 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/brianvoe/gofakeit/v7 v7.0.3 h1:tGCt+eYfhTMWE1ko5G2EO1f/yE44yNpIwUb4h32O0wo= +github.com/brianvoe/gofakeit/v7 v7.0.3/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -42,8 +44,8 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= diff --git a/internal/postgres/tag.go b/internal/postgres/tag.go index 1dc97b1..d873506 100644 --- a/internal/postgres/tag.go +++ b/internal/postgres/tag.go @@ -36,3 +36,17 @@ func CreateTagNodeWitRelation(ctx context.Context, db *gorm.DB, PostID models.An return nil } + +func GetTags(ctx context.Context, db *gorm.DB) ([]pgModels.Tag, error) { + var tags []pgModels.Tag + result := db.WithContext(ctx).Find(&tags) + if result.Error != nil { + return nil, result.Error + } + + log.WithFields(log.Fields{ + "tag_amount": len(tags), + }).Trace("database: got tags") + + return tags, nil +} diff --git a/internal/utils/modelConvert.go b/internal/utils/modelConvert.go index 080af20..29a4995 100644 --- a/internal/utils/modelConvert.go +++ b/internal/utils/modelConvert.go @@ -45,3 +45,16 @@ func PostgresConvertToAnthroveTag(pgTag *pgModels.Tag) *graphModels.AnthroveTag 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 +} diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index e4ee38a..887a62a 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -138,8 +138,9 @@ func (p *postgresqlConnection) GetUserTagsTroughFavedPosts(ctx context.Context, } func (p *postgresqlConnection) GetAllTags(ctx context.Context) ([]graphModels.TagsWithFrequency, error) { - //TODO implement me - panic("implement me") + tags, err := postgres.GetTags(ctx, p.db) + + return utils.ConvertToTagsWithFrequency(tags), err } func (p *postgresqlConnection) GetAllSources(ctx context.Context) ([]graphModels.AnthroveSource, error) {