fix folder name for db adapter

This commit is contained in:
2025-03-27 22:09:34 +01:00
parent a56454110a
commit 46077870c3
50 changed files with 2 additions and 1 deletions

View File

@@ -0,0 +1 @@
package api

View File

@@ -0,0 +1,3 @@
package api
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config oapi-codegen-cfg.yaml ../../../../api/openapi.json

View File

@@ -0,0 +1,6 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/oapi-codegen/oapi-codegen/HEAD/configuration-schema.json
package: api
output: api.gen.go
generate:
models: true
gin-server: true

View File

@@ -0,0 +1,11 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) CreatePerson(c *gin.Context) {}
func (srv *server) SoftDeletePerson(c *gin.Context, id int, params SoftDeletePersonParams) {}
func (srv *server) UpdatePerson(c *gin.Context, id int, params UpdatePersonParams) {}
func (srv *server) HardDeletePerson(c *gin.Context, id int, params HardDeletePersonParams) {}

View File

@@ -0,0 +1,6 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) CreatePersonAndRelationship(c *gin.Context, id int, params CreatePersonAndRelationshipParams) {
}

View File

@@ -0,0 +1,5 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) GetFamilyTreeById(c *gin.Context, id int) {}

View File

@@ -0,0 +1,9 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) GetPersonByGoogleId(c *gin.Context, googleId string) {}
func (srv *server) CreatePersonByGoogleIdAndInviteCode(c *gin.Context, googleId string) {}
func (srv *server) CreatePersonByGoogleId(c *gin.Context, googleId string) {}

View File

@@ -0,0 +1,5 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) GetRecipesByPersonId(c *gin.Context, id int, params GetRecipesByPersonIdParams) {}

View File

@@ -0,0 +1,9 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) DeleteRecipeRelationship(c *gin.Context, recipeId int, params DeleteRecipeRelationshipParams) {
}
func (srv *server) CreateRecipeRelationship(c *gin.Context, recipeId int, params CreateRecipeRelationshipParams) {
}

View File

@@ -0,0 +1,9 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) SoftDeleteRecipe(c *gin.Context, id int, params SoftDeleteRecipeParams) {}
func (srv *server) UpdateRecipe(c *gin.Context, id int, params UpdateRecipeParams) {}
func (srv *server) HardDeleteRecipe(c *gin.Context, id int, params HardDeleteRecipeParams) {}

View File

@@ -0,0 +1,7 @@
package api
import "github.com/gin-gonic/gin"
func (srv *server) CreateRelationship(c *gin.Context, params CreateRelationshipParams) {}
func (srv *server) GetRelationship(c *gin.Context, id1 int, id2 int, params GetRelationshipParams) {}

View File

@@ -0,0 +1,34 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/vcscsvcscs/GenerationsHeritage/apps/db-adapter/pkg/gin/healthcheck"
"go.uber.org/zap"
)
type server struct {
db neo4j.DriverWithContext
health healthcheck.HealthCheck
logger *zap.Logger
}
func New(logger *zap.Logger, drv neo4j.DriverWithContext, healthcheck healthcheck.HealthCheck) ServerInterface {
if logger == nil {
panic("logger is required")
}
if drv == nil {
panic("neo4j driver is required")
}
if healthcheck == nil {
panic("healthcheck is required")
}
return &server{db: drv, health: healthcheck, logger: logger}
}
func (srv *server) HealthCheck(c *gin.Context) {
srv.health.HealthCheckHandler(c)
}

View File

@@ -0,0 +1,77 @@
package api
import (
"testing"
"github.com/gin-gonic/gin"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"
)
type mockHealthCheck struct {
mock.Mock
}
func (m *mockHealthCheck) HealthCheckHandler(c *gin.Context) {
m.Called(c)
}
func (m *mockHealthCheck) SetStatus(status string) {
m.Called(status)
}
func (m *mockHealthCheck) GetStatus() string {
args := m.Called()
return args.String(0)
}
func TestNewServer(t *testing.T) {
logger := zap.NewNop()
mockDriver, err := neo4j.NewDriverWithContext("bolt+ssc://memgraph:7687", nil)
assert.NoError(t, err)
mockHealth := &mockHealthCheck{}
t.Run("should create a new server instance", func(t *testing.T) {
t.Parallel()
srv := New(logger, mockDriver, mockHealth)
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)
})
})
t.Run("should panic if driver is nil", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(logger, nil, mockHealth)
})
})
t.Run("should panic if healthcheck is nil", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
New(logger, mockDriver, nil)
})
})
}
func TestHealthCheck(t *testing.T) {
mockHealth := &mockHealthCheck{}
srv := &server{health: mockHealth}
t.Run("should call HealthCheckHandler", func(t *testing.T) {
mockHealth.On("HealthCheckHandler", mock.Anything).Once()
c, _ := gin.CreateTestContext(nil)
srv.HealthCheck(c)
mockHealth.AssertCalled(t, "HealthCheckHandler", c)
})
}