refactor post model
This commit is contained in:
parent
62f9de9546
commit
30025b4044
8 changed files with 373 additions and 151 deletions
|
@ -29,22 +29,34 @@ export class PostsService {
|
|||
return Post.fromDto(response.data.post)
|
||||
}
|
||||
|
||||
async loadPublicFeed(
|
||||
cursor: string | null,
|
||||
amount: number | null,
|
||||
): Promise<{ posts: Post[]; next: string | null }> {
|
||||
async load(postId: string): Promise<Post | null> {
|
||||
const response = await this.client.GET('/posts/{postId}', {
|
||||
params: {
|
||||
path: { postId },
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data?.post) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Post.fromDto(response.data.post)
|
||||
}
|
||||
|
||||
async loadPublicFeed(cursor: string | null, amount: number | null): Promise<{ posts: Post[] }> {
|
||||
const response = await this.client.GET('/posts', {
|
||||
params: {
|
||||
query: { From: cursor ?? undefined, Amount: amount ?? undefined },
|
||||
query: { After: cursor ?? undefined, Amount: amount ?? undefined },
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
return { posts: [], next: null }
|
||||
return { posts: [] }
|
||||
}
|
||||
|
||||
return { posts: response.data.posts.map(Post.fromDto), next: response.data.next }
|
||||
return { posts: response.data.posts.map(Post.fromDto) }
|
||||
}
|
||||
|
||||
async addReaction(postId: string, emoji: string): Promise<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue