|
- import { apiDelete, apiGet, apiPost } from '@/lib/api'
-
- import type { Post, PostTagChange } from '@/types'
-
-
- export const fetchPosts = async (
- { url, title, tags, match, created_from, created_to, updated_from,
- updated_to, original_created_from, original_created_to, page, limit }: {
- url?: string
- title?: string
- tags?: string
- match?: 'all' | 'any'
- created_from?: string
- created_to?: string
- updated_from?: string
- updated_to?: string
- original_created_from?: string
- original_created_to?: string
- page?: number
- limit?: number },
- ): Promise<{
- posts: Post[]
- count: number }> =>
- await apiGet ('/posts', { params: {
- url, title, tags, match, created_from, created_to, updated_from, updated_to,
- original_created_from, original_created_to,
- ...(page && { page }),
- ...(limit && { limit }) } })
-
-
- export const fetchPost = async (id: string): Promise<Post> => await apiGet (`/posts/${ id }`)
-
-
- export const fetchPostChanges = async (
- { id, page, limit }: {
- id?: string
- page: number
- limit: number },
- ): Promise<{
- changes: PostTagChange[]
- count: number }> =>
- await apiGet ('/posts/changes', { params: { ...(id && { id }), page, limit } })
-
-
- export const toggleViewedFlg = async (id: string, viewed: boolean): Promise<void> => {
- await (viewed ? apiPost : apiDelete) (`/posts/${ id }/viewed`)
- }
|