69 lines
1.3 KiB
TypeScript
69 lines
1.3 KiB
TypeScript
import { useApi } from '@/composables/useApi'
|
|
import type { Byline } from '@/lib/articleTypes'
|
|
import type { ArticleStatus } from '@/lib/articleListQuery'
|
|
|
|
export type { Byline }
|
|
|
|
export interface Article {
|
|
id: number
|
|
title: string
|
|
body: string
|
|
is_online: boolean
|
|
site_id?: number
|
|
authors?: Byline[]
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
export type { ArticleStatus }
|
|
|
|
export interface ArticleCounts {
|
|
all: number
|
|
online: number
|
|
draft: number
|
|
}
|
|
|
|
export interface ArticlePage {
|
|
items: Article[]
|
|
total: number
|
|
page: number
|
|
size: number
|
|
counts: ArticleCounts
|
|
}
|
|
|
|
export interface ListArticlesParams {
|
|
page: number
|
|
size: number
|
|
q?: string
|
|
status?: ArticleStatus | ''
|
|
sort?: string
|
|
site?: string
|
|
}
|
|
|
|
export function useArticles() {
|
|
const { request } = useApi()
|
|
|
|
function listArticles(params: ListArticlesParams): Promise<ArticlePage> {
|
|
const query = new URLSearchParams({
|
|
format: 'html',
|
|
page: String(params.page),
|
|
size: String(params.size),
|
|
})
|
|
if (params.q) {
|
|
query.set('q', params.q)
|
|
}
|
|
if (params.status) {
|
|
query.set('status', params.status)
|
|
}
|
|
if (params.sort) {
|
|
query.set('sort', params.sort)
|
|
}
|
|
if (params.site) {
|
|
query.set('site', params.site)
|
|
}
|
|
return request<ArticlePage>(`/v1/article/?${query.toString()}`)
|
|
}
|
|
|
|
return { listArticles }
|
|
}
|