refactor(model): changed types of model
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
e3a5adb2cc
commit
76f3c8d97e
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// CreateAnthrovePostToSourceLink establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
||||
func CreateAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain string, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||
func CreateAnthrovePostToSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthrovePostID models.AnthrovePostID, anthroveSourceDomain models.AnthroveSourceDomain, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||
query := `
|
||||
MATCH (sourceNode:Source {domain: $source_url})
|
||||
MATCH (postNode:AnthrovePost {post_id: $anthrove_post_id})
|
||||
|
@ -86,9 +86,9 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
|
||||
}
|
||||
|
||||
sources = append(sources, models.AnthroveSource{
|
||||
DisplayName: source.Props["display_name"].(string),
|
||||
Domain: source.Props["domain"].(string),
|
||||
Icon: source.Props["icon"].(string),
|
||||
DisplayName: models.AnthroveSourceDisplayName(source.Props["display_name"].(string)),
|
||||
Domain: models.AnthroveSourceDomain(source.Props["domain"].(string)),
|
||||
Icon: models.AnthroveSourceIcon(source.Props["icon"].(string)),
|
||||
})
|
||||
|
||||
}
|
||||
@ -101,7 +101,7 @@ func GetAllSourceNodes(ctx context.Context, driver neo4j.DriverWithContext) ([]m
|
||||
}
|
||||
|
||||
// GetSourceNodesByURL returns the first models.AnthroveSource provided by the database
|
||||
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl string) (*models.AnthroveSource, error) {
|
||||
func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, sourceUrl models.AnthroveSourceDomain) (*models.AnthroveSource, error) {
|
||||
var source models.AnthroveSource
|
||||
|
||||
query := `
|
||||
@ -126,9 +126,9 @@ func GetSourceNodesByURL(ctx context.Context, driver neo4j.DriverWithContext, so
|
||||
return nil, err
|
||||
}
|
||||
|
||||
source.DisplayName = record.Props["display_name"].(string)
|
||||
source.Domain = record.Props["domain"].(string)
|
||||
source.Icon = record.Props["icon"].(string)
|
||||
source.DisplayName = models.AnthroveSourceDisplayName(record.Props["display_name"].(string))
|
||||
source.Domain = models.AnthroveSourceDomain(record.Props["domain"].(string))
|
||||
source.Icon = models.AnthroveSourceIcon(record.Props["icon"].(string))
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"source_url": sourceUrl,
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error {
|
||||
func CreateUserNodeWithSourceRelation(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDomain models.AnthroveSourceDomain, userID string, username string) error {
|
||||
query := `
|
||||
MATCH (sourceNode:Source {domain: $source_domain})
|
||||
MERGE (:User {user_id: $anthrove_user_id})-[r:HAS_ACCOUNT_AT {username: $source_user_name, user_id: $source_user_id}]->(sourceNode)
|
||||
@ -133,9 +133,9 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
||||
UserID: sourceUserID,
|
||||
Username: sourceUsername,
|
||||
Source: models.AnthroveSource{
|
||||
DisplayName: displayName,
|
||||
Domain: domain,
|
||||
Icon: icon,
|
||||
DisplayName: models.AnthroveSourceDisplayName(displayName),
|
||||
Domain: models.AnthroveSourceDomain(domain),
|
||||
Icon: models.AnthroveSourceIcon(icon),
|
||||
},
|
||||
}
|
||||
userSource[displayName] = anthroveSourceUser
|
||||
@ -149,7 +149,7 @@ func GetUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anth
|
||||
return userSource, nil
|
||||
}
|
||||
|
||||
func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDisplayName string) (map[string]models.AnthroveUserRelationship, error) {
|
||||
func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithContext, anthroveUserID models.AnthroveUserID, sourceDisplayName models.AnthroveSourceDisplayName) (map[string]models.AnthroveUserRelationship, error) {
|
||||
|
||||
userSource := make(map[string]models.AnthroveUserRelationship)
|
||||
|
||||
@ -194,9 +194,9 @@ func GetSpecifiedUserSourceLink(ctx context.Context, driver neo4j.DriverWithCont
|
||||
UserID: sourceUserID,
|
||||
Username: sourceUsername,
|
||||
Source: models.AnthroveSource{
|
||||
DisplayName: displayName,
|
||||
Domain: domain,
|
||||
Icon: icon,
|
||||
DisplayName: models.AnthroveSourceDisplayName(displayName),
|
||||
Domain: models.AnthroveSourceDomain(domain),
|
||||
Icon: models.AnthroveSourceIcon(icon),
|
||||
},
|
||||
}
|
||||
userSource[displayName] = anthroveSourceUser
|
||||
@ -256,9 +256,9 @@ func GetAnthroveUser(ctx context.Context, driver neo4j.DriverWithContext, anthro
|
||||
})
|
||||
|
||||
userSources = models.AnthroveSource{
|
||||
DisplayName: utils.GetOrDefault(source.Props, "display_name", "").(string),
|
||||
Domain: utils.GetOrDefault(source.Props, "domain", "").(string),
|
||||
Icon: utils.GetOrDefault(source.Props, "icon", "").(string),
|
||||
DisplayName: models.AnthroveSourceDisplayName(utils.GetOrDefault(source.Props, "display_name", "").(string)),
|
||||
Domain: models.AnthroveSourceDomain(utils.GetOrDefault(source.Props, "domain", "").(string)),
|
||||
Icon: models.AnthroveSourceIcon(utils.GetOrDefault(source.Props, "icon", "").(string)),
|
||||
}
|
||||
|
||||
anthroveUser.UserID = models.AnthroveUserID(utils.GetOrDefault(user.Props, "user_id", "").(string))
|
||||
|
@ -35,6 +35,6 @@ func (g *graphConnection) CheckPostNodeExistsBySourceURL(ctx context.Context, so
|
||||
}
|
||||
|
||||
// LinkPostWithSource establishes a link between a models.AnthrovePost and a models.AnthroveSource
|
||||
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 models.AnthroveSourceDomain, anthrovePostRelationship *models.AnthrovePostRelationship) error {
|
||||
return relations.CreateAnthrovePostToSourceLink(ctx, g.driver, anthrovePostID, anthroveSourceDomain, anthrovePostRelationship)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ type Source interface {
|
||||
DeleteSource(ctx context.Context, anthroveSource *models.AnthroveSource) error
|
||||
|
||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
||||
GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error)
|
||||
GetSourceByURL(ctx context.Context, sourceUrl models.AnthroveSourceDomain) (*models.AnthroveSource, error)
|
||||
|
||||
// GetSourceLinkForUser retrieves the links between a user and sources in the OtterSpace graph.
|
||||
// It returns a map of source domains to user-source relationships, and an error if the operation fails.
|
||||
|
@ -19,7 +19,7 @@ func (g *graphConnection) DeleteSource(ctx context.Context, anthroveSource *mode
|
||||
}
|
||||
|
||||
// GetSourceByURL returns the first models.AnthroveSource provided by the database
|
||||
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl string) (*models.AnthroveSource, error) {
|
||||
func (g *graphConnection) GetSourceByURL(ctx context.Context, sourceUrl models.AnthroveSourceDomain) (*models.AnthroveSource, error) {
|
||||
return source.GetSourceNodesByURL(ctx, g.driver, sourceUrl)
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ func (g *graphConnection) GetAllSources(ctx context.Context) ([]models.AnthroveS
|
||||
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 models.AnthroveSourceDisplayName) (map[string]models.AnthroveUserRelationship, error) {
|
||||
return user.GetSpecifiedUserSourceLink(ctx, g.driver, anthroveUserID, sourceDisplayName)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ type User interface {
|
||||
DeleteUser(ctx context.Context, anthroveUserID models.AnthroveUserID) error
|
||||
|
||||
// CreateUserWithRelationToSource will create or get a user to link it with a given source.
|
||||
CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain string, userID string, username string) error
|
||||
CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceDomain models.AnthroveSourceDomain, userID string, username string) error
|
||||
|
||||
// LinkUserWithPost creates a link between a user and a post in the OtterSpace graph.
|
||||
LinkUserWithPost(ctx context.Context, anthroveUser *models.AnthroveUser, anthrovePost *models.AnthrovePost) error
|
||||
|
@ -19,7 +19,7 @@ func (g *graphConnection) DeleteUser(ctx context.Context, anthroveUserID models.
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
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 models.AnthroveSourceDomain, userID string, username string) error {
|
||||
return user.CreateUserNodeWithSourceRelation(ctx, g.driver, anthroveUserID, sourceDomain, userID, username)
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,9 @@ package models
|
||||
type AnthroveUserID string
|
||||
type AnthrovePostID string
|
||||
type AnthroveRating string
|
||||
type AnthroveSourceDomain string
|
||||
type AnthroveSourceIcon string
|
||||
type AnthroveSourceDisplayName string
|
||||
|
||||
const (
|
||||
SFW AnthroveRating = "s"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type AnthroveSource struct {
|
||||
DisplayName string `json:"display_name" format:"string"`
|
||||
Domain string `json:"domain" format:"string"`
|
||||
Icon string `json:"icon" format:"string"`
|
||||
DisplayName AnthroveSourceDisplayName `json:"display_name" format:"string"`
|
||||
Domain AnthroveSourceDomain `json:"domain" format:"string"`
|
||||
Icon AnthroveSourceIcon `json:"icon" format:"string"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user