63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import request from '@/utils/request'
|
|
import type { ICommonPageResponse, ICommonResponse } from '@/types/common'
|
|
import type { ContentLocale } from '@/utils/content-locale'
|
|
|
|
export type MediaType = 'article' | 'video'
|
|
|
|
export interface INewsItem {
|
|
id: string
|
|
locale: ContentLocale
|
|
mediaType: MediaType
|
|
title: string
|
|
summary: string
|
|
thumbnail: string
|
|
thumbnailAlt?: string
|
|
url?: string
|
|
youtubeUrl?: string
|
|
tiktokUrl?: string
|
|
sortOrder: number
|
|
status: 'published' | 'draft'
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface INewsListParams {
|
|
page: number
|
|
pageSize: number
|
|
locale?: '' | ContentLocale
|
|
mediaType?: '' | MediaType
|
|
keyword?: string
|
|
status?: '' | 'published' | 'draft'
|
|
}
|
|
|
|
export interface INewsInput {
|
|
id?: string
|
|
locale: ContentLocale
|
|
mediaType: MediaType
|
|
title: string
|
|
summary: string
|
|
thumbnail: string
|
|
thumbnailAlt?: string
|
|
url?: string
|
|
youtubeUrl?: string
|
|
tiktokUrl?: string
|
|
sortOrder?: number
|
|
status?: 'published' | 'draft'
|
|
}
|
|
|
|
export const newsPage = (params?: INewsListParams) => {
|
|
return request.get<ICommonPageResponse<INewsItem[]>>('/news', { params })
|
|
}
|
|
|
|
export const createNews = (data: INewsInput) => {
|
|
return request.post<ICommonResponse<INewsItem>>('/news', data)
|
|
}
|
|
|
|
export const updateNews = (data: INewsInput & { id: string }) => {
|
|
return request.put<ICommonResponse<INewsItem>>('/news', data)
|
|
}
|
|
|
|
export const deleteNews = (ids: string[]) => {
|
|
return request.delete<ICommonResponse<unknown>>('/news', { data: ids })
|
|
}
|