This commit is contained in:
2026-02-01 03:59:39 +09:00
parent 145d93679c
commit 8cc2a88e7c
12 changed files with 235 additions and 215 deletions
+10 -30
View File
@@ -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`)
}