import Post from '@/modules/post/model.ts'
import { setData, getData, listData, removeData } from '@/helpers/data.ts'
type PostParams = {
blogSlug?: string
postSlug?: string
postInput?: Post
}
class PostRepository {
static async createPost({ postInput, blogSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postInput?.slug as string]
const result = await setData({ key, value: postInput })
if (result.ok) return await getData({ key })
}
static async listPosts({ blogSlug }: PostParams) {
const prefix = ['blog', blogSlug as string, 'post']
return await listData({ prefix })
}
static async showPost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await getData({ key })
}
static async updatePost({ postInput, blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
return await setData({ key, value: postInput })
}
static async deletePost({ blogSlug, postSlug }: PostParams) {
const key = ['blog', blogSlug as string, 'post', postSlug as string]
await removeData({ key })
}
}
export default PostRepository