chore(post): code & folder restructure

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2024-05-31 15:08:24 +02:00
parent 1075d45cb7
commit fc73377d86
12 changed files with 39 additions and 34 deletions

View File

@ -1,4 +1,4 @@
package internal package post
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package internal package relation
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package internal package source
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package internal package tag
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package internal package user
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package internal package utils
import ( import (
"fmt" "fmt"

View File

@ -3,7 +3,7 @@ package graph
import ( import (
"context" "context"
"git.dragse.it/anthrove/otter-space-sdk/internal" "git.dragse.it/anthrove/otter-space-sdk/internal/utils"
"github.com/neo4j/neo4j-go-driver/v5/neo4j" "github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config" "github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
) )
@ -37,6 +37,6 @@ func (g *graphConnection) Connect(ctx context.Context, endpoint string, username
func logger(graphDebug bool) func(config *config.Config) { func logger(graphDebug bool) func(config *config.Config) {
return func(config *config.Config) { return func(config *config.Config) {
config.Log = internal.NewGraphLogger(graphDebug) config.Log = utils.NewGraphLogger(graphDebug)
} }
} }

View File

@ -27,6 +27,5 @@ type Post interface {
CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error)
// LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph. // LinkPostWithSource establishes a link between a post and a source in the OtterSpace graph.
// It returns an error if the operation fails.
LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error
} }

View File

@ -3,36 +3,37 @@ package graph
import ( import (
"context" "context"
"git.dragse.it/anthrove/otter-space-sdk/internal" "git.dragse.it/anthrove/otter-space-sdk/internal/post"
"git.dragse.it/anthrove/otter-space-sdk/internal/relation"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
) )
// CreatePost will always create a new node, it does not check if the node with the corresponding post_id and rating exists. // CreatePost will always create a new node, it does not check if the node with the corresponding post_id and rating exists.
func (g *graphConnection) CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error { func (g *graphConnection) CreatePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
return internal.CreateAnthrovePostNode(ctx, g.driver, anthrovePost) return post.CreateAnthrovePostNode(ctx, g.driver, anthrovePost)
} }
// DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out. // DeletePost will always delete a node, it only needs the anthrovePost.PostID filled out.
func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error { func (g *graphConnection) DeletePost(ctx context.Context, anthrovePost *models.AnthrovePost) error {
return internal.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost) return post.DeleteAnthrovePostNode(ctx, g.driver, anthrovePost)
} }
// CheckPostNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID. // CheckPostNodeExistsBySourceID checks if a models.AnthrovePost exists by its sourcePostID.
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) { func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, sourcePostID string) (*models.AnthrovePost, bool, error) {
return internal.AnthroveNodeExistsBySourceID(ctx, g.driver, sourcePostID) return post.AnthroveNodeExistsBySourceID(ctx, g.driver, sourcePostID)
} }
// CheckPostNodeExistsByAnthroveID checks if a models.AnthrovePost exists by its models.AnthrovePostID. // CheckPostNodeExistsByAnthroveID checks if a models.AnthrovePost exists by its models.AnthrovePostID.
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) { func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (*models.AnthrovePost, bool, error) {
return internal.AnthroveNodeExistsByAnthroveID(ctx, g.driver, anthrovePost) return post.AnthroveNodeExistsByAnthroveID(ctx, g.driver, anthrovePost)
} }
// CheckPostNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl. // CheckPostNodeExistsBySourceURL checks if a models.AnthrovePost exists by its sourceUrl.
func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) { func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, sourceUrl string) (*models.AnthrovePost, bool, error) {
return internal.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl) return post.AnthroveNodeExistsBySourceURL(ctx, g.driver, sourceUrl)
} }
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error { func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
return internal.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship) return relation.EstablishAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
} }

View File

@ -2,12 +2,14 @@ package graph
import ( import (
"context" "context"
"git.dragse.it/anthrove/otter-space-sdk/internal"
"git.dragse.it/anthrove/otter-space-sdk/internal/source"
"git.dragse.it/anthrove/otter-space-sdk/internal/user"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
) )
func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { func (g *graphConnection) CreateSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
return internal.CreateSourceNode(ctx, g.driver, anthroveSource) return source.CreateSourceNode(ctx, g.driver, anthroveSource)
} }
func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error { func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error {
@ -16,17 +18,17 @@ func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *mode
} }
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) { func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
return internal.GetSourceNodesByURL(ctx, g.driver, sourceUrl) return source.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
} }
func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) { func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveSource, error) {
return internal.GetAllSourceNodes(ctx, g.driver) return source.GetAllSourceNodes(ctx, g.driver)
} }
func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) { func (g *graphConnection) GetSourceLinkForSpecifiedUser(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
return internal.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName) return user.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
} }
func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) { func (g *graphConnection) GetSourceLinkForUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.AnthroveUserRelationship, error) {
return internal.GetUserSourceLink(ctx, g.driver, anthroveUserID) return user.GetUserSourceLink(ctx, g.driver, anthroveUserID)
} }

View File

@ -2,7 +2,8 @@ package graph
import ( import (
"context" "context"
"git.dragse.it/anthrove/otter-space-sdk/internal"
"git.dragse.it/anthrove/otter-space-sdk/internal/tag"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
) )
@ -17,9 +18,9 @@ func (g *graphConnection) DeleteTag() error {
} }
func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error { func (g *graphConnection) AddTagWithRelationToPost(ctx context.Context, anthrovePostID models.AnthrovePostID, anthroveTag *models.AnthroveTag) error {
return internal.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag) return tag.CreateTagNodeWitRelation(ctx, g.driver, anthrovePostID, anthroveTag)
} }
func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) { func (g *graphConnection) GetAllTags(ctx context.Context) ([]models.TagsWithFrequency, error) {
return internal.GetTags(ctx, g.driver) return tag.GetTags(ctx, g.driver)
} }

View File

@ -3,7 +3,9 @@ package graph
import ( import (
"context" "context"
"fmt" "fmt"
"git.dragse.it/anthrove/otter-space-sdk/internal"
"git.dragse.it/anthrove/otter-space-sdk/internal/relation"
"git.dragse.it/anthrove/otter-space-sdk/internal/user"
"git.dragse.it/anthrove/otter-space-sdk/pkg/models" "git.dragse.it/anthrove/otter-space-sdk/pkg/models"
) )
@ -18,33 +20,33 @@ func (g *graphConnection) DeleteUser(ctx context.Context, anthroveUserID models.
} }
func (g *graphConnection) CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error { func (g *graphConnection) CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
return internal.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username) return user.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
} }
func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { func (g *graphConnection) GetUserTagsTroughFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) {
return internal.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID) return user.GetUserTagNodeWitRelationToFavedPosts(ctx, g.driver, anthroveUserID)
} }
func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { func (g *graphConnection) GetUserFavoritePostsWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) {
return internal.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit) return user.GetUserFavoriteNodeWithPagination(ctx, g.driver, anthroveUserID, skip, limit)
} }
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) { func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUserID models.AnthroveUserID) (*models.AnthroveUser, error) {
return internal.GetAnthroveUser(ctx, g.driver, anthroveUserID) return user.GetAnthroveUser(ctx, g.driver, anthroveUserID)
} }
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) { func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) {
return internal.GetUserFavoritesCount(ctx, g.driver, anthroveUserID) return user.GetUserFavoritesCount(ctx, g.driver, anthroveUserID)
} }
func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) { func (g *graphConnection) CheckUserPostLink(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID string, sourceUrl string) (bool, error) {
return internal.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl) return relation.CheckUserToPostLink(ctx, g.driver, anthroveUserID, sourcePostID, sourceUrl)
} }
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error { func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
return internal.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost) return relation.EstablishUserToPostLink(ctx, g.driver, anthroveUser, anthrovePost)
} }
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) { func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
return internal.GetAllAnthroveUserIDs(ctx, g.driver) return user.GetAllAnthroveUserIDs(ctx, g.driver)
} }