2024-09-02 13:43:03 +00:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"app-cloudep-tweeting-service/internal/config"
|
|
|
|
"app-cloudep-tweeting-service/internal/domain/repository"
|
|
|
|
client4J "app-cloudep-tweeting-service/internal/lib/neo4j"
|
|
|
|
"context"
|
2024-09-03 01:17:50 +00:00
|
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
2024-09-02 13:43:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SocialNetworkParam struct {
|
|
|
|
Config config.Config
|
|
|
|
Neo4jClient *client4J.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
type SocialNetworkRepository struct {
|
|
|
|
cfg config.Config
|
|
|
|
neo4jClient *client4J.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustSocialNetworkRepository(param SocialNetworkParam) repository.SocialNetworkRepository {
|
|
|
|
return &SocialNetworkRepository{
|
|
|
|
cfg: param.Config,
|
|
|
|
neo4jClient: param.Neo4jClient,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SocialNetworkRepository) CreateUserNode(ctx context.Context, uid string) error {
|
2024-09-03 01:17:50 +00:00
|
|
|
session, err := s.neo4jClient.Conn()
|
2024-09-02 13:43:03 +00:00
|
|
|
if err != nil {
|
2024-09-03 01:17:50 +00:00
|
|
|
return err
|
2024-09-02 13:43:03 +00:00
|
|
|
}
|
2024-09-03 01:17:50 +00:00
|
|
|
defer session.Close(ctx)
|
2024-09-02 13:43:03 +00:00
|
|
|
|
2024-09-03 01:17:50 +00:00
|
|
|
params := map[string]interface{}{
|
2024-09-02 13:43:03 +00:00
|
|
|
"uid": uid,
|
|
|
|
}
|
|
|
|
|
2024-09-03 01:17:50 +00:00
|
|
|
_, err = session.NewSession(ctx, neo4j.SessionConfig{
|
|
|
|
AccessMode: neo4j.AccessModeWrite,
|
|
|
|
}).Run(ctx, "CREATE (n:User {uid: $uid}) RETURN n", params)
|
2024-09-02 13:43:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-09-03 01:17:50 +00:00
|
|
|
// // 處理結果
|
|
|
|
// if run.Next(ctx) {
|
|
|
|
// node := run.Record().AsMap()
|
|
|
|
// fmt.Printf("Created Node: %v\n", node)
|
|
|
|
// }
|
2024-09-02 13:43:03 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|