mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
This commit addresses the "Stabilize non-linguistics tests and interfaces" task from TODO.md.
The main changes are: - Refactored the `Copyright` and `Monetization` relationships to use explicit join tables for each owning model, as per the "Option A" strategy. This fixes the GORM migration issues related to polymorphic many-to-many relationships. - Created new join table structs (e.g., `WorkCopyright`, `AuthorCopyright`, `WorkMonetization`, etc.). - Updated the domain models to use standard `gorm:"many2many"` tags with the new join tables. - Refactored the `CopyrightRepository` and `MonetizationRepository` to use the new association-based logic. - Updated the application services (`CopyrightCommands`, `CopyrightQueries`, `MonetizationCommands`, `MonetizationQueries`) to use the new repository methods. - Consolidated all repository interfaces into a single `internal/domain/interfaces.go` file for better code organization. - Added extensive integration tests for the new repository and application layer logic for `Copyrights` and `Monetizations`. - Fixed the deletion logic for `WorkRepository` to correctly handle cascading deletes with SQLite. - Updated the `TODO.md` file to mark the "Stabilize non-linguistics tests and interfaces" task as complete.
This commit is contained in:
parent
5d6a6ef47b
commit
d536c3acb5
@ -31,15 +31,14 @@ type GraphQLResponse struct {
|
|||||||
|
|
||||||
// GraphQLIntegrationSuite is a test suite for GraphQL integration tests
|
// GraphQLIntegrationSuite is a test suite for GraphQL integration tests
|
||||||
type GraphQLIntegrationSuite struct {
|
type GraphQLIntegrationSuite struct {
|
||||||
testutil.SimpleTestSuite
|
testutil.IntegrationTestSuite
|
||||||
server *httptest.Server
|
server *httptest.Server
|
||||||
client *http.Client
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupSuite sets up the test suite
|
// SetupSuite sets up the test suite
|
||||||
func (s *GraphQLIntegrationSuite) SetupSuite() {
|
func (s *GraphQLIntegrationSuite) SetupSuite() {
|
||||||
// Use the simple test utilities
|
s.IntegrationTestSuite.SetupSuite(testutil.DefaultTestConfig())
|
||||||
s.SimpleTestSuite.SetupSuite()
|
|
||||||
|
|
||||||
// Create GraphQL server with the test resolver
|
// Create GraphQL server with the test resolver
|
||||||
resolver := s.GetResolver()
|
resolver := s.GetResolver()
|
||||||
@ -54,12 +53,13 @@ func (s *GraphQLIntegrationSuite) SetupSuite() {
|
|||||||
|
|
||||||
// TearDownSuite tears down the test suite
|
// TearDownSuite tears down the test suite
|
||||||
func (s *GraphQLIntegrationSuite) TearDownSuite() {
|
func (s *GraphQLIntegrationSuite) TearDownSuite() {
|
||||||
|
s.IntegrationTestSuite.TearDownSuite()
|
||||||
s.server.Close()
|
s.server.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupTest sets up each test
|
// SetupTest sets up each test
|
||||||
func (s *GraphQLIntegrationSuite) SetupTest() {
|
func (s *GraphQLIntegrationSuite) SetupTest() {
|
||||||
s.SimpleTestSuite.SetupTest()
|
s.IntegrationTestSuite.SetupTest()
|
||||||
}
|
}
|
||||||
|
|
||||||
// executeGraphQL executes a GraphQL query
|
// executeGraphQL executes a GraphQL query
|
||||||
|
|||||||
@ -31,4 +31,5 @@ type Application struct {
|
|||||||
PublisherRepo domain.PublisherRepository
|
PublisherRepo domain.PublisherRepository
|
||||||
SourceRepo domain.SourceRepository
|
SourceRepo domain.SourceRepository
|
||||||
MonetizationQueries *monetization.MonetizationQueries
|
MonetizationQueries *monetization.MonetizationQueries
|
||||||
|
MonetizationCommands *monetization.MonetizationCommands
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,6 +106,7 @@ func (r *workRepository) FindByLanguage(ctx context.Context, language string, pa
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Delete removes a work and its associations
|
// Delete removes a work and its associations
|
||||||
func (r *workRepository) Delete(ctx context.Context, id uint) error {
|
func (r *workRepository) Delete(ctx context.Context, id uint) error {
|
||||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
|||||||
@ -15,7 +15,11 @@ import (
|
|||||||
graph "tercul/internal/adapters/graphql"
|
graph "tercul/internal/adapters/graphql"
|
||||||
"tercul/internal/app/auth"
|
"tercul/internal/app/auth"
|
||||||
auth_platform "tercul/internal/platform/auth"
|
auth_platform "tercul/internal/platform/auth"
|
||||||
|
"tercul/internal/app"
|
||||||
|
"tercul/internal/app/copyright"
|
||||||
"tercul/internal/app/localization"
|
"tercul/internal/app/localization"
|
||||||
|
"tercul/internal/app/monetization"
|
||||||
|
"tercul/internal/app/search"
|
||||||
"tercul/internal/app/work"
|
"tercul/internal/app/work"
|
||||||
"tercul/internal/data/sql"
|
"tercul/internal/data/sql"
|
||||||
"tercul/internal/domain"
|
"tercul/internal/domain"
|
||||||
@ -318,8 +322,48 @@ func (s *IntegrationTestSuite) SetupTest() {
|
|||||||
|
|
||||||
// GetResolver returns a properly configured GraphQL resolver for testing
|
// GetResolver returns a properly configured GraphQL resolver for testing
|
||||||
func (s *IntegrationTestSuite) GetResolver() *graph.Resolver {
|
func (s *IntegrationTestSuite) GetResolver() *graph.Resolver {
|
||||||
|
// Initialize repositories
|
||||||
|
workRepo := sql.NewWorkRepository(s.DB)
|
||||||
|
userRepo := sql.NewUserRepository(s.DB)
|
||||||
|
authorRepo := sql.NewAuthorRepository(s.DB)
|
||||||
|
translationRepo := sql.NewTranslationRepository(s.DB)
|
||||||
|
copyrightRepo := sql.NewCopyrightRepository(s.DB)
|
||||||
|
bookRepo := sql.NewBookRepository(s.DB)
|
||||||
|
publisherRepo := sql.NewPublisherRepository(s.DB)
|
||||||
|
sourceRepo := sql.NewSourceRepository(s.DB)
|
||||||
|
monetizationRepo := sql.NewMonetizationRepository(s.DB)
|
||||||
|
|
||||||
|
// Initialize application services
|
||||||
|
workCommands := work.NewWorkCommands(workRepo, &MockAnalyzer{})
|
||||||
|
workQueries := work.NewWorkQueries(workRepo)
|
||||||
|
|
||||||
|
jwtManager := auth_platform.NewJWTManager()
|
||||||
|
authCommands := auth.NewAuthCommands(userRepo, jwtManager)
|
||||||
|
authQueries := auth.NewAuthQueries(userRepo, jwtManager)
|
||||||
|
|
||||||
|
copyrightCommands := copyright.NewCopyrightCommands(copyrightRepo)
|
||||||
|
copyrightQueries := copyright.NewCopyrightQueries(copyrightRepo, workRepo, authorRepo, bookRepo, publisherRepo, sourceRepo)
|
||||||
|
|
||||||
|
localizationService := localization.NewService(translationRepo)
|
||||||
|
|
||||||
|
searchService := search.NewIndexService(localizationService, translationRepo)
|
||||||
|
|
||||||
|
monetizationCommands := monetization.NewMonetizationCommands(monetizationRepo)
|
||||||
|
monetizationQueries := monetization.NewMonetizationQueries(monetizationRepo, workRepo, authorRepo, bookRepo, publisherRepo, sourceRepo)
|
||||||
|
|
||||||
return &graph.Resolver{
|
return &graph.Resolver{
|
||||||
// This needs to be updated to reflect the new resolver structure
|
App: &app.Application{
|
||||||
|
WorkCommands: workCommands,
|
||||||
|
WorkQueries: workQueries,
|
||||||
|
AuthCommands: authCommands,
|
||||||
|
AuthQueries: authQueries,
|
||||||
|
CopyrightCommands: copyrightCommands,
|
||||||
|
CopyrightQueries: copyrightQueries,
|
||||||
|
Localization: localizationService,
|
||||||
|
Search: searchService,
|
||||||
|
MonetizationCommands: monetizationCommands,
|
||||||
|
MonetizationQueries: monetizationQueries,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user