ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.5 KiB

  1. import { apiDelete, apiGet, apiPost } from '@/lib/api'
  2. import type { Post, PostTagChange } from '@/types'
  3. export const fetchPosts = async (
  4. { url, title, tags, match, created_from, created_to, updated_from,
  5. updated_to, original_created_from, original_created_to, page, limit }: {
  6. url?: string
  7. title?: string
  8. tags?: string
  9. match?: 'all' | 'any'
  10. created_from?: string
  11. created_to?: string
  12. updated_from?: string
  13. updated_to?: string
  14. original_created_from?: string
  15. original_created_to?: string
  16. page?: number
  17. limit?: number },
  18. ): Promise<{
  19. posts: Post[]
  20. count: number }> =>
  21. await apiGet ('/posts', { params: {
  22. url, title, tags, match, created_from, created_to, updated_from, updated_to,
  23. original_created_from, original_created_to,
  24. ...(page && { page }),
  25. ...(limit && { limit }) } })
  26. export const fetchPost = async (id: string): Promise<Post> => await apiGet (`/posts/${ id }`)
  27. export const fetchPostChanges = async (
  28. { id, page, limit }: {
  29. id?: string
  30. page: number
  31. limit: number },
  32. ): Promise<{
  33. changes: PostTagChange[]
  34. count: number }> =>
  35. await apiGet ('/posts/changes', { params: { ...(id && { id }), page, limit } })
  36. export const toggleViewedFlg = async (id: string, viewed: boolean): Promise<void> => {
  37. await (viewed ? apiPost : apiDelete) (`/posts/${ id }/viewed`)
  38. }