refactor(PostRepository): update PostsListApiResponse structure and handle response mapping
Some checks failed
Frontend CI / build-and-push-web (push) Failing after 5m21s
Frontend CI / ota-android (push) Successful in 10m57s
Frontend CI / build-android-apk (push) Has been cancelled

- Change 'posts' to 'list' in PostsListApiResponse for consistency with API response.
- Introduce optional fields: 'page', 'page_size', and 'total_pages' for enhanced pagination support.
- Update response handling in PostRepository methods to accommodate new structure and ensure default values for 'hasMore'.
This commit is contained in:
lafay
2026-03-23 00:16:10 +08:00
parent 69e21471fe
commit cee120a6f8

View File

@@ -53,10 +53,13 @@ interface PostApiResponse {
* API帖子列表响应类型
*/
interface PostsListApiResponse {
posts: PostApiResponse[];
has_more: boolean;
list: PostApiResponse[];
has_more?: boolean;
next_cursor?: string;
total?: number;
page?: number;
page_size?: number;
total_pages?: number;
}
/**
@@ -242,7 +245,7 @@ export class PostRepository implements IPostRepository {
const response = await this.api.get<PostsListApiResponse>('/posts', queryParams);
const posts = response.posts.map(p => this.mapToPost(p));
const posts = (response.list || []).map(p => this.mapToPost(p));
// 缓存帖子
posts.forEach(post => {
@@ -252,7 +255,7 @@ export class PostRepository implements IPostRepository {
return {
posts,
hasMore: response.has_more,
hasMore: response.has_more ?? false,
nextCursor: response.next_cursor,
total: response.total,
};
@@ -315,7 +318,7 @@ export class PostRepository implements IPostRepository {
const response = await this.api.get<PostsListApiResponse>(`/users/${userId}/posts`, queryParams);
const posts = response.posts.map(p => this.mapToPost(p));
const posts = (response.list || []).map(p => this.mapToPost(p));
// 缓存帖子
posts.forEach(post => {
@@ -325,7 +328,7 @@ export class PostRepository implements IPostRepository {
return {
posts,
hasMore: response.has_more,
hasMore: response.has_more ?? false,
nextCursor: response.next_cursor,
total: response.total,
};
@@ -350,7 +353,7 @@ export class PostRepository implements IPostRepository {
const response = await this.api.get<PostsListApiResponse>('/posts/search', queryParams);
const posts = response.posts.map(p => this.mapToPost(p));
const posts = (response.list || []).map(p => this.mapToPost(p));
// 缓存帖子
posts.forEach(post => {
@@ -360,7 +363,7 @@ export class PostRepository implements IPostRepository {
return {
posts,
hasMore: response.has_more,
hasMore: response.has_more ?? false,
nextCursor: response.next_cursor,
total: response.total,
};