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,74 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/repository/generated"
|
||||
)
|
||||
|
||||
type CreateArticleInput struct {
|
||||
TenantID int64
|
||||
SourceType string
|
||||
TemplateID *int64
|
||||
}
|
||||
|
||||
type CreateArticleVersionInput struct {
|
||||
ArticleID int64
|
||||
VersionNo int
|
||||
Title string
|
||||
HTMLContent string
|
||||
MarkdownContent string
|
||||
WordCount int
|
||||
SourceLabel string
|
||||
}
|
||||
|
||||
type ArticleRepository interface {
|
||||
CreateArticle(ctx context.Context, input CreateArticleInput) (int64, error)
|
||||
CreateArticleVersion(ctx context.Context, input CreateArticleVersionInput) (int64, error)
|
||||
UpdateArticleCurrentVersion(ctx context.Context, articleID, tenantID, versionID int64) error
|
||||
UpdateArticleGenerateStatus(ctx context.Context, articleID, tenantID int64, status string) error
|
||||
}
|
||||
|
||||
type articleRepository struct {
|
||||
q generated.Querier
|
||||
}
|
||||
|
||||
func NewArticleRepository(db generated.DBTX) ArticleRepository {
|
||||
return &articleRepository{q: newQuerier(db)}
|
||||
}
|
||||
|
||||
func (r *articleRepository) CreateArticle(ctx context.Context, input CreateArticleInput) (int64, error) {
|
||||
return r.q.CreateArticle(ctx, generated.CreateArticleParams{
|
||||
TenantID: input.TenantID,
|
||||
SourceType: input.SourceType,
|
||||
TemplateID: pgInt8(input.TemplateID),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *articleRepository) CreateArticleVersion(ctx context.Context, input CreateArticleVersionInput) (int64, error) {
|
||||
return r.q.CreateArticleVersion(ctx, generated.CreateArticleVersionParams{
|
||||
ArticleID: input.ArticleID,
|
||||
VersionNo: int32(input.VersionNo),
|
||||
Title: pgText(&input.Title),
|
||||
HtmlContent: pgText(&input.HTMLContent),
|
||||
MarkdownContent: pgText(&input.MarkdownContent),
|
||||
WordCount: int32(input.WordCount),
|
||||
SourceLabel: pgText(&input.SourceLabel),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *articleRepository) UpdateArticleCurrentVersion(ctx context.Context, articleID, tenantID, versionID int64) error {
|
||||
return r.q.UpdateArticleCurrentVersion(ctx, generated.UpdateArticleCurrentVersionParams{
|
||||
VersionID: pgInt8(&versionID),
|
||||
ID: articleID,
|
||||
TenantID: tenantID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *articleRepository) UpdateArticleGenerateStatus(ctx context.Context, articleID, tenantID int64, status string) error {
|
||||
return r.q.UpdateArticleGenerateStatus(ctx, generated.UpdateArticleGenerateStatusParams{
|
||||
Status: status,
|
||||
ID: articleID,
|
||||
TenantID: tenantID,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user