embed queries (in progress)

This commit is contained in:
2025-03-28 00:22:23 +01:00
parent c10a4a71f7
commit bb792b41e2
16 changed files with 126 additions and 49 deletions

View File

@@ -1,8 +1,18 @@
package api
import "github.com/gin-gonic/gin"
import (
"context"
func (srv *server) GetPersonByGoogleId(c *gin.Context, googleId string) {}
"github.com/gin-gonic/gin"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)
func (srv *server) GetPersonByGoogleId(c *gin.Context, googleId string) {
ctx, cancel := context.WithTimeout(context.Background(), srv.dbOpTimeout)
defer cancel()
session := srv.db.NewSession(ctx, neo4j.SessionConfig{})
session.ExecuteRead()
}
func (srv *server) CreatePersonByGoogleIdAndInviteCode(c *gin.Context, googleId string) {}

View File

@@ -1,6 +1,8 @@
package api
import (
"time"
"github.com/gin-gonic/gin"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter/pkg/gin/healthcheck"
@@ -8,12 +10,13 @@ import (
)
type server struct {
db neo4j.DriverWithContext
health healthcheck.HealthCheck
logger *zap.Logger
db neo4j.DriverWithContext
dbOpTimeout time.Duration
health healthcheck.HealthCheck
logger *zap.Logger
}
func New(logger *zap.Logger, drv neo4j.DriverWithContext, healthcheck healthcheck.HealthCheck) ServerInterface {
func New(logger *zap.Logger, drv neo4j.DriverWithContext, healthcheck healthcheck.HealthCheck, databaseOperationTimeoutInMs time.Duration) ServerInterface {
if logger == nil {
panic("logger is required")
}
@@ -26,6 +29,10 @@ func New(logger *zap.Logger, drv neo4j.DriverWithContext, healthcheck healthchec
panic("healthcheck is required")
}
if databaseOperationTimeoutInMs == 0 {
panic("database operation timeout is required")
}
return &server{db: drv, health: healthcheck, logger: logger}
}

View File

@@ -36,28 +36,35 @@ func TestNewServer(t *testing.T) {
t.Run("should create a new server instance", func(t *testing.T) {
t.Parallel()
srv := New(logger, mockDriver, mockHealth)
srv := New(logger, mockDriver, mockHealth, 1)
assert.NotNil(t, srv)
})
t.Run("should panic if logger is nil", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(nil, mockDriver, mockHealth)
New(nil, mockDriver, mockHealth, 1)
})
})
t.Run("should panic if driver is nil", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(logger, nil, mockHealth)
New(logger, nil, mockHealth, 1)
})
})
t.Run("should panic if healthcheck is nil", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(logger, mockDriver, nil)
New(logger, mockDriver, nil, 1)
})
})
t.Run("should panic if databaseOperationTimeout is 0", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(logger, mockDriver, mockHealth, 0)
})
})
}