some change
This commit is contained in:
parent
d4a1492d56
commit
313f1def49
38 changed files with 475 additions and 401 deletions
62
src/app/feed/posts/postsService.ts
Normal file
62
src/app/feed/posts/postsService.ts
Normal file
|
@ -0,0 +1,62 @@
|
|||
import { Post } from './posts.ts'
|
||||
import client from '../../api/client.ts'
|
||||
|
||||
export class PostsService {
|
||||
constructor() {}
|
||||
|
||||
async createNew(authorId: string, content: string, media: CreatePostMedia[]): Promise<string> {
|
||||
const response = await client.POST('/posts', {
|
||||
body: {
|
||||
authorId,
|
||||
content,
|
||||
media: media.map((m) => {
|
||||
return { ...m, type: null, url: m.url.toString() }
|
||||
}),
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
throw new Error('Failed to create post')
|
||||
}
|
||||
|
||||
return response.data.postId
|
||||
}
|
||||
|
||||
async loadPublicFeed(cursor: string | null, amount: number | null): Promise<Post[]> {
|
||||
const response = await client.GET('/posts', {
|
||||
query: { cursor, amount },
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
return []
|
||||
}
|
||||
|
||||
return response.data?.posts.map((post) => Post.fromDto(post))
|
||||
}
|
||||
|
||||
async loadByAuthor(
|
||||
username: string,
|
||||
cursor: string | null,
|
||||
amount: number | null,
|
||||
): Promise<Post[]> {
|
||||
const response = await client.GET('/posts', {
|
||||
query: { cursor, amount, username },
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
return []
|
||||
}
|
||||
|
||||
return response.data?.posts.map((post) => Post.fromDto(post))
|
||||
}
|
||||
}
|
||||
|
||||
interface CreatePostMedia {
|
||||
mediaId: string
|
||||
url: string | URL
|
||||
width: number | null
|
||||
height: number | null
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue