initial commit

This commit is contained in:
SoXX 2024-02-16 15:16:50 +01:00
commit d13d244edf
11 changed files with 414 additions and 0 deletions

194
.gitignore vendored Normal file
View File

@ -0,0 +1,194 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,goland,go
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,goland,go
### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
### GoLand ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### GoLand Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,goland,go
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
.idea/*
/.run/*
.env

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.dragse.it/anthrove/anthrove-graph-sdk.git
go 1.22.0
require github.com/neo4j/neo4j-go-driver/v5 v5.17.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/neo4j/neo4j-go-driver/v5 v5.17.0 h1:Bdqg1Y8Hd3uLYToXtBjysDYXTdMiP7zeUNUEwfbJkSo=
github.com/neo4j/neo4j-go-driver/v5 v5.17.0/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k=

54
pkg/graph.go Normal file
View File

@ -0,0 +1,54 @@
package logic
import (
"context"
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
)
type Graph interface {
// Connect sets up a connection to the endpoint using the provided username and password
Connect(ctx context.Context, endpoint string, username string, password string) error
// AddUserToGraph uploads an Anthrove user to the graph
AddUserToGraph(ctx context.Context, anthroveUser *models.AnthroveUser) error
// AddSourceToGraph uploads an Anthrove source to the graph
AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error
// AddPostToGraph uploads an Anthrove post to the graph
AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error
// AddTagToGraph uploads a tag associated with an Anthrove post to the graph
AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error
// LinkPostWithSource establishes a link between a post and a source in the graph
LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error
// LinkUserWithPost establishes a link between a user and a post in the graph
LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error
// VerifyUserPostLink checks if a link between a user and a post exists in the graph
VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error)
// CheckPostNodeExistsByAnthroveID checks if an Anthrove post node exists in the graph by its Anthrove ID
CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error)
// CheckPostNodeExistsBySourceURL checks if an Anthrove post node exists in the graph by its source URL
CheckPostNodeExistsBySourceURL(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error)
// CheckPostNodeExistsBySourceID checks if an Anthrove post node exists in the graph by its source ID
CheckPostNodeExistsBySourceID(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error)
// GetUserFavoriteCount retrieves the count of user's favorite posts
GetUserFavoriteCount(ctx context.Context, anthroveUser *models.AnthroveUser) (int64, error)
// GetUserSourceLinks retrieves the links between a user and sources in the graph
GetUserSourceLinks(ctx context.Context, anthroveUser *models.AnthroveUser) (map[string]models.AnthroveUserRelationship, error)
// GetAnthroveUser retrieves an Anthrove user from the graph by their ID
GetAnthroveUser(ctx context.Context, anthroveUser *models.AnthroveUser) (*models.AnthroveUser, error)
// GetAllAnthroveUserIDs retrieves all Anthrove user IDs from the graph
GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error)
}

95
pkg/impl.go Normal file
View File

@ -0,0 +1,95 @@
package logic
import (
"context"
"git.dragse.it/anthrove/anthrove-graph-sdk.git/pkg/models"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)
type graphConnection struct {
driver neo4j.DriverWithContext
neo4jDebug bool
}
func NewGraphConnection(graphDebug bool) Graph {
return &graphConnection{
driver: nil,
neo4jDebug: graphDebug,
}
}
func (g *graphConnection) Connect(ctx context.Context, endpoint string, username string, password string) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) AddUserToGraph(ctx context.Context, anthroveUser *models.AnthroveUser) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) AddSourceToGraph(ctx context.Context, anthroveSource *models.AnthroveSource) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) AddPostToGraph(ctx context.Context, anthrovePost *models.AnthrovePost) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) AddTagToGraph(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveTag *models.AnthroveTag) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) LinkPostWithSource(ctx context.Context, anthrovePost *models.AnthrovePost, anthrovePostRelationship *models.AnthrovePostRelationship, anthroveSource *models.AnthroveSource) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) VerifyUserPostLink(ctx context.Context, anthrovePost *models.AnthrovePost, anthroveUser *models.AnthroveUser) (bool, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) CheckPostNodeExistsByAnthroveID(ctx context.Context, anthrovePost *models.AnthrovePost) (bool, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) CheckPostNodeExistsBySourceID(ctx context.Context, anthroveSource *models.AnthroveSource) (bool, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) GetUserFavoriteCount(ctx context.Context, anthroveUser *models.AnthroveUser) (int64, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) GetUserSourceLinks(ctx context.Context, anthroveUser *models.AnthroveUser) (map[string]models.AnthroveUserRelationship, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) GetAnthroveUser(ctx context.Context, anthroveUser *models.AnthroveUser) (*models.AnthroveUser, error) {
//TODO implement me
panic("implement me")
}
func (g *graphConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) {
//TODO implement me
panic("implement me")
}

27
pkg/models/const.go Normal file
View File

@ -0,0 +1,27 @@
package models
type AnthroveUserID string
type AnthrovePostID string
type AnthroveRating string
const (
SFW AnthroveRating = "s"
NSFW AnthroveRating = "e"
Questionable AnthroveRating = "q"
Unknown AnthroveRating = "unknown"
)
func (r *AnthroveRating) Convert(e621Rating string) {
switch e621Rating {
case "e":
*r = NSFW
case "q":
*r = Questionable
case "s":
*r = SFW
default:
*r = Unknown
}
}

6
pkg/models/post.go Normal file
View File

@ -0,0 +1,6 @@
package models
type AnthrovePost struct {
PostID AnthrovePostID `json:"post_id"`
Rating AnthroveRating `json:"rating"`
}

View File

@ -0,0 +1,12 @@
package models
type AnthroveUserRelationship struct {
UserID string `json:"user_id"`
Username string `json:"username"`
ScrapeTimeInterval string `json:"scrape_time_interval"`
Source AnthroveSource `json:"source"`
}
type AnthrovePostRelationship struct {
PostID string `json:"post_id"`
Url string `json:"url"`
}

7
pkg/models/source.go Normal file
View File

@ -0,0 +1,7 @@
package models
type AnthroveSource struct {
DisplayName string `json:"display_name"`
Domain string `json:"domain"`
Icon string `json:"icon"`
}

6
pkg/models/tag.go Normal file
View File

@ -0,0 +1,6 @@
package models
type AnthroveTag struct {
Name string `json:"name"`
Type string `json:"type"`
}

6
pkg/models/user.go Normal file
View File

@ -0,0 +1,6 @@
package models
type AnthroveUser struct {
UserID AnthroveUserID `json:"user_id"`
Relationship []AnthroveUserRelationship `json:"relationship"`
}