This commit is contained in:
+10
-30
@@ -1,7 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import toCamel from 'camelcase-keys'
|
||||
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { apiDelete, apiGet, apiPost } from '@/lib/api'
|
||||
|
||||
import type { Post } from '@/types'
|
||||
|
||||
@@ -16,35 +13,18 @@ export const fetchPosts = async (
|
||||
): Promise<{
|
||||
posts: Post[]
|
||||
count: number
|
||||
nextCursor: string }> => {
|
||||
const res = await axios.get (`${ API_BASE_URL }/posts`, {
|
||||
params: {
|
||||
tags,
|
||||
match,
|
||||
...(page && { page }),
|
||||
...(limit && { limit }),
|
||||
...(cursor && { cursor }) } })
|
||||
|
||||
return toCamel (res.data as any, { deep: true }) as {
|
||||
posts: Post[]
|
||||
count: number
|
||||
nextCursor: string }
|
||||
}
|
||||
nextCursor: string }> => await apiGet ('/posts', {
|
||||
params: {
|
||||
tags,
|
||||
match,
|
||||
...(page && { page }),
|
||||
...(limit && { limit }),
|
||||
...(cursor && { cursor }) } })
|
||||
|
||||
|
||||
export const fetchPost = async (id: string): Promise<Post> => {
|
||||
const res = await axios.get (`${ API_BASE_URL }/posts/${ id }`, {
|
||||
headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') ?? '' } })
|
||||
|
||||
return toCamel (res.data as any, { deep: true }) as Post
|
||||
}
|
||||
export const fetchPost = async (id: string): Promise<Post> => await apiGet (`/posts/${ id }`)
|
||||
|
||||
|
||||
export const toggleViewedFlg = async (id: string, viewed: boolean): Promise<void> => {
|
||||
const url = `${ API_BASE_URL }/posts/${ id }/viewed`
|
||||
const opt = { headers: { 'X-Transfer-Code': localStorage.getItem ('user_code') ?? '' } }
|
||||
if (viewed)
|
||||
await axios.post (url, { }, opt)
|
||||
else
|
||||
await axios.delete (url, opt)
|
||||
await (viewed ? apiPost : apiDelete) (`/posts/${ id }/viewed`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user