This commit introduces the `MergeWork` command, a new feature to merge two `Work` entities, their associations, and their statistics. The entire operation is performed atomically within a database transaction to ensure data integrity.
Key changes include:
- A new `MergeWork` method in `internal/app/work/commands.go`.
- An `Add` method on the `WorkStats` entity for combining statistics.
- A new `GetWithAssociationsInTx` method on the `WorkRepository` to fetch entities within a transaction.
- A comprehensive integration test using an in-memory SQLite database to validate the merge logic.
This commit also consolidates all scattered TODOs and build issues from `TODO.md` and `BUILD_ISSUES.md` into a single, actionable `TASKS.md` file. The legacy documentation files have been removed to create a single source of truth for pending work.
The integration tests for admin-only mutations were failing due to an authorization issue. The root cause was that the JWT token used in the tests did not reflect the user's admin role, which was being set directly in the database.
This commit fixes the issue by:
1. Updating the `CreateAuthenticatedUser` test helper to generate a new JWT token after a user's role is changed. This ensures the token contains the correct, up-to-date role.
2. Removing all uses of `auth.ContextWithAdminUser` from the integration tests, making the JWT token the single source of truth for authorization.
This change also removes unused imports and variables that were causing build failures after the refactoring. All integration tests now pass.
This commit introduces a comprehensive set of foundational improvements to make the API more robust, secure, and observable.
The following features have been implemented:
- **Observability Stack:** A new `internal/observability` package has been added, providing structured logging with `zerolog`, Prometheus metrics, and OpenTelemetry tracing. This stack is fully integrated into the application's request pipeline.
- **Centralized Authorization:** A new `internal/app/authz` service has been created to centralize authorization logic. This service is now used by the `user`, `work`, and `comment` services to protect all Create, Update, and Delete operations.
- **Standardized Input Validation:** The previous ad-hoc validation has been replaced with a more robust, struct-tag-based system using the `go-playground/validator` library. This has been applied to all GraphQL input models.
- **Structured Error Handling:** A new set of custom error types has been introduced in the `internal/domain` package. A custom `gqlgen` error presenter has been implemented to map these domain errors to structured GraphQL error responses with specific error codes.
- **`updateUser` Endpoint:** The `updateUser` mutation has been fully implemented as a proof of concept for the new patterns, including support for partial updates and comprehensive authorization checks.
- **Test Refactoring:** The test suite has been significantly improved by decoupling mock repositories from the shared `testutil` package, resolving circular dependency issues and making the tests more maintainable.
This commit isolates the `Work` aggregate into its own package at `internal/domain/work`, following the first step of the refactoring plan in `refactor.md`.
- The `Work` struct, related types, and the `WorkRepository` interface have been moved to the new package.
- A circular dependency between `domain` and `work` was resolved by moving the `AnalyticsRepository` to the `app` layer.
- All references to the moved types have been updated across the entire codebase to fix compilation errors.
- Test files, including mocks and integration tests, have been updated to reflect the new structure.
This commit addresses a broken build state caused by a mid-stream architectural refactoring. The changes align the existing code with the new Domain-Driven Design (DDD-lite) structure outlined in `refactor.md`.
Key changes include:
- Defined missing domain interfaces for `Auth`, `Localization`, and `Search`.
- Refactored application services to use a `Commands` and `Queries` pattern.
- Updated GraphQL resolvers to call application services instead of accessing repositories directly.
- Fixed dependency injection in `cmd/api/main.go` by removing the non-existent `ApplicationBuilder` and manually instantiating services.
- Corrected numerous test files (`integration`, `unit`, and `repository` tests) to reflect the new architecture, including fixing mock objects and test suite setups.
- Added missing database migrations for test schemas to resolve "no such table" errors.
This effort successfully gets the application to a compilable state and passes a significant portion of the test suite, laying the groundwork for further development and fixing the remaining test failures.
This change introduces a service layer to encapsulate the business logic
for each domain aggregate. This will make the code more modular,
testable, and easier to maintain.
The following services have been created:
- author
- bookmark
- category
- collection
- comment
- like
- tag
- translation
- user
The main Application struct has been updated to use these new services.
The integration test suite has also been updated to use the new
Application struct and services.
This is a work in progress. The next step is to fix the compilation
errors and then refactor the resolvers to use the new services.
This change introduces a major architectural refactoring of the application, with a focus on improving testability, decoupling, and observability.
The following domains have been successfully refactored:
- `localization`: Wrote a full suite of unit tests and added logging.
- `auth`: Introduced a `JWTManager` interface, wrote comprehensive unit tests, and added logging.
- `copyright`: Separated integration tests, wrote a full suite of unit tests, and added logging.
- `monetization`: Wrote a full suite of unit tests and added logging.
- `search`: Refactored the Weaviate client usage by creating a wrapper to improve testability, and achieved 100% test coverage.
For each of these domains, 100% test coverage has been achieved for the refactored code.
The refactoring of the `work` domain is currently in progress. Unit tests have been written for the commands and queries, but there is a persistent build issue with the query tests that needs to be resolved. The error indicates that the query methods are undefined, despite appearing to be correctly defined and called.