feat: add tenant and user management with migrations, handlers, and tests
- Implemented tenant and user management features including: - Tenant creation and management with associated migrations. - User creation and management with associated migrations. - Tenant membership management with associated migrations. - Platform user roles management with associated migrations. - Quota management with associated migrations. - Article and template management with associated migrations. - Added HTTP handlers for templates and workspaces. - Created tests for protected and public routes. - Introduced a script to check tenant scope in SQL queries. - Documented task plan for backend completion and frontend foundation.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
|
||||
)
|
||||
|
||||
type AuditLogInput struct {
|
||||
OperatorID int64
|
||||
TenantID *int64
|
||||
Module string
|
||||
Action string
|
||||
BeforeJSON []byte
|
||||
AfterJSON []byte
|
||||
Result *string
|
||||
}
|
||||
|
||||
type GenerationTaskInput struct {
|
||||
TenantID int64
|
||||
ArticleID *int64
|
||||
QuotaReservationID *int64
|
||||
TaskType string
|
||||
InputParamsJSON []byte
|
||||
}
|
||||
|
||||
type GenerationTaskStatusInput struct {
|
||||
ID int64
|
||||
TenantID int64
|
||||
Status string
|
||||
ErrorMessage *string
|
||||
StartedAt *time.Time
|
||||
CompletedAt *time.Time
|
||||
}
|
||||
|
||||
type AuditRepository interface {
|
||||
CreateAuditLog(ctx context.Context, input AuditLogInput) error
|
||||
CreateGenerationTask(ctx context.Context, input GenerationTaskInput) (int64, error)
|
||||
UpdateGenerationTaskStatus(ctx context.Context, input GenerationTaskStatusInput) error
|
||||
}
|
||||
|
||||
type auditRepository struct {
|
||||
q generated.Querier
|
||||
}
|
||||
|
||||
func NewAuditRepository(db generated.DBTX) AuditRepository {
|
||||
return &auditRepository{q: newQuerier(db)}
|
||||
}
|
||||
|
||||
func (r *auditRepository) CreateAuditLog(ctx context.Context, input AuditLogInput) error {
|
||||
return r.q.CreateAuditLog(ctx, generated.CreateAuditLogParams{
|
||||
OperatorID: input.OperatorID,
|
||||
TenantID: pgInt8(input.TenantID),
|
||||
Module: input.Module,
|
||||
Action: input.Action,
|
||||
BeforeJson: input.BeforeJSON,
|
||||
AfterJson: input.AfterJSON,
|
||||
Result: pgText(input.Result),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *auditRepository) CreateGenerationTask(ctx context.Context, input GenerationTaskInput) (int64, error) {
|
||||
return r.q.CreateGenerationTask(ctx, generated.CreateGenerationTaskParams{
|
||||
TenantID: input.TenantID,
|
||||
ArticleID: pgInt8(input.ArticleID),
|
||||
QuotaReservationID: pgInt8(input.QuotaReservationID),
|
||||
TaskType: input.TaskType,
|
||||
InputParamsJson: input.InputParamsJSON,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *auditRepository) UpdateGenerationTaskStatus(ctx context.Context, input GenerationTaskStatusInput) error {
|
||||
return r.q.UpdateGenerationTaskStatus(ctx, generated.UpdateGenerationTaskStatusParams{
|
||||
Status: input.Status,
|
||||
ErrorMessage: pgText(input.ErrorMessage),
|
||||
StartedAt: pgTimestamp(input.StartedAt),
|
||||
CompletedAt: pgTimestamp(input.CompletedAt),
|
||||
ID: input.ID,
|
||||
TenantID: input.TenantID,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user