mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
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.
26 lines
634 B
Go
26 lines
634 B
Go
package book
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// BookQueries contains the query handlers for the book aggregate.
|
|
type BookQueries struct {
|
|
repo domain.BookRepository
|
|
}
|
|
|
|
// NewBookQueries creates a new BookQueries handler.
|
|
func NewBookQueries(repo domain.BookRepository) *BookQueries {
|
|
return &BookQueries{repo: repo}
|
|
}
|
|
|
|
// Book retrieves a book by its ID.
|
|
func (q *BookQueries) Book(ctx context.Context, id uint) (*domain.Book, error) {
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// Books retrieves a list of all books.
|
|
func (q *BookQueries) Books(ctx context.Context) ([]domain.Book, error) {
|
|
return q.repo.ListAll(ctx)
|
|
} |