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,258 @@
|
||||
export interface ApiEnvelope<T> {
|
||||
code: number;
|
||||
message: string;
|
||||
data: T;
|
||||
request_id: string;
|
||||
}
|
||||
|
||||
export interface ApiErrorEnvelope {
|
||||
code: number;
|
||||
message: string;
|
||||
detail?: string;
|
||||
request_id?: string;
|
||||
}
|
||||
|
||||
export interface AuthTokens {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
}
|
||||
|
||||
export interface LoginRequest {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
id: number;
|
||||
email: string;
|
||||
name: string;
|
||||
avatar_url: string | null;
|
||||
tenant_id: number;
|
||||
tenant_role: string;
|
||||
permissions: string[];
|
||||
}
|
||||
|
||||
export interface LoginResponse {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
expires_at: number;
|
||||
user: UserInfo;
|
||||
}
|
||||
|
||||
export interface RefreshResponse {
|
||||
access_token: string;
|
||||
refresh_token: string;
|
||||
expires_at: number;
|
||||
}
|
||||
|
||||
export interface WorkspaceOverview {
|
||||
article_count: number;
|
||||
published_count: number;
|
||||
brand_count: number;
|
||||
supported_platform_count: number;
|
||||
}
|
||||
|
||||
export interface RecentArticle {
|
||||
id: number;
|
||||
title: string | null;
|
||||
template_name: string | null;
|
||||
generate_status: string;
|
||||
publish_status: string;
|
||||
source_type: string;
|
||||
word_count: number;
|
||||
source_label: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface QuotaSummary {
|
||||
plan_code: string;
|
||||
plan_name: string;
|
||||
total_quota: number;
|
||||
used_quota: number;
|
||||
balance: number;
|
||||
reset_at: string | null;
|
||||
}
|
||||
|
||||
export interface TemplateCard {
|
||||
id: number;
|
||||
scope: string;
|
||||
template_key: string;
|
||||
template_name: string;
|
||||
origin_type: string;
|
||||
card_config: Record<string, unknown> | null;
|
||||
prompt_visibility: string;
|
||||
}
|
||||
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };
|
||||
|
||||
export interface TemplateSchemaField {
|
||||
name: string;
|
||||
type: string;
|
||||
label: string;
|
||||
required?: boolean;
|
||||
default?: JsonValue;
|
||||
options?: Array<string | number | { label: string; value: string | number }>;
|
||||
placeholder?: string;
|
||||
help_text?: string;
|
||||
}
|
||||
|
||||
export interface TemplateSchema {
|
||||
fields?: TemplateSchemaField[];
|
||||
[key: string]: JsonValue | TemplateSchemaField[] | undefined;
|
||||
}
|
||||
|
||||
export interface TemplateListItem {
|
||||
id: number;
|
||||
scope: string;
|
||||
origin_type: string;
|
||||
template_key: string;
|
||||
template_name: string;
|
||||
schema_json: TemplateSchema;
|
||||
prompt_visibility: string;
|
||||
card_config: Record<string, JsonValue> | null;
|
||||
status: string;
|
||||
version_no: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface TemplateDetail extends TemplateListItem {
|
||||
prompt_template?: string | null;
|
||||
}
|
||||
|
||||
export interface TemplateGenerateRequest {
|
||||
input_params: Record<string, JsonValue>;
|
||||
}
|
||||
|
||||
export interface TemplateGenerateResponse {
|
||||
article_id: number;
|
||||
task_id: number;
|
||||
}
|
||||
|
||||
export interface ArticleListParams {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
generate_status?: string;
|
||||
publish_status?: string;
|
||||
source_type?: string;
|
||||
template_id?: number;
|
||||
keyword?: string;
|
||||
}
|
||||
|
||||
export interface ArticleListItem {
|
||||
id: number;
|
||||
source_type: string;
|
||||
template_name: string | null;
|
||||
generate_status: string;
|
||||
publish_status: string;
|
||||
title: string | null;
|
||||
word_count: number;
|
||||
source_label: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ArticleListResponse {
|
||||
items: ArticleListItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface ArticleDetail {
|
||||
id: number;
|
||||
source_type: string;
|
||||
template_id: number | null;
|
||||
template_name: string | null;
|
||||
generate_status: string;
|
||||
publish_status: string;
|
||||
title: string | null;
|
||||
html_content: string | null;
|
||||
markdown_content: string | null;
|
||||
word_count: number;
|
||||
source_label: string | null;
|
||||
version_no: number | null;
|
||||
generation_error_message: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ArticleVersion {
|
||||
id: number;
|
||||
version_no: number;
|
||||
title: string | null;
|
||||
word_count: number;
|
||||
source_label: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface BrandRequest {
|
||||
name: string;
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface Brand {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface KeywordRequest {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Keyword {
|
||||
id: number;
|
||||
brand_id: number;
|
||||
name: string;
|
||||
status: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface QuestionRequest {
|
||||
keyword_id: number;
|
||||
question_text: string;
|
||||
}
|
||||
|
||||
export interface UpdateQuestionRequest {
|
||||
question_text: string;
|
||||
}
|
||||
|
||||
export interface Question {
|
||||
id: number;
|
||||
brand_id: number;
|
||||
keyword_id: number;
|
||||
current_version_id: number | null;
|
||||
question_text: string | null;
|
||||
version_no: number | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface QuestionVersion {
|
||||
id: number;
|
||||
question_id: number;
|
||||
question_text: string;
|
||||
question_hash: string;
|
||||
version_no: number;
|
||||
is_active: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CompetitorRequest {
|
||||
name: string;
|
||||
website?: string | null;
|
||||
description?: string | null;
|
||||
product_lines_json?: JsonValue;
|
||||
}
|
||||
|
||||
export interface Competitor {
|
||||
id: number;
|
||||
brand_id: number;
|
||||
name: string;
|
||||
website: string | null;
|
||||
description: string | null;
|
||||
product_lines_json: JsonValue | null;
|
||||
created_at: string;
|
||||
}
|
||||
Reference in New Issue
Block a user