import type { Handler } from '../../../dist' ; import * as Model from './model' ; export const root = ( c ) => { return c . json ( { message : 'Hello' } ) ; } ; export const list = ( c ) => { const posts = Model . getPosts ( ) ; return c . json ( { posts : posts , ok : true } ) ; } ; export const create = async ( c ) => { const param = ( await c . req . json ( ) ) as Model . Param ; const newPost = Model . createPost ( param ) ; if ( ! newPost ) { return c . json ( { error : 'Can not create new post' , ok : false } , 200 ) ; } return c . json ( { post : newPost , ok : true } , 201 ) ; } ; export const show = async ( c ) => { const id = c . req . params ( 'id' ) ; const post = Model . getPost ( id ) ; if ( ! post ) { return c . json ( { error : 'Not Found' , ok : false } , 404 ) ; } return c . json ( { post : post , ok : true } ) ; } ; export const update = async ( c ) => { const id = c . req . params ( 'id' ) ; if ( ! Model . getPost ( id ) ) { return c . json ( { ok : false } , 204 ) ; } const param = ( await c . req . json ( ) ) as Model . Param ; const success = Model . updatePost ( id , param ) ; return c . json ( { ok : success } ) ; } ; export const destroy = async ( c ) => { const id = c . req . params ( 'id' ) ; if ( ! Model . getPost ( id ) ) { return c . json ( { ok : false } , 204 ) ; } const success = Model . deletePost ( id ) ; return c . json ( { ok : success } ) ; } ;