mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
fix folder name for db adapter
This commit is contained in:
1
apps/db-adapter/internal/api/authorization_by_id.go
Normal file
1
apps/db-adapter/internal/api/authorization_by_id.go
Normal file
@@ -0,0 +1 @@
|
||||
package api
|
3
apps/db-adapter/internal/api/generate.go
Normal file
3
apps/db-adapter/internal/api/generate.go
Normal 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
|
6
apps/db-adapter/internal/api/oapi-codegen-cfg.yaml
Normal file
6
apps/db-adapter/internal/api/oapi-codegen-cfg.yaml
Normal 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
|
11
apps/db-adapter/internal/api/person.go
Normal file
11
apps/db-adapter/internal/api/person.go
Normal 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) {}
|
6
apps/db-adapter/internal/api/person_and_relationship.go
Normal file
6
apps/db-adapter/internal/api/person_and_relationship.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package api
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (srv *server) CreatePersonAndRelationship(c *gin.Context, id int, params CreatePersonAndRelationshipParams) {
|
||||
}
|
5
apps/db-adapter/internal/api/person_family_tree.go
Normal file
5
apps/db-adapter/internal/api/person_family_tree.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package api
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (srv *server) GetFamilyTreeById(c *gin.Context, id int) {}
|
9
apps/db-adapter/internal/api/person_google.go
Normal file
9
apps/db-adapter/internal/api/person_google.go
Normal 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) {}
|
5
apps/db-adapter/internal/api/person_recipes.go
Normal file
5
apps/db-adapter/internal/api/person_recipes.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package api
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (srv *server) GetRecipesByPersonId(c *gin.Context, id int, params GetRecipesByPersonIdParams) {}
|
9
apps/db-adapter/internal/api/recipe_relationship.go
Normal file
9
apps/db-adapter/internal/api/recipe_relationship.go
Normal 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) {
|
||||
}
|
9
apps/db-adapter/internal/api/recipes.go
Normal file
9
apps/db-adapter/internal/api/recipes.go
Normal 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) {}
|
7
apps/db-adapter/internal/api/relationship.go
Normal file
7
apps/db-adapter/internal/api/relationship.go
Normal 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) {}
|
34
apps/db-adapter/internal/api/server.go
Normal file
34
apps/db-adapter/internal/api/server.go
Normal 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)
|
||||
}
|
77
apps/db-adapter/internal/api/server_test.go
Normal file
77
apps/db-adapter/internal/api/server_test.go
Normal 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)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user