import { authenticate } from '@loopback/authentication' ; import { Count , CountSchema , Filter , FilterExcludingWhere , repository , Where , } from '@loopback/repository' ; import { del , get , getModelSchemaRef , param , patch , post , put , requestBody , } from '@loopback/rest' ; import { Todo } from '../models' ; import { TodoRepository } from '../repositories' ; @ authenticate ( 'jwt' ) export class TodoController { constructor ( @ repository ( TodoRepository ) public todoRepository ) { } @ post ( '/todos' , { responses : { '200' : { description : 'Todo model instance' , content : { 'application/json' : { schema : getModelSchemaRef ( Todo ) } } , } , } , } ) async create ( @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( Todo , { title : 'NewTodo' , exclude : [ 'id' ] , } ) , } , } , } ) todo ) { return this . todoRepository . create ( todo ) ; } @ get ( '/todos/{id}' , { responses : { '200' : { description : 'Todo model instance' , content : { 'application/json' : { schema : getModelSchemaRef ( Todo , { includeRelations : true } ) , } , } , } , } , } ) async findById ( @ param . path . number ( 'id' ) id , @ param . filter ( Todo , { exclude : 'where' } ) filter ? ) { return this . todoRepository . findById ( id , filter ) ; } @ get ( '/todos' , { responses : { '200' : { description : 'Array of Todo model instances' , content : { 'application/json' : { schema : { type : 'array' , items : getModelSchemaRef ( Todo , { includeRelations : true } ) , } , } , } , } , } , } ) async find ( @ param . filter ( Todo ) filter ? ) { return this . todoRepository . find ( filter ) ; } @ put ( '/todos/{id}' , { responses : { '204' : { description : 'Todo PUT success' , } , } , } ) async replaceById ( @ param . path . number ( 'id' ) id , @ requestBody ( ) todo ) { await this . todoRepository . replaceById ( id , todo ) ; } @ patch ( '/todos/{id}' , { responses : { '204' : { description : 'Todo PATCH success' , } , } , } ) async updateById ( @ param . path . number ( 'id' ) id , @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( Todo , { partial : true } ) , } , } , } ) todo ) { await this . todoRepository . updateById ( id , todo ) ; } @ del ( '/todos/{id}' , { responses : { '204' : { description : 'Todo DELETE success' , } , } , } ) async deleteById ( @ param . path . number ( 'id' ) id ) { await this . todoRepository . deleteById ( id ) ; } @ get ( '/todos/count' , { responses : { '200' : { description : 'Todo model count' , content : { 'application/json' : { schema : CountSchema } } , } , } , } ) async count ( @ param . where ( Todo ) where ? ) { return this . todoRepository . count ( where ) ; } @ patch ( '/todos' , { responses : { '200' : { description : 'Todo PATCH success count' , content : { 'application/json' : { schema : CountSchema } } , } , } , } ) async updateAll ( @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( Todo , { partial : true } ) , } , } , } ) todo , @ param . where ( Todo ) where ? ) { return this . todoRepository . updateAll ( todo , where ) ; } }