import { Count, CountSchema, Filter, FilterExcludingWhere, repository, Where, } from '@loopback/repository'; import { post, param, get, getModelSchemaRef, patch, put, del, requestBody, response, } from '@loopback/rest'; import {Provider} from '../models'; import {ProviderRepository} from '../repositories'; export class ProviderController { constructor( @repository(ProviderRepository) public providerRepository : ProviderRepository, ) {} @post('/providers') @response(200, { description: 'Provider model instance', content: {'application/json': {schema: getModelSchemaRef(Provider)}}, }) async create( @requestBody({ content: { 'application/json': { schema: getModelSchemaRef(Provider, { title: 'NewProvider', exclude: ['id'], }), }, }, }) provider: Omit, ): Promise { return this.providerRepository.create(provider); } @get('/providers/count') @response(200, { description: 'Provider model count', content: {'application/json': {schema: CountSchema}}, }) async count( @param.where(Provider) where?: Where, ): Promise { return this.providerRepository.count(where); } @get('/providers') @response(200, { description: 'Array of Provider model instances', content: { 'application/json': { schema: { type: 'array', items: getModelSchemaRef(Provider, {includeRelations: true}), }, }, }, }) async find( @param.filter(Provider) filter?: Filter, ): Promise { return this.providerRepository.find(filter); } @patch('/providers') @response(200, { description: 'Provider PATCH success count', content: {'application/json': {schema: CountSchema}}, }) async updateAll( @requestBody({ content: { 'application/json': { schema: getModelSchemaRef(Provider, {partial: true}), }, }, }) provider: Provider, @param.where(Provider) where?: Where, ): Promise { return this.providerRepository.updateAll(provider, where); } @get('/providers/{id}') @response(200, { description: 'Provider model instance', content: { 'application/json': { schema: getModelSchemaRef(Provider, {includeRelations: true}), }, }, }) async findById( @param.path.number('id') id: number, @param.filter(Provider, {exclude: 'where'}) filter?: FilterExcludingWhere ): Promise { return this.providerRepository.findById(id, filter); } @patch('/providers/{id}') @response(204, { description: 'Provider PATCH success', }) async updateById( @param.path.number('id') id: number, @requestBody({ content: { 'application/json': { schema: getModelSchemaRef(Provider, {partial: true}), }, }, }) provider: Provider, ): Promise { await this.providerRepository.updateById(id, provider); } @put('/providers/{id}') @response(204, { description: 'Provider PUT success', }) async replaceById( @param.path.number('id') id: number, @requestBody() provider: Provider, ): Promise { await this.providerRepository.replaceById(id, provider); } @del('/providers/{id}') @response(204, { description: 'Provider DELETE success', }) async deleteById(@param.path.number('id') id: number): Promise { await this.providerRepository.deleteById(id); } }