import { intercept } from '@loopback/core' ; import { Count , CountSchema , Filter , repository , Where , } from '@loopback/repository' ; import { del , get , getFilterSchemaFor , getModelSchemaRef , getWhereSchemaFor , param , patch , post , put , requestBody , } from '@loopback/rest' ; import { ValidatePhoneNumInterceptor } from '../interceptors' ; import { CoffeeShop } from '../models' ; import { CoffeeShopRepository } from '../repositories' ; @ intercept ( ValidatePhoneNumInterceptor . BINDING_KEY ) export class CoffeeShopController { constructor ( @ repository ( CoffeeShopRepository ) public coffeeShopRepository ) { } @ post ( '/coffee-shops' , { responses : { '200' : { description : 'CoffeeShop model instance' , content : { 'application/json' : { schema : getModelSchemaRef ( CoffeeShop ) } } , } , } , } ) async create ( @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( CoffeeShop , { title : 'NewCoffeeShop' , exclude : [ 'shopId' ] , } ) , } , } , } ) coffeeShop ) { return this . coffeeShopRepository . create ( coffeeShop ) ; } @ get ( '/coffee-shops/count' , { responses : { '200' : { description : 'CoffeeShop model count' , content : { 'application/json' : { schema : CountSchema } } , } , } , } ) async count ( @ param . query . object ( 'where' , getWhereSchemaFor ( CoffeeShop ) ) where ? ) { return this . coffeeShopRepository . count ( where ) ; } @ get ( '/coffee-shops' , { responses : { '200' : { description : 'Array of CoffeeShop model instances' , content : { 'application/json' : { schema : { type : 'array' , items : getModelSchemaRef ( CoffeeShop , { includeRelations : true } ) , } , } , } , } , } , } ) async find ( @ param . query . object ( 'filter' , getFilterSchemaFor ( CoffeeShop ) ) filter ? ) { return this . coffeeShopRepository . find ( filter ) ; } @ patch ( '/coffee-shops' , { responses : { '200' : { description : 'CoffeeShop PATCH success count' , content : { 'application/json' : { schema : CountSchema } } , } , } , } ) async updateAll ( @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( CoffeeShop , { partial : true } ) , } , } , } ) coffeeShop , @ param . query . object ( 'where' , getWhereSchemaFor ( CoffeeShop ) ) where ? ) { return this . coffeeShopRepository . updateAll ( coffeeShop , where ) ; } @ get ( '/coffee-shops/{id}' , { responses : { '200' : { description : 'CoffeeShop model instance' , content : { 'application/json' : { schema : getModelSchemaRef ( CoffeeShop , { includeRelations : true } ) , } , } , } , } , } ) async findById ( @ param . path . string ( 'id' ) id , @ param . query . object ( 'filter' , getFilterSchemaFor ( CoffeeShop ) ) filter ? ) { return this . coffeeShopRepository . findById ( id , filter ) ; } @ patch ( '/coffee-shops/{id}' , { responses : { '204' : { description : 'CoffeeShop PATCH success' , } , } , } ) async updateById ( @ param . path . string ( 'id' ) id , @ requestBody ( { content : { 'application/json' : { schema : getModelSchemaRef ( CoffeeShop , { partial : true } ) , } , } , } ) coffeeShop ) { await this . coffeeShopRepository . updateById ( id , coffeeShop ) ; } @ put ( '/coffee-shops/{id}' , { responses : { '204' : { description : 'CoffeeShop PUT success' , } , } , } ) async replaceById ( @ param . path . string ( 'id' ) id , @ requestBody ( ) coffeeShop ) { await this . coffeeShopRepository . replaceById ( id , coffeeShop ) ; } @ del ( '/coffee-shops/{id}' , { responses : { '204' : { description : 'CoffeeShop DELETE success' , } , } , } ) async deleteById ( @ param . path . string ( 'id' ) id ) { await this . coffeeShopRepository . deleteById ( id ) ; } }