This commit is contained in:
2025-10-05 03:15:46 +09:00
parent 19a17e7ba7
commit d5d7e0e22b
10 changed files with 372 additions and 73 deletions
+37
View File
@@ -0,0 +1,37 @@
import axios from 'axios'
import toCamel from 'camelcase-keys'
import { API_BASE_URL } from '@/config'
import type { Post } from '@/types'
export const fetchPosts = async ({ tags, match, limit, cursor }: {
tags: string
match: 'any' | 'all'
limit: number
cursor?: string }): Promise<{ posts: Post[]; nextCursor: string }> => {
const res = await axios.get (`${ API_BASE_URL }/posts`, {
params: { tags, match, limit, ...(cursor && { cursor }) } })
return toCamel (res.data as any, { deep: true }) as { posts: Post[]
nextCursor: string }
}
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 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)
}