import { Controller , Path , GET , POST , PathParam , QueryParam , BodyParam , ReqParam , ResParam , NextParam , OriginParam , Before , After } from '../../../../src/index' ; import { authController } from '../auth' ; @ Path ( '/api/posts' , authController ) class PostController extends Controller { @ GET @ Path ( '/:name/:id' , ( ctx , next ) => ~ ~ ctx . params . id > 20 ) @ Before ( ( req , res , next ) => req . beforeHook = 'before' ) @ After ( ( req , res , next ) => console . log ( 'done' ) ) getAllPosts ( @ PathParam ( 'id' ) id , @ PathParam ( 'name' ) name , @ QueryParam ( 'user' ) user , @ ReqParam ( 'req' ) req , @ ResParam ( 'res' ) res ) { return Promise . resolve ( [ { id : id , name , content : 'test' , author : 'wangyafei' , comments : [ ] , userName : user . name , userAge : user . age , before : req . beforeHook } ] ) ; } @ GET @ Path ( '/name/id/:id' ) getPostByName ( @ PathParam ( 'id' ) id , @ OriginParam ( 'origin' ) origin ) { origin . ctx . response . redirect ( '/users' ) ; return [ { id : id , content : 'test' , author : 'wangyafei' , comments : [ ] } ] ; } @ POST @ Path ( '/add' ) addPost ( @ BodyParam ( 'post' ) post ) { return post ; } } export default PostController ;