refactor(Post, PostMapper, PostRepository, CreatePostScreen, HomeScreen): update communityId to channelId for improved clarity
Some checks failed
Frontend CI / build-and-push-web (push) Successful in 2m48s
Frontend CI / ota-android (push) Successful in 11m3s
Frontend CI / build-android-apk (push) Has been cancelled

- Renamed communityId to channelId across Post entity, PostMapper, and PostRepository for consistency and clarity.
- Updated CreatePostScreen to include channel selection functionality, enhancing user experience when creating posts.
- Adjusted HomeScreen to support filtering posts by channel, improving content organization.
- Refactored related interfaces and services to align with the new channelId terminology, ensuring a cohesive codebase.
This commit is contained in:
lafay
2026-03-24 22:27:33 +08:00
parent b49cc0f3bd
commit 126e204592
15 changed files with 439 additions and 260 deletions

View File

@@ -24,7 +24,7 @@ export class PostMapper {
isFavorited: response.is_favorited || false,
isTop: response.is_pinned || false,
status: (response.status || 'published') as 'published' | 'draft' | 'deleted',
communityId: response.community_id,
channelId: response.channel_id,
tags: [],
createdAt: new Date(response.created_at || Date.now()),
// 空字符串/缺省时用 created_at避免误用 Date.now() 导致全部显示「刚修改」
@@ -58,8 +58,8 @@ export class PostMapper {
if (model.images !== undefined) {
request.images = model.images;
}
if (model.communityId !== undefined) {
request.community_id = model.communityId;
if (model.channelId !== undefined) {
request.channel_id = model.channelId;
}
if (model.tags !== undefined) {
request.tags = model.tags;
@@ -75,7 +75,7 @@ export class PostMapper {
title: string,
content: string,
images?: string[],
communityId?: string
channelId?: string
): Record<string, any> {
const request: Record<string, any> = {
title,
@@ -84,8 +84,8 @@ export class PostMapper {
if (images && images.length > 0) {
request.images = images;
}
if (communityId) {
request.community_id = communityId;
if (channelId) {
request.channel_id = channelId;
}
return request;
}

View File

@@ -85,7 +85,7 @@ export interface PostModel {
isFavorited: boolean;
isTop: boolean;
status: 'published' | 'draft' | 'deleted';
communityId?: string;
channelId?: string;
tags?: string[];
createdAt: Date;
updatedAt: Date;

View File

@@ -37,7 +37,7 @@ interface PostApiResponse {
is_favorited: boolean;
is_pinned: boolean;
status: string;
community_id?: string;
channel_id?: string;
tags?: string[];
created_at: string;
updated_at: string;
@@ -124,7 +124,7 @@ export class PostRepository implements IPostRepository {
isFavorited: model.isFavorited,
isPinned: model.isTop,
status: model.status,
communityId: model.communityId,
channelId: model.channelId,
tags: model.tags || [],
createdAt: model.createdAt.toISOString(),
updatedAt: model.updatedAt.toISOString(),
@@ -143,7 +143,7 @@ export class PostRepository implements IPostRepository {
created_at: model.createdAt.toISOString(),
updated_at: model.updatedAt.toISOString(),
content_edited_at: response.content_edited_at,
community_id: model.communityId,
channel_id: model.channelId,
};
}
@@ -250,7 +250,7 @@ export class PostRepository implements IPostRepository {
queryParams.cursor = params.cursor;
}
if (params?.post_type) queryParams.tab = params.post_type;
if (params?.communityId) queryParams.community_id = params.communityId;
if (params?.channelId) queryParams.channel_id = params.channelId;
if (params?.authorId) queryParams.author_id = params.authorId;
if (params?.tags && params.tags.length > 0) queryParams.tags = params.tags.join(',');
if (params?.status) queryParams.status = params.status;
@@ -364,7 +364,7 @@ export class PostRepository implements IPostRepository {
if (params.page) queryParams.page = params.page;
if (params.pageSize) queryParams.page_size = params.pageSize;
if (params.scope) queryParams.scope = params.scope;
if (params.communityId) queryParams.community_id = params.communityId;
if (params.channelId) queryParams.channel_id = params.channelId;
const response = await this.api.get<PostsListApiResponse>('/posts/search', queryParams);
@@ -398,7 +398,7 @@ export class PostRepository implements IPostRepository {
data.title,
data.content,
data.images?.map(img => img.url),
data.communityId
data.channelId
);
if (data.tags && data.tags.length > 0) {

View File

@@ -19,8 +19,8 @@ export interface GetPostsParams {
cursor?: string;
/** 帖子类型筛选可选follow, hot, latest */
post_type?: 'follow' | 'hot' | 'latest';
/** 社区ID过滤 */
communityId?: string;
/** 频道ID过滤 */
channelId?: string;
/** 作者ID过滤 */
authorId?: string;
/** 标签过滤 */
@@ -45,8 +45,8 @@ export interface CreatePostData {
content: string;
/** 图片列表 */
images?: PostImage[];
/** 所属社区ID */
communityId?: string;
/** 所属频道ID */
channelId?: string;
/** 标签列表 */
tags?: string[];
/** 帖子状态 */
@@ -97,8 +97,8 @@ export interface SearchPostsParams {
pageSize?: number;
/** 搜索范围:标题、内容、或全部 */
scope?: 'title' | 'content' | 'all';
/** 社区ID过滤 */
communityId?: string;
/** 频道ID过滤 */
channelId?: string;
}
// ==================== Repository 接口 ====================